Making A Kernel Test Disk

This procedure describes how to create a disk that can be used to boot and test Linux kernels. This procedure will allow you to use one computer to build Linux kernels and another to boot and test them.

Here are the materials you will need for this:

  • A build computer - a system with development tools that will be used to compile Linux kernels.
  • A test computer - a system of similar architecture (probably x86), with BIOS that supports booting off USB devices, that will be used to test kernel builds.
  • External hard disk - with USB interface. I've used this procedure with a 4GB memory stick, which worked, albeit slower than a hard drive.
  • A Ubuntu Linux CD - the "desktop" version, which can be run as a live CD.

Part One - Setup the Hard Disk

  • Boot the test computer off the Ubuntu CD.
  • Plug the external disk drive into the USB.
  • Start a console terminal window:
    Applications -> Accessories -> Terminal
  • Run the command:
      $ sudo grub --device-map=/tmp/devs.map
      </dev/null
      Probing devices to guess BIOS drives. This may take a long
      time.
  • Run the command:
      $ cat /tmp/devs.map
      (fd0)   /dev/fd0
      (hd0)   /dev/hda
      (hd1)   /dev/sda
  • Look at the devs.map output and determine the ID of the external disk drive. The external disk drive typically appears as a SCSI drive (/dev/sdX), and it's the last drive listed. The above example was generated on a system that had one internal IDE disk (/dev/hda) and an external USB disk (/dev/sda). So, the device ID that I want in this case is "(hd1)". This will be needed later, when the GRUB boot loader is installed.
  • If you have any icons on the desktop for the external hard disk (you probably will if it was previously partitioned), dismount them by right-clicking the icon and selecting eject. I've seen the install fail if you try to run it with the external disk mounted.
  • Double-click the "Install" icon on the desktop to launch the Ubuntu installer.
  • Go through the install process.
  • At the "Select a disk (step 5 of 6)" screen, select the external hard drive. In this example, I'd select the "/dev/sda" entry.
  • At the "Prepare disk space" screen, the easiest thing to do is select "Erase entire disk". Or, if you want finer control over the partitioning, you can manually edit the partitioning table.
  • At the "Ready to install (step 6 of 6)" screen, verify that the "GRUB will be installed to" matches the device ID of the external drive, determined above. The default is "(hd0)". In my case, I needed to change that to "(hd1)". This is important! Without this change, the install on my system would install the GRUB boot loader to the internal IDE hard drive instead of the external USB disk.
  • Click install and the install process will begin. The install will run for about 20 minutes.
  • When the "Installation complete" pop-up window appears, do not click any buttons. Just push it off to the side for the time being, while we make a few patchups to the hard disk.
  • Edit the GRUB menu file, with a command such as:
      $ sudo vi /target/boot/grub/menu.lst
If you chose to install GRUB to a disk other than "(hd0)" you need to find all instances of that device ("hd1" in my example) and change them to "hd0". I had four instances of "(hd1,0)" and I changed them all to "(hd0,0)". This is important! That's because the external hard disk will become the first system drive (which is "hd0") when you boot off it. If you don't make this change, GRUB will look for Linux on a different hard drive when you boot.
  • Return to the "Installation complete" pop-up window and click the button to reboot the system.
  • Leave the external disk drive plugged in and verify you can boot Linux off of it. Note that there are timing issues booting off USB. My cold boot almost never works. I sometimes have to CTRL-ALT-DEL a couple times to get it to go to the external hard disk.
  • If all goes well, your system will boot to a graphical desktop. I recommend disabling services you won't need for kernel testing, particularly the graphical desktop. To do this, select:
      System -> Administration -> Services
I recommend turning off all the services except the following:
  • Computer activity logger (klogd)
  • Computer activity logger (sysklogd)
  • Graphical login manager (gdm)
  • System communication bus (dbus)
  • Finally, before dismissing the "Services setting" window, go back and turn off:
    • Graphical login manager (gdm)
    When prompted "Are you sure you want to deactivate gdm?" click "Yes". That will immediately terminate your graphical session. That's why you needed to save this setting for last.
  • System setup is complete. You can switch to a console (ALT-F1), login, and run:
      $ sudo shutdown -h now

Part Two - Build Linux and Install to the Hard Disk

      $ make defconfig
  • Build the kernel. I run a parallel make by running:
      $ make -j3
On my AMD Athlon64 X2 3800+ system (dual core, 2.00GHz), the initial build takes just under 4 minutes.
  • Plug the external drive into the build computer. If necessary, mount it. My workstation (Ubuntu Feisty) recognized the disk and automatically mounted it on /media/disk. In the rest of the instructions, I'm going to assume that's the directory where your drive is mounted.
  • Run the following commands (substituting your uid:gid for mine):
      $ sudo chown -R chip:chip /media/disk/boot
      $ sudo chown chip:chip
      /media/disk/lib/modules
This step allows you to install to the hard drive without superuser priviliges. This is important! It protects your workstation from accidental damage, caused by mistakenly overwriting a system file.
  • Install the newly built kernel to the external hard disk with the following commands:
      $ make install
      INSTALL_PATH=/media/disk/boot
      $ make modules_install
      INSTALL_MOD_PATH=/media/disk
  • Update the GRUB configuration on the external hard drive to boot the new kernel. Do:
      $ vi /media/disk/boot/grub/menu.lst
Add an entry (before all the other boot entries) that says:
      title       vmlinuz-2.6.20.7
      root        (hd0,0)
      kernel      /boot/vmlinuz-2.6.20.7 root=/dev/sda1 ro
      rootdelay=5
      boot
  • Be sure to replace vmlinuz-2.6.20.7 with the name of the kernel you built.
  • The root=/dev/sda1 may have to be adjusted, depending on your system configuration.
  • The rootdelay=5 avoids a problem with the time it takes the USB system to initialize. Without it, your system may not recognize the external disk.
  • Dismount the external hard disk, move it over to the test computer, and try to boot off it. Remember that cold booting off of USB can be a problem on some machines, and be prepared to CTRL-ALT-DEL if it doesn't recognize the external disk right away.