December 9, 2015 | Article | 2 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. However, testing a software build for that OS which run on top of virtualization require a method to copy files between host and the guest system. Software such as VirtualBox and VMware have a feature which enable user to activate shared directory. However not every operating system can do this because this feature act as device driver or kernel module. Moreover, QEMU doesn’t have this. The best and practical way to copy file on QEMU is copy all files into .iso images which is accessible by internet. Another way is mount the virtual hard disk or the disk image, which we will do in this article.
As the title suggested, we will discuss the way in various host operating system. Therefore, materials I use are:
- Slackware64 14.0 (Linux)
- Windows 7 32 bit (Windows)
- QEMU 1.4.0
Most linux distribution allow virtual disk mounting using mount command. The disk image should be mounted into a specific directory, let’s say /media/MyOS. Most of the operation need root privilege, so acquire root privilege before we do.
Make sure your virtual image file is in RAW format. If you think your disk image is in another format, use following command:
qemu-img convert <image-file> -O raw <image-file.raw>
Mounting the disk image is simple thing, as simple as mounting another storage device. Note that the actual partition start from offset 32256, after some structure on the disk such as MBR, partition table, etc. The following example assume you are using FAT as file system.
mount -o loop,offset=32256 <image-file> /media/MyOS -t vfat
The 32256 comes from the start of the very first partition * the size of a block. This is because before the first partition there are some data such as MBR. So if your first partition start from block 2048, multiplying it will result in 1048576. Of course the partition should have been formatted with the preferred format.
If the disk has several partition, and you want to mount specific partition (not the first) then you should change the offset to the start of the partition.
To unmount is even easier.
Basically, Windows doesn’t provide such powerful tools like Linux does. However, we can always use third party’s software. Like in Linux section, in this section our goal is to mount raw images.
OSFMount allow local disk image mounting in Windows with a drive letter (E:/, F:/, G:/, etc). You can download OSFMount here.
Another tool which can be downloaded here. Note that it is not free product, but you can always use the demo version.linux, qemu, virtualbox, windows