TL;DR : I try to tell my kernel on a Qemu machine to start /sbin/init from an NFS server but I have a kernel panic (not syncing: VFS: Unable to mount root fs on unknown-block(2,0)). I used the following command for that :
kvm \ -netdev tap,id=totou,ifname=tap1 -device e1000,netdev=totou,mac=52:54:00:12:34:57 \ -kernel /tmp/bzImage \ -append "root=/dev/nfs rw nfsroot=10.0.2.3:/serverNFS ip=dhcp" \ -m 6G A more detailed explanation :
I compiled a kernel (linux-4.8.6):
make defconfig make -j8 cp arch/x86/boot/bzImage /tmp I also have a disk mydisk.qcow2 create by qemu-img and which has one ext4 partition in which I only have /sbin/init. Where init is the result of gcc -static -o init init.c and where init.c is :
#include <stdio.h> #include <unistd.h> int main() { printf("Hello init\n"); while(1) sleep(100); return 0; } Then I run qemu (kvm) :
kvm \ -kernel /tmp/bzImage \ -append "root=/dev/sda1 rw" \ -hda mydisk.qcow2 \ -m 6G and all is working as expected : the kernel start and start init.
Then I added a dhcp and nfs server on another VM :
qemu-DHCP-and-NFS-server ------- (tap0)[ host bridge (br0) ](tap1) --------- qemu client
Host bridge br0 contains two interfaces : tap0 connected to qemu server and tap1 connected to the client. the bridge ip is 10.0.2.2/24 with mac=5e:50:67:79:96:f0 the qemu-DHCP-and-NFS-server ip is 10.0.2.3/24 with mac=52:54:00:12:34:56
On qemu-DHCP-and-NFS-server the
initbinary is in /serverNFS/sbin/init and /etc/export looks like :/serverNFS *(rw,no_root_squash,async,insecure)
just for testing I run a ubuntu live cd on the qemu client :
kvm \ -netdev tap,id=totou,ifname=tap1 -device e1000,netdev=totou,mac=52:54:00:12:34:57 \ -cdrom ubuntu-16.04-desktop-amd64.iso \ -m 6G and try to mount the nfs partion :
# mkdir /tmp/nfs # mount.nfs 10.0.2.3:/serverNFS /tmp/nfs # ls /tmp/nfs/sbin init OK so DHCP and NFS works !!
Now I stop qemu client and start it again with :
kvm \ -netdev tap,id=totou,ifname=tap1 -device e1000,netdev=totou,mac=52:54:00:12:34:57 \ -kernel /tmp/bzImage \ -append "root=/dev/nfs rw nfsroot=10.0.2.3:/serverNFS ip=dhcp" \ -m 6G On the boot, the kernel start and I can see things like:
... Sending DHCP requests ;, OK IP-Config : Got DHCP answer from 10.0.2.3, my address is 10.0.2.19 IP-Config : Complete: device=eth0,hwaddr=52:54:00:12:34:57, ipaddr=10.0.2.19, mask=255.255.255.0, gw=10.0.2.2 host=10.0.2.19, domain=, nis-domain=(none) bootserver=10.0.2.3, rootserver=10.0.2.3, rootpath=/serverNFS ...
But at the end I have a kernel panic - "not syncing : VFS: Unable to mount root fs
It look likes I have an issue with my nfs server but I can't find why. Do you have any idea?
Just one more precision : I don't want to add '-initrd' (or explain why it is absolutly necessary). All things in the kernel configuration in File systems -> Network File System are selected (not as module). Also CONFIG_ROOT_NFS, CONFIG_IP_PNP, CONFIG_IP_PNP_BOOTP, CONFIG_IP_PNP_RARP, CONFIG_IP_PNP_DHCP are all selected.
Please tell me if you want some other precisions.