http://code.google.com/p/linuxopenbsm/wiki/KernelDebugUserModeLinux Kernel Debugging under Gentoo LinuxCompiling the host Kernel/* FIXME : SKAS */ # cd /usr/src/linux # make menuconfig [ Networking -> ... -> Netfilter -> (activate IP Tables support & Full NAT Masq & IPv4 connection tracking support ] [ & netfilter Xtables support & netfilter connection tracking support) ] [ Device Drivers -> Network Device Support -> Universal TUN/TAP device driver support ] # make && make modules && make modules_install # cp .config /boot/config-2.6.x.x # cp arch/{x86,i386}/boot/bzImage /boot/kernel-2.6.x.x # reboot Compiling the UML KernelDownload the vanilla sources into ~/ $ cd linux-2.6.25-rc6 $ make defconfig ARCH=um $ make menuconfig ARCH=um [ General Setup -> Auditing Support ] [ General Setup -> Enable system-call auditing support ] $ make linux modules ARCH=um Preparing the filesystems# nano -w /etc/fstab [ HOST system ] [ change the following ] [ #shm /dev/shm tmpfs nodev,nosuid,noexec 0 0 ] [ shm /dev/shm tmpfs nodev,nosuid 0 0 ] Download stage3 and the latest portage tree from http://mirror.ovh.net/gentoo-distfiles/releases/x86 General Way # emerge gdb # emerge usermode-utilities # mkdir /mnt/loop # mkdir /mnt/gentoo # cd /mnt/gentoo # tar xvjpf /path/to/stage3.tar.bz2 # cp -L /etc/resolv.conf /mnt/gentoo/etc/. # cd /path/to/linux # make modules_install INSTALL_MOD_PATH=/mnt/gentoo ARCH=um # cp /path/to/linux/System.map /mnt/gentoo # chroot /mnt/gentoo /bin/bash (chroot-env) # env-update (chroot-env) # source /etc/profile (chroot-env) # nano -w /etc/fstab (chroot-env) [ /dev/BOOT ------> #/dev/BOOT ] (chroot-env) [ /dev/ROOT ------> /dev/ubda ] (chroot-env) [ /dev/SWAP ------> /dev/ubdb ] (chroot-env) # nano -w /etc/inittab (chroot-env) [ in section # TERMINALS comment out ALL cX and add ] (chroot-env) [ c0:12345:respawn:/sbin/agetty 38400 tty0 linux ] (chroot-env) # passwd (chroot-env) # rc-update del consolefont boot (chroot-env) # rc-update del keymaps boot (chroot-env) # exit # cd /mnt/gentoo # tar cvjpf ~/gentoo.tar.bz2 * # cd # rm -rf /mnt/gentoo # dd if=/dev/zero of=root_fs seek=500 count=1 bs=1M # mke2fs -jF root_fs # mount -o loop root_fs /mnt/loop # tar xvjpf gentoo.tar.bz2 -C /mnt/loop # umount /mnt/loop # dd if=/dev/zero of=swap_fs seek=500 count=1 bs=1M # mkswap -f swap_fs Now you should be able to boot the UML system. Try it with # /path/to/linux ubd0=/root/root_fs ubd1=/root/swap_fs
My Way # emerge gdb # emerge usermode-utilities # cfdisk [ allocate 6000MB to a new partition on freespace ] # reboot # mke2fs -j /dev/hda5 [ partition created with cfdisk ] # mkdir /mnt/gentoo # mount /dev/hda5 /mnt/gentoo # cd /mnt/gentoo # tar xvjpf /path/to/stage3.tar.bz2 # tar xvfj /path/to/portage.tar.bz2 -C /mnt/gentoo/usr # cp -L /etc/resolv.conf /mnt/gentoo/etc/. # cp -L /etc/make.conf /mnt/gentoo/etc/make.conf # cd /path/to/linux # make modules_install INSTALL_MOD_PATH=/mnt/gentoo ARCH=um # cp /path/to/linux/System.map /mnt/gentoo # chroot /mnt/gentoo /bin/bash (chroot-env) # env-update (chroot-env) # source /etc/profile (chroot-env) # nano -w /etc/fstab (chroot-env) [ /dev/BOOT ------> #/dev/BOOT ] (chroot-env) [ /dev/ROOT ------> /dev/ubda ] (chroot-env) [ /dev/SWAP ------> /dev/ubdb ] (chroot-env) # nano -w /etc/inittab (chroot-env) [ in section # TERMINALS comment out ALL cX and add ] (chroot-env) [ c0:12345:respawn:/sbin/agetty 38400 tty0 linux ] (chroot-env) # emerge --sync (chroot-env) # emerge syslog-ng (chroot-env) # rc-update add syslog-ng default (chroot-env) # emerge audit (chroot-env) # rc-update add auditd default (chroot-env) # rc-update del consolefont boot (chroot-env) # rc-update del keymaps boot (chroot-env) # passwd (chroot-env) # exit # cd # umount /mnt/gentoo # dd if=/dev/zero of=swap_fs seek=500 count=1 bs=1M # mkswap -f swap_fs Now you should be able to boot the UML system. Try it with # /path/to/linux ubd0=/dev/hda5 ubd1=/root/swap_fs
Networking# ln -s /usr/src/linux.2.6.20.9-skas linux # emerge iptables # iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE # echo 1 > /proc/sys/net/ipv4/ip_forward # /path/to/linux ubd0=/root/root_fs ubd1=/root/swap_fs eth0=tuntap,,,10.10.10.2 (host ip) # ifconfig eth0 10.10.10.100 up # route add default gw 10.10.10.2 # ping -c 3 www.google.com [ if you want to store these config do the following ] # nano -w /etc/conf.d/net [ config_eth0=("10.10.10.100 netmask 255.255.255.0 brd 10.10.10.255") ] [ routes_eth0=("default via 10.10.10.2") ] # rc-update add net.eth0 default Booting UMLBoot the UML system with all the previous settings enabled # iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE # echo 1 > /proc/sys/net/ipv4/ip_forward # /path/to/linux ubd0=/dev/hda5 ubd1=/root/swap_fs audit=1 eth0=tuntap,,,10.10.10.2 Debugging# gdb /path/to/linux [ linux is the exec file into the UML kernel sources after compilation ] (gdb) handle SIGUSR1 pass nostop noprint (gdb) handle SIGSEGV pass nostop noprint (gdb) run ubd0=/root/root_fs ubd1=/root/swap_fs audit=1 [ KERNEL BOOT] login: [ to return to gdb prompt use 'kill -2 pid' on another console where pid is the first PID in ps aux related to ...linux ubd0.... ] (gdb) b audit_syscall_entry (gdb) c [ now is going to break whenever audit_syscall_entry is called ] |
- [linuxkernelnewbies] KernelDebug - linuxopenbsm - UserModeLinux... Peter Teoh