Freelance Projects

Upeksha Wisidagama

Compiling a Linux Kernel From Source Tarball

This is the third post about building a linux system from source files.

If you have rebooted your host after completing the steps described in the second post, first, mount the new system partition.

Our new system is on sdb disk.

‘Mounting the new system’
1
2
3
sudo su
export LFS=/mnt/lfs
mount -v -t ext3 /dev/sdb $LFS

Mounting the system filesystem

Mounting and Populating Device (Virtual) Filesystem

‘Mounting Dev Filesystem’
1
mount -v --bind /dev $LFS/dev

Mounting Virtual Kernel Filesystems

‘Mounting Virtual Kernel Filesystems’
1
2
3
mount -vt devpts devpts $LFS/dev/pts
mount -vt proc proc $LFS/proc
mount -vt sysfs sysfs $LFS/sys

Mounting Virtual Kernel Filesystems

Chroot to New System and Compile the Kernel

‘Chrooting into new System’
1
2
3
4
chroot "$LFS" /usr/bin/env -i \
    HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin \
    /bin/bash --login

‘Make MrProper’ ensures that the kernel tree is absolutely clean. The kernel team recommends that this command be issued prior to each kernel compilation. Do not rely on the source tree being clean after un-tarring.

Now run ‘make LANG=en_US LC_ALL= menuconfig’ after ‘make mrproper’.

Linux Kernel Configuration

Install the Fresh Linux Kernel in the Boot Directory

Finally run the following command to install the Linux Kernel in the Boot directory.

‘Install Kernel in Boot Directory’
1
2
make
cp -v arch/x86/boot/bzImage /boot/vmlinuz-3.8.1-upeksha-7.3

Now configure the Grub Bootloader and boot into the New Linux System.

Next: Booting and Logging into the New Linux System