BuildKernelWithChroot

Summary

This wiki page is the step-by-step document for build the environment of chroot for build kernel image

Install necessary package on host

host# sudo apt-get install schroot debootstrap dchroot

Where the root of chroot is

host# sudo mkdir /var/chroot

Before you start

There is an easy script that can do whole things that have to be done at host side that describe as below section. You can download this script and give it a try create_chroot.sh It should be run with root privilage.

$ ./create_chroot.sh
Usage: ./create_chroot.sh name corename arch location
 ex. ./create_chroot.sh hardy-lpia hardy lpia /var/chroot/hardy-lpia

$ sudo ./create_chroot.sh jaunty-lpia jaunty lpia /var/chroot/jaunty-lpia
I: Retrieving Release
I: Retrieving Packages
I: Validating Packages
I: Resolving dependencies of required packages...
I: Resolving dependencies of base packages...
...
postfix:*:14424:0:99999:7:::
statd:*:14425:0:99999:7:::

NOTE. there are three local files will be modified, they are
        /etc/schroot/schroot.conf
        /etc/fstab
        /etc/dchroot.conf
please check the modification isn't mixed up the files and you can find the backup files in the /tmp.

Done.

You can try to use the new chroot by
        sudo chroot /var/chroot/jaunty-lpia
or
        dchroot -c jaunty-lpia -d
Enjoy.

Modify the schroot config file

host# sudo vi /etc/schroot/schroot.conf
Append the following context

[hardy-lpia]
description=Ubuntu hardy lpia 32 bit
location=/var/chroot/hardy-lpia
priority=3
users=<your_userid_on_your_host>
groups=sbuild
root-groups=root
personality=linux32

Install basic package into chroot environment

host# sudo debootstrap --variant=buildd --arch lpia hardy /var/chroot/hardy-lpia http://ports.ubuntu.com/
host# sudo cp /etc/resolv.conf /var/chroot/hardy-lpia/etc/resolv.conf
host# sudo vi /var/chroot/hardy-lpia/etc/apt/sources.list
Remove everything and add following line

deb http://ports.ubuntu.com hardy main restricted multiverse universe
deb-src http://ports.ubuntu.com hardy main restricted multiverse universe

Now you can chroot in and install more package

host# sudo chroot /var/chroot/hardy-lpia
root@chroot# apt-get install gnupg; apt-get update
root@chroot# apt-get install wget debconf devscripts dialog nano vim debhelper locales sudo kernel-wedge fakeroot
root@chroot# locale-gen en_US.UTF-8
root@chroot# tzselect
root@chroot# exit

Bind several directory with chroot and host

host# sudo vi /etc/fstab
Append the following lines
Take care it will bind /home between your host and chroot environment
If you want to remove chroot environment, *umount them first*

#
# Hardy-lpia
#
/home           /var/chroot/hardy-lpia/home        none    bind            0       0
/tmp            /var/chroot/hardy-lpia/tmp         none    bind            0       0
/dev            /var/chroot/hardy-lpia/dev         none    bind            0       0
proc-chroot     /var/chroot/hardy-lpia/proc        proc    defaults        0       0
devpts-chroot   /var/chroot/hardy-lpia/dev/pts     devpts  defaults        0       0

host# sudo mount -a

Setup userid/password in chroot

host# sudo cp /etc/passwd /var/chroot/hardy-lpia/etc/
host# sudo sed 's/\([^:]*\):[^:]*:/\1:*:/' /etc/shadow | sudo tee /var/chroot/hardy-lpia/etc/shadow
host# sudo cp /etc/group /var/chroot/hardy-lpia/etc/
host# sudo cp /etc/hosts /var/chroot/hardy-lpia/etc/
host# sudo cp /etc/sudoers /var/chroot/hardy-lpia/etc/
host# sudo chroot /var/chroot/hardy-lpia/
chroot# dpkg-reconfigure passwd
chroot# passwd <your_userid_on_your_host>
chroot# echo hardy-lpia > /etc/debian_chroot
chroot# exit

Setup final information for dchroot.conf

host# sudo vi /etc/dchroot.conf
Append with the following content

hardy-lpia /var/chroot/hardy-lpia/

Congratulations, everything is done

host# dchroot -c hardy-lpia -d
your shall prompt shall be something like this

(hardy-lpia)ikepanhc@laptop:~$ 

KernelTeam/BuildKernelWithChroot (last edited 2009-11-11 07:58:25 by acelankao)