1. nfs驗證
驗證NAT模式下Guest機器是否能mount上Host機器的nfs
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
原來是要安裝nfs-common,還覺得是NAT不支持NFS.
sudo apt-get nfs-common, 由於通常安裝kernel把nfs編譯成module。
2. 準備rootfs
來自於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
. 一開始mount不上,發現要修改exportfs(NAT的緣故)
/home/qianjiang/pls *(rw,no_root_squash,no_all_squash,sync,nohide,no_subtree_check)
改爲
/home/qianjiang/pls *(rw,insecure,sync,no_subtree_check)
主要是加insecure
4. 修改grub.cfg
爲了不每次都輸入長長的command line,創建tftpboot/boot/grub/grub.cfg,包括下面的內容
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
}
或者把菜單框架去掉,並在最後一行加boot,就能夠直接啓動了
5.
. 應該是mount上了,可是顯示下面的行,大概是由於rootfs有問題
[ 20.512132] nfs: server 192.168.1.106 not responding, still trying
網上看帖子,感受是內核的問題,
http://permalink.gmane.org/gmane.linux.nfs/39841
修改fs/nfs/nfsroot.c
#define NFS_DEF_OPTIONS "vers=3,proto=tcp,mountproto=udp"
而後解決了這個問題,看來真不順啊,整了都兩天了才所有走通下來,不過收益挺大的。
6. 調試變得很是方便
開一個vim窗口修改內核代碼,開一個minicom窗口查看調試信息,而後一個窗口輸入相似下面的命令。
make && cp arch/x86/boot/bzImage ~/tftpboot/boot/ #編譯
vboxmanage startvm "kernel-debug" #啓動機器
或者
vboxmanage controlvm "kernel-debug" reset #復位機器
附. mount後的nfs文件系統沒有寫權限html
最後在配置上加no_root_squash才搞定(/etc/exports)。
由於rootnfs是以root權限登陸nfs文件系統的,這是所不但願的,因此要有寫權限的化就要聲明no_root_squash.
一個很不錯的nfs指南,下次再遇到nfs問題能夠參考:
http://tldp.org/HOWTO/NFS-HOWTO/troubleshooting.html
linux