Running QEMU with a root file system directory instead of disk image
Solution 1
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.
Solution 2
You can write your filesystem in a USB drive, then attach that with QEMU virtual machine.
Than mount that as your root filesystem with kernel options at GRUB
- Activate boot menu in virtualmachine
- Attach the external drive in which your filesystem including kernel is present.
- If your filesystem has kernel and grub it's all fine. Else attach any linux live CD also with the virtual machine. Edit the GRUB command line and use your kernel and root filesystem.
Say your pendrive is /dev/sdB
(considering you've attached a hard disk image also and that is /dev/sdA
, anyway you can find it) your grub command shall look like
kernel (hd1,gpt0)/location_of-kernel root=/dev/sdB
initramfs mention_if_you_have
boot
Replace gpt0
with proper partition and /dev/sdB
with proper letter live /dev/sdb1
or /dev/sdb
(in case the USB has no partition)
Related videos on Youtube
e.jahandar
Updated on September 18, 2022Comments
-
e.jahandar over 1 year
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
-
jpf about 6 yearsMaybe you could try to setup the rootfs as a p9 shared folder, then mount the shared folder as rootfs in your initramfs?
-
firo about 6 yearsTry to boot with NFS.
-
Mio Rin over 5 yearsIs there a reason why
chroot
orsystemd-nspawn
(or other containerization) can not be used for this? -
Darren Ng over 2 years
-