I created an ext4-filesystem on a loop device with all necessary files to boot with, e.g.:

/bin /boot /dev /lib /mnt /etc ...

Now I want to boot from the loop device as an image (let's say filesystem.img) with this filesystem. Is it possible to make this loop device as the new root filesystem and to boot from it with the GRUB2 bootloader?

I also read an article about initrd to perform this with the initial ram disk: https://developer.ibm.com/articles/l-initrd/

2 Answers 2


qemu should do the job. I use such command to emulate booting from another hard drive:

sync ; echo 3 | sudo tee /proc/sys/vm/drop_caches ; sudo qemu-system-x86_64 -m 1024 -enable-kvm -hda /dev/sdc

first two sections (sync and echo 3) usually are needed single time after you have edited the image file.

-m 1024 - sets Ram limit.

-enable-kvm - can be omited if causing problems.

-hda /dev/sdc - this part you should change..

here is a better answer - Booting a raw disk image in QEMU

  • Thanks for your answer! In my case, I want to boot directly from GRUB with that disk image. Do you know if this is possible? It seems like it is not possible with QEMU, am I right?
    – User100700
    Jun 23, 2022 at 6:55
  • Well, it is sure possible with GRUB Jun 23, 2022 at 8:03
  1. load into GRUB2 and enter its command line mode (hit 'c') and investigate how it enumerated your disks in (hdN,N) fashion with ls command
  2. load into GRUB2 and edit any entry (hit 'e') , edit it into something like https://superuser.com/a/1300189/702372 according to your files location . Load it by hittin Ctrl-x
  3. to make a permanent entry, follow the answer from 2.
  • Thank you once again. I got problems booting into my filesystem. I got in my main partition (hd0, msdos1), the following file is my filesystem: filesystem.img. My entry in /etc/grub.d/40_custom is: menuentry "test" { insmod linux set isofile="boot/filesystem.img" loopback loop (hd0,msdos1)/${isofile} linux (loop)/vmlinuz initrd (loop)/boot/initrd.img-4.15.0-187-generic }. But after that, when I boot from it, I get an error message attempt to read or write outside of disk 'loop'. Do you know a solution?
    – User100700
    Jun 24, 2022 at 10:50
  • I practiced it a bit. Probably I can tell you exact commands if you tell how you made that fs.img file. Jul 5, 2022 at 9:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .