Debugging kernel code requires a dedicated computer, as bugs may result in the system crashing or worse. (such as corrupted or overwritten file systems) Rather than dedicating a physical machine, we will be using the free version of VMWare Server as our test platform in this class.
We will run a stripped-down Linux distribution, CRUX Linux (http://www.crux.nu), on the virtual machine, for two reasons: (a) it takes less disk space, and (b) it boots quickly - this is something we are going to be doing a lot of, either after installing a new kernel, or after crashing.
The following directions walk you through (a) installing VMWare, (b) installing the linux distribution, and (c) compiling and booting a new kernel.
note - if you have SElinux enabled (e.g. if you're running CentOS 4.3) you won't be able to install VMWare. Remove the selinux policies first:
rpm -e selinux-policy-targeted
note for Macintosh users - this has been tested with a trial copy of build 1884 of Parallels for Mac, and with the appropriate substitutions (CD/ROM has to be primary slave to boot, so pass a kernel command line option; use IDE drive instead of SCSI) it seems to work.
cfdisk 2.12r
Disk Drive: /dev/sda
Size: 1342177280 bytes, 1342 MB
Heads: 255 Sectors per Track: 63 Cylinders: 163
Name Flags Part Type FS Type [Label] Size (MB)
---------------------------------------------------------------------
sda1 Primary Linux swap 254.99
sda2 Boot Primary Linux 1085.74
[Bootable] [ Delete ] [ Help ] [Maximize] [ Print ]
[ Quit ] [ Type ] [ Units ] [ Write ]
Be sure to (a) set the "Boot" flag on /dev/sda2 so you can boot from it, and (b) set the type of /dev/sda1 to "swap".
mkfs.ext3 /dev/sda2 mount /dev/sda2 /mnt mkswap /dev/sda1 swapon /dev/sda1
$ mount --bind /dev /mnt/dev $ mount --bind /tmp /mnt/tmp $ mount -t proc proc /mnt/proc $ mount -t sysfs none /mnt/sys $ chroot /mnt /bin/bash
/dev/sda2 / ext3 defaults 1 1 /dev/sda1 swap swap defaults 0 0
SERVICES=(net sshd)You can add other services, but you probably don't need them.
$ cd /usr/src/linux-2.6.15.6 $ cp linux-2.6.15.6-small.config .config $ make oldconfig $ make $ make modules_install $ cp arch/i386/boot/bzImage /boot/vmlinuz $ cp System.map /boot/System.map
$ grub grub> root (hd0,1) grub> setup (hd0) grub> quitNOTE - the standard CRUX instructions describe using LILO, an older linux boot loader, instead of Grub. In my experience this results in a virtual machine that will not boot.
Now you are done - you should be able to disconnect the CD/ROM (menu VM->CD/ROM->disconnect) and reboot into your newly installed virtual machine.