0

Configuration:

  • MacOS arm64 M1 Apple Silicon as host
  • Live USB with Ubuntu 20.04 amd64 within a squashfs filesystem as guest
  • QEMU emulator on the host OS

I want to strip the OS out the squashfs and boot it on a emulated amd64 virtual machine on my mac. I managed to extract the Ubuntu OS. I mounted the squashfs an copied the content into an img file I created using dd. I copied the image on the mac but when I try to boot the VM says "No bootable device".

Here are the commands I used, from a supporting Linux virtual machine

mount -t squashfs -o loop /path/to/filesystem.squashfs /sqshfs/mount/point

I created an empty image and made an ext4 fs

dd if=/dev/zeroes of=image.img bs=1M count=15000
mkfs.ext4 image.img

mounted it and copied the files

mount -t auto image.img /img/mount/point
cp -r /sqshfs/mount/point/* /img/mount/point

now on the image I have this folders

total 112
drwxr-xr-x   2 root root  4096 Jan 10 02:37 bin
drwxr-xr-x   3 root root  4096 Jan 10 02:37 boot
drwxr-xr-x   4 root root  4096 Jan 10 02:37 dev
drwxr-xr-x 147 root root 12288 Jan 10 02:37 etc
drwxr-xr-x   3 root root  4096 Jan 10 02:37 home
lrwxrwxrwx   1 root root    33 Jan 10 02:37 initrd.img -> boot/initrd.img-5.4.0-150-generic
lrwxrwxrwx   1 root root    33 Jan 10 02:37 initrd.img.old -> boot/initrd.img-5.4.0-148-generic
drwxr-xr-x  23 root root  4096 Jan 10 02:37 lib
drwxr-xr-x   2 root root  4096 Jan 10 02:37 lib64
drwx------   2 root root 16384 Jan 10 02:36 lost+found
drwxr-xr-x   2 root root  4096 Jan 10 02:37 media
drwxr-xr-x   2 root root  4096 Jan 10 02:37 mnt
drwxr-xr-x   5 root root  4096 Jan 10 02:37 opt
drwxr-xr-x   2 root root  4096 Jan 10 02:37 proc
drwx------   3 root root  4096 Jan 10 02:37 root
drwxr-xr-x   2 root root  4096 Jan 10 02:37 run
drwxr-xr-x   2 root root 12288 Jan 10 02:37 sbin
drwxr-xr-x   2 root root  4096 Jan 10 02:37 snap
drwxr-xr-x   2 root root  4096 Jan 10 02:37 srv
drwxr-xr-x   2 root root  4096 Jan 10 02:37 sys
drwxr-xr-t   2 root root  4096 Jan 10 02:37 tmp
drwxr-xr-x  11 root root  4096 Jan 10 02:38 usr
drwxr-xr-x  15 root root  4096 Jan 10 02:38 var
lrwxrwxrwx   1 root root    30 Jan 10 02:38 vmlinuz -> boot/vmlinuz-5.4.0-150-generic
lrwxrwxrwx   1 root root    30 Jan 10 02:38 vmlinuz.old -> boot/vmlinuz-5.4.0-148-generic

converted the img in qcow2

qemu-img convert -f raw -O qcow2 -c image.img image.qcow2

and configured QEMU as follows

qemu-system-x86_64 \
-name TEST \
-cpu qemu64-v1 \
-smp cpus=4,sockets=1,cores=4,threads=1 \
-machine pc-q35-7.2,vmport=off,i8042=off,hpet=off \
-accel tcg,thread=multi,tb-size=1024 \
-m 4096 \
-drive file=/Users/steve/VMs/image.qcow2 \
-boot menu=on

When I try to boot the VM says "No bootable device". I'm very new abt QEMU and I know this configuration miss something but it should at least try to boot the kernel. GUID?

1 Answer 1

1

You did not tell QEMU to find the kernel and initramfs directly, and you specified machine pc-q35-7.2.

Looking at the source code, one of the defaults for that system type is firmware=bios-256k.bin, which means the the system will run SeaBIOS, attempt to boot like a classic BIOS-based x86 system and look for a Master Boot Record.

Since you copied the files from one filesystem image to another, any boot blocks (which are embedded directly into the image and are not part of any files) are not present. Furthermore, your image.qcow2 is image of a single filesystem, equivalent of just running mkfs.ext4 /dev/sda without partitioning it first. So there is no partition table, and no Master Boot Record (which is located outside any partitions) either.

You could pretty easily copy the kernel and initramfs files off the image:

mount -t auto image.img /img/mount/point
cp /img/mount/point/boot/vmlinux-5.4.0-150-generic /Users/steve/VMs/
cp /img/mount/point/boot/initrd.img-5.4.0-150-generic /Users/steve/VMs/

and add the QEMU options -kernel /Users/steve/VMs/vmlinux-5.4.0-150-generic -initrd /Users/steve/VMs/initrd.img-5.4.0-150-generic to give them directly to QEMU for booting.

Your next hurdle is that you would need to specify the root filesystem location for the kernel, since any root filesystem UUIDs embedded in the initramfs image are no longer correct because the filesystem is no longer the original one. So you might add a QEMU option to specify a kernel command line like -append root=/dev/sda (non-partitioned image, remember?) and hope the kernel is not stripped down to support only squashfs for root filesystem type.

Also, a direct boot like that may not allow the kernel to get any configuration information it would normally receive from BIOS, so some things may be wonky.

You may find that it would be better to set up a proper partitioned disk image with a suitable bootloader embedded in the MBR, but at least the direct kernel image boot will be easy enough to attempt. And who knows? It might work!

2
  • Hi, thanks for the input. That was a great starting point for me to learn. I managed to boot the vm. It complains about a lot of stuff but at least it was a step forward. Thanks again Jan 10 at 11:13
  • 1
    Ubuntu's bootloader will normally add the boot options quiet splash. This direct boot scheme left them out, so you probably got a fully verbose old-school Linux boot, which is a massive wall of text. Changing the -append option to something like -append "root=/dev/sda quiet splash" might make it more similar to booting an actual system from the original USB stick.
    – telcoM
    Jan 10 at 13:09

You must log in to answer this question.

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