经过虚拟机调试linux 内核(续)

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

相关文章
相关标签/搜索