December 9, 2015 | Article | No Comments
Testing and debugging an operating system require an environment. Many people prefer to use emulator and virtualization software like QEMU, VMware, or VirtualBox for this job.
If you have read my previous article about mounting QEMU Hard Disk Image, you should note that the partition should already have been formatted with a specific filesystem. This is bad if we just create a fresh QEMU disk image.
This article will discuss about how to format the partition inside QEMU disk image. The assumption made here is the disk image is fresh and no more operation than partitioning it. I assume you have at least one partition (such as FAT32, Linux, etc. Any!).
In this article I use:
- Slackware64 14.0 as host system
- QEMU 1.4.0
I also provide a small empty raw image for play around (see next section).
Obtain the Materials
You can download an empty disk image here
The compressed image size is 2MB and the extracted (the image itself) is 2GB.
The disk image has two partition (as seen on fdisk):
- W95 FAT32, start from 2048 , end on 268287. This will be formatted as FAT32.
- Linux, start from 268288, end on 4194303. This will be formatted as EXT4.
There is nothing special about this image. The process I did is common and you can achieve it by yourself:
- Create empty qemu image file
qemu-img create -f raw xath-testsuite-ext3.img 2G
The image is in raw format. This is important as it is the simple one.
- Create the partition using fdisk.
We also need a Linux ISO image. We will use Slackware mini install which can be obtained here. In the rest of this article, we will refer this as minislack.iso.
What we will do are:
- Format the hard disk / QEMU disk image using Linux installer.
- Interrupt the Linux installer, stop QEMU, mount the QEMU image on Linux and clean it up.
Boot the disk with QEMU and Slackware as first boot
qemu-system-i386 xath-testsuite-ext3.img -cdrom minislack.iso -boot d
Once booted, just press enter. Press enter again when you are asked for keyboard layout. You will be brought to a terminal. Login as root with no password.
Our disk image is recognized as /dev/sda. To format a partition as FAT32 use mkfs.vfat and to format it as EXT4 use mkfs.ext4.
We will try the second one and I will leave you with the first one for you to play with 😉
Now for final touch. Still using the Slackware on QEMU, mount the /dev/sda1 and /dev/sda2. Your goal now is to remove the content. After this point, we can finally say “done!”.