3

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

bumped to the homepage by Community 8 hours ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

  • Maybe you could try to setup the rootfs as a p9 shared folder, then mount the shared folder as rootfs in your initramfs? – jpf Mar 11 '18 at 10:47
  • Try to boot with NFS. – firo Mar 17 '18 at 9:27
  • Is there a reason why chroot or systemd-nspawn (or other containerization) can not be used for this? – Mioriin Jan 18 at 16:16
0

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

  1. Activate boot menu in virtualmachine
  2. Attach the external drive in which your filesystem including kernel is present.
  3. 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)

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.