Annvix
Personal tools



/Documentation/Dev/Building/Chroot

From Annvix

Developer's Reference: Building Annvix: Building a chroot

Development for Annvix is done largely by developers on their own systems, however not all developers may have extra hardware to dedicate to Annvix, or they may not want to dedicate what extra hardware they do have. If you don't mind a commercial product, VMWare is a useful tool. UML will likely be the cat's meow for Annvix development. At the moment, however, using a chroot to build and test packages is a very viable way to go and is probably one of the easiest ways to create an Annvix build environment.

The first step is to create the home for the chroot. For simplicity's sake, we are making a symlink so that we use /chroot for our base (this also can support multiple chroots).

# mkdir /home/chroot
# ln -s /home/chroot /
# export chroot=/chroot/annvix
# mkdir $chroot

Copy a Clean Install

The next step is to copy a clean install (at the moment, you will need to use a minimal Mandrakelinux 9.2). To do so, you will need to do the install on another partition or another computer. The following assumes you installed Mandrakelinux 9.2 in VMWare.

# rsync -av --one-file-system -l -t -e ssh root@vmware:/ $chroot/

If you are copying from another partition on the local machine you may use something like:

# rsync -av --one-file-system /mnt/9.2 $chroot/

The above assumes your clean install of Mandrakelinux 9.2 is mounted at /mnt/9.2. If you have /var and /usr mounted as separate partitions, you will need to repeat the above for each separate mount point; i.e.:

for i in "var usr"; do
  mkdir ${chroot}/{$i}
  rsync -av --one-file-system /mnt/9.2/${i} $chroot/${i}
done

Finally, you will need to re-create the /dev filesystem without devfs by remounting / and using rsync (you could also use MAKEDEV). On the host system, create /mnt/disk and execute:

# mount -o bind /mnt/disk
# rsync -av /mnt/disk/dev/ $chroot/dev/
# umount /mnt/disk

Setting up urpmi

Because you are using a clean minimal Mandrakelinux 9.2 install, there is no need to re-initialize urpmi or the rpm database. At this point you can enter the chroot by executing:

# chroot $chroot

Now you are in the chroot. If this is a true minimal install without any real configuration, you will need to do a few things. The first is to remove all urpmi medium because it will be looking for the install CD-ROMs (assuming that is how you created the clean install to begin with). This can be done by executing:

# urpmi.removemedia -a

Before you can add new media you will need to configure DNS in your chroot (unless you want to make all IP-based connections). This is simply done by editing /etc/resolv.conf within the chroot.

You will want to create new urpmi media for your chroot. Typically, you should have a mirror of the repositories you are interested in. For instance, until there is an actual Annvix installer, you will always need to bootstrap by using Mandrakelinux 9.2 as a base. Because of this, you should add three sources: the 9.2 install base, 9.2 updates, and the Annvix sources. The following examples will differ largely on whether you maintain a local mirror of any of the three sources or whether you need to use one on the internet. For the 9.2 install base, it is recommended that you copy all of the RPMs from the install CDs to a local system and use genhdlist to create a new hdlist. We'll assume that all three sources are stored on a server called files.mylan.net which allows local access only anonymous FTP to our sources (which would be mirrored onto that machine).

# urpmi.addmedia 92dis ftp://files.mylan.net/dis/9.2/RPMS with hdlist.cz
# urpmi.addmedia 92updates ftp://files.mylan.net/updates/9.2/RPMS \
  with ../base/hdlist.cz
# urpmi.addmedia annvix ftp://files.mylan.net/releases/1.0-CURRENT/i586/RPMS \
  with ../base/hdlist.cz

Final Configuration

If you do not have openssh-server already installed in your minimal install, install it now (you can do this from within the chroot).

# urpmi openssh-server

Edit /etc/ssh/sshd_config and change the Port setting from port 22 to some other port (ie. 24, 26, etc.). This will allow you to run sshd from within the chroot and not have it conflict with the sshd server running on the host. As well, you most likely will want to copy the host system's ssh host keys into the chroot. This is because if you intend to ssh into both the host and the chroot, your ssh client will complain about mismatched keys because both the chroot and the host will have the same IP address. To do this, exit the chroot and copy the host system's keys:

# exit
# cp -fv /etc/ssh/ssh*key* $chroot/etc/ssh
# chroot $chroot

Now that you are back in the chroot, you need to remove the .pid files from /var/run so that no automatic scripts will kill processes outside of the chroot (although this is fixed in initscripts for Mandrakelinux 9.2, it's still a good idea):

# rm -f /var/run/*.pid

Finally, remove all of the rc?.d scripts that restart services within the chroot:

# find /etc/rc.d/rc?.d -type l -exec rm -f {} \;

Now you can start sshd within the chroot:

# service sshd start

Use useradd/groupadd to create a user inside the chroot. You can now exit the chroot and use ssh to enter it.

# exit
# ssh localhost -p N

Where "N" is the port you configured in sshd_config.

Finally, you will need to make the /proc filesystem available to the chroot as some packages (MySQL comes to mind) require /proc to be mounted in order to compile properly. You may also wish to mount the /home partition from the host inside the chroot as well.

To mount /proc within the chroot, execute (from outside the chroot):

# mount -o bind /proc $chroot/proc

To mount /home within the chroot, execute (again, from outside the chroot):

# mount -o bind /home $chroot/home

The details of creating the chroot were initially created by Nanar (Nanar @ #mandrake on irc.freenode.net) and posted on the Mandrakesoft cooker wiki ChrootHowTo topic.





Sponsors: Cheap Flights - Credit Card Consolidation - Arizona Pools - Loans