Saturday, October 21, 2006

Ubuntu Kernel Builds In A Virtual Machine

Use VMPlayer and Ubuntu server to create a virtual build system to compile custom Linux kernels for Ubuntu (and Debian?), quickly & easily.

Particularly useful for compiling kernels on faster machines for slower target system--which is exactly why I did this! Compiled custom kernels for a VIA C3 box on my AMD64 system. It saved me a lot of time and works marvelously well.

What you need:
  • The specifications for the target system for which you are going to build a custom kernel. Processor type, chipset information, etc. Google the model number of your mainboard to find the needed user manual and/or specs for your system.
  • VMPlayer
  • Build a Virtual Machine with EasyVMX
  • Ubuntu Server. Why? Fast, easy installation in the virtual environment. No need for all the extemporaneous desktop stuff, just a clean command line environment to compile kernels.
First, navigate to EasyVMX and configure your build system. These are the options that I chose as shown in the configuration file & image (click for a readable version) that follows. After downloading the Ubuntu Server iso image, you can either burn it to CD and install it to your VM from your drive or copy the .iso file into your VM directory & install it as a virtual CD:



#!/usr/bin/vmplayer

# Filename: Ubuntu_Build_Server.vmx
# Generated 2006-10-18;08:17:44 by EasyVMX!
# http://www.easyvmx.com

# This is a Workstation 5 or 5.5 config file
# It can be used with Player
config.version = "8"
virtualHW.version = "4"

# Selected operating system for your virtual machine
guestOS = "ubuntu"

# displayName is your own name for the virtual machine
displayName = "Ubuntu_Build_Server"

# These fields are free text description fields
guestinfo.vmware.product.url = "http://www.easyvmx.com/"
guestinfo.vmware.product.class = "virtual machine"

# Number of virtual CPUs. Your virtual machine will not
# work if this number is higher than the number of your physical CPUs
numvcpus = "1"

# Memory size and other memory settings
memsize = "320"
MemAllowAutoScaleDown = "FALSE"
MemTrimRate = "-1"

# Unique ID for the virtual machine will be created
uuid.action = "create"

# Remind to install VMware Tools
# This setting has no effect in VMware Player
tools.remindInstall = "TRUE"

# Startup hints interfers with automatic startup of a virtual machine
# This setting has no effect in VMware Player
hints.hideAll = "TRUE"

# Enable time synchronization between computer
# and virtual machine
tools.syncTime = "TRUE"

# First serial port, physical COM1 is not available
serial0.present = "FALSE"

# Optional second serial port, physical COM2 is not available
serial1.present = "FALSE"

# First parallell port, physical LPT1 is not available
parallel0.present = "FALSE"

# Logging
# This config activates logging, and keeps last log
logging = "TRUE"
log.fileName = "Ubuntu_Build_Server.log"
log.append = "TRUE"
log.keepOld = "1"

# These settings decides interaction between your
# computer and the virtual machine
isolation.tools.hgfs.disable = "FALSE"
isolation.tools.dnd.disable = "TRUE"
isolation.tools.copy.enable = "TRUE"
isolation.tools.paste.enabled = "TRUE"

# First network interface card
ethernet0.present = "TRUE"
ethernet0.virtualDev = "e1000"
ethernet0.connectionType = "nat"
ethernet0.addressType = "generated"
ethernet0.generatedAddressOffset = "0"

# Settings for physical floppy drive
floppy0.present = "FALSE"

# Settings for physical CDROM drive
ide1:0.present = "TRUE"
ide1:0.deviceType = "cdrom-raw"
ide1:0.startConnected = "TRUE"
ide1:0.fileName = "auto detect"
ide1:0.autodetect = "TRUE"

# Settings for the optional virtual CDROM, ISO-image
ide1:1.present = "TRUE"
ide1:1.fileName = "ubuntu-6.06.1-server-i386.iso"
ide1:1.deviceType = "cdrom-image"
ide1:1.mode = "persistent"
ide1:1.startConnected = "FALSE"
# Set the line about to TRUE if you wish to install from .iso file

# First IDE disk, size 4Gb
ide0:0.present = "TRUE"
ide0:0.fileName = "Ubuntu_Build_Server.vmdk"
ide0:0.mode = "persistent"
ide0:0.startConnected = "TRUE"
ide0:0.writeThrough = "TRUE"

# END OF EasyVMX! CONFIG


Install Ubuntu Server to your Virtual Machine via CD Rom or .iso file. The simple interface is very easy to navigate and you will be up and running in no time. Here are some of the defaults that I used. After installing it once you will probably be able to do it in your sleep...
  • English
  • United States
  • American English (keyboard)
  • hostname (of your choice)
  • Partition disks
    • Erase entire disk: IDE1 master (hda) - 4.3 GB VMware Virtual IDE
    • Write the changes to disks? Yes
  • Select your time zone
    • Is the system clock set to UTC? (probably not) No
  • Full Name for the new user: that's you!
    • Username for your account: totally up to you
    • Choose a password for the new user: remember this! It is not only your login password but you will need it for issuing commands as the root superuser with sudo.
  • The system installs... The CD ejects... Continue is highlighted... Remove the CD & press Enter. The VM reboots and you can now login.
Remember, the sudo password = your login password.

Now it's time to get the needed pieces for building kernels installed on your VM and ready to go.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install linux-image-k7 (or the kernel that best suits your particular host system, or skip this if the standard server kernel is acceptable)
sudo telinit 6

Log back into the VM. If you are connected to the internet via broadband and don't want to deal with the install CD, remove it from the apt sources file:

sudo nano /etc/apt/sources.list


Comment out the following line near the beginning of the file by adding a # to the start of the line as follows:

# deb cdrom:[Ubunutu-Server 6.06.1 _Dapper Drake_ - Release i386 (20060807.1)]/ dapper main restricted


Ctrl+x
Y [Enter] to save the changes

sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install kernel-package
sudo apt-get install libncurses5-dev
sudo apt-get install linux-source
cd /usr/src
sudo tar -xjvf linux-source-2.6.15.tar.bz2
sudo ln -s /usr/src/linux-source-2.6.15 /usr/src/linux
cd /usr/src/linux

sudo make clean
sudo make mrproper
sudo make oldconfig
sudo make menuconfig


Modify the kernel options as desired for your target system. Particularly you will probably want to go to Processor Type & Features and select the correct processor for your target system and save your new config when finished.



sudo make-kpkg clean
sudo make-kpkg --initrd --append-to-version=-custom kernel_image kernel_headers


Insert what you want in place of "custom" (lowercase) to identify your custom kernel.

Let the compiling begin!

cd /usr/src
ls


You should see your new custom kernel packages, for example:

kernel-image-2.6.15-custom_10.00.Custom_i386.deb
kernel-headers-2.6.15-custom_10.00.Custom_i386.deb

Copy these to your target system and install them with the following:

sudo dpkg -i kernel-image-2.6.15-custom_10.00.Custom_i386.deb
sudo dpkg -i kernel-headers-2.6.15-custom_10.00.Custom_i386.deb
sudo telinit 6

The system will reboot, and you can verify that you are running your new custom kernel with the command:

cat /proc/version

Credit goes to this doc for providing several pieces for this how-to:
http://ubuntuforums.org/showthread.php?s=0d310eadb229405b090ab3fab7090ab7&t=56835


Tags:

No comments: