通过虚拟机调试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
网上看帖子,感觉是内核的问题,
修改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 #复位机器

相关内容

    暂无相关文章