Linux – Running QEMU with a root file system directory instead of disk image

buildrootdisk-imagelinuxqemuroot-filesystem

In order to test the root file system i need to run QEMU with created disk image as root file system, the QEMU accepts -kernel which can be used for specifying kernel directly without deploying it inside root file system, however i need similar feature for root file system to specify path of extracted root file system instead of creating a disk image and use it with -hda or -usbdisk options.

is it possible at all with QEMU alone?!
Or with third-party tools (like virtual disk image emulator)

My goal is to test a tar archive of root file system without creating disk image

Best Answer

If your rootfs is not too big you can use an initd. Use the -initrd option to qemu and provide a (compressed) cpio file with the rootfs. So if you have a tar file you must unpack it and create a cpio instead. You must use -H newc format for cpio. Example;

mkdir /tmp/rootfs
cd /tmp/rootfs
tar xf /path/to/rootfs.tar
find | cpio --quiet -o -H newc | bzip2 -c > /tmp/rootfs.cpio

A nice thing is that you don't need root or sudo for this.

Related Question