0
votes

I built a custom linux kernel, and get the bzImage at linux-src/arch/x86_64/boot/bzImage. Now I have a qemu image ubuntu.qcow2 loaded a Ubuntu iso, and I want to use qemu with the given image and kernel.

From Direct Linux Boot, I use

qemu-system-x86_64 -kernel linux-src/arch/x86_64/boot/bzImage -hda ubuntu.qcow2 -append "root=/dev/hda"

But it turns out error:

not syncing: VFS: Unable to mount root fs on unknown-block(0, 0)

I don't know much about initrd, is this error due to the lack of initrd?

2
It's saying that whatever is in ubuntu.qcow2 doesn't look like a root filesystem that it understands. - stark
@stark Could you tell me what is the correct way to create the right qcow2 image? - Evian
The problem is probably not the qcow2 image but that your new kernel does not have all the driver and filesystem support necessary to find the disk image and understand it. - Peter Maydell

2 Answers

1
votes

I came across the same problem and fix it after struggling. For clarity and reproducibility, I list all the steps.

  1. create the qcow2 image from ISO ref
disk_img=ubuntu.qcow2
iso_name=ubuntu-21.04-desktop-amd64.iso

qemu-img create -f qcow2 "$disk_img" 1T

qemu-system-x86_64 \
        -cdrom "$iso" \
        -drive "file=${disk_img},format=qcow2" \
        -enable-kvm \
        -m 2G \
        -smp 2 \
        ;

Then, you install Ubuntu as the instructions, once finished, just reboot.

  1. Run the Ubuntu with built-in kernel.
qemu-system-x86_64 \
  -drive "file=${disk_img},format=qcow2" \
  -enable-kvm \
  -m 8G \
  -smp 8

In Qemu, open a terminal and use df -h to find out from which drive your Ubuntu boot.On my computer, it's "/dev/sda3". df -h

  1. compile the kernel
cd /kernel/src/path
git reset --hard origin/master
make defconfig
make -j4
  1. Run the Ubuntu with the newly compiled kernel with hard drive specified
qemu-system-x86_64 \
  -hda ${disk_img} \
  -enable-kvm \
  -append "root=/dev/sda3" \
  -kernel /kernel/src/path/arch/x86/boot/bzImage \
  -cpu host \
  -m 8G \
  -smp 8

As the following pictures says, the kernel is what I just compiled. new compiled kernel

The key point is to inform the kernel 'root=/dev/sda3', as can be obtained in step 2.

0
votes

I have a similar problem as well, even I followed the answer from @Martins3 .
I intended to swap the kernel from an existed .qcow2 file but I still cannot log in my qemu. I solved it by creating an initrd file from source.

So after step 1-3 from @Martins3 's answer. I did that.

# make the initrd file
sudo make modules -j`nproc`
sudo make modules_install

After you install the modules, note the version number in the output message. output message after make modules_install Here the version number is 5.14.0-rc6+

# you can create initrd in any path
cd <initrd-dir>
# please note that the <version-num> should match the version number you just installed
sudo mkinitrd initrd-{version-num}.img <version-num>

Then the following command works for me

qemu-system-x86_64 \
  -hda ${disk_img} \
  -enable-kvm \
  -append "root=/dev/sda3" \
  -kernel /kernel/src/path/arch/x86/boot/bzImage \
  -initrd ${initrd-file-path} \
  -cpu host \
  -m 8G \
  -smp 8