1. nfs Verification
Verify whether the Guest machine can mount nfs of the Host machine in NAT mode.
Sudo mount 192.168.1.102:/home/qianjiang/pls temp/
Mount: wrong fs type, bad option, bad superblock on 192.168.1.102:/home/qianjiang/pls,
Missing codepage or helper program, or other error
(For several filesystems (e.g. nfs, cifs) you might
Need a/sbin/mount. <type> helper program)
In some cases useful info is found in syslog-try
Dmesg | tail or so
It turns out that nfs-common is to be installed and NAT does not support NFS.
Sudo apt-get nfs-common, because nfs is compiled into a module by installing kernel.
2. Prepare rootfs
From initrd. img
Gzip-cd/boot/initrd. img | cpio-imd -- quiet
3. add nfs to kernel command line
Kernel command line: BOOT_IMAGE =/boot/bzImage root =/dev/nfs nfsroot = 192.168.1.102:/home/qianjiang/pls/root/pc-root ip = dhcp nfsrootdebug console = ttyS0, 115200
. The mount fails at the beginning and exportfs needs to be modified (due to NAT)
/Home/qianjiang/pls * (rw, no_root_squash, no_all_squash, sync, nohide, no_subtree_check)
Change
/Home/qianjiang/pls * (rw, insecure, sync, no_subtree_check)
Mainly add insecure
4. Modify grub. cfg
To avoid entering a long command line every time, create tftpboot/boot/grub. cfg, including the following content
Menuentry Kernel debug -- class ubuntu -- class gnu-linux -- class gnu -- class OS {
Echo Loading Linux...
Linux/boot/bzImage root =/dev/nfs rw nfsroot = 192.168.1.102:/home/qianjiang/pls/root/pc-root ip = dhcp nfsrootdebug console = ttyS0, 115200
}
You can also remove the menu framework and add boot to the last line.
5.
. It should be mounted, but the following line is displayed, probably because of a problem with rootfs.
[20.512132] nfs: server 192.168.1.106 not responding, still trying
After reading the post online, I feel that it is a kernel problem,
Modify fs/nfs/nfsroot. c
# Define NFS_DEF_OPTIONS "vers = 3, proto = tcp, mountproto = udp"
Then we solved this problem. It seems that it was not good. It took two days to get it all done, but the benefits were quite high.
6. debugging becomes very convenient
Open a vim window to modify the kernel code, open a mini-com window to view debugging information, and enter commands similar to the following in a window.
Make & cp arch/x86/boot/bzImage ~ /Tftpboot/boot/# compile
Vboxmanage startvm "kernel-debug" # start the machine
Or
Vboxmanage controlvm "kernel-debug" reset # reset the machine