FreeBSD Links

Freebsd.org

OpenPacket Blog

Arquivos

30/08/2005   03/09/2005   06/09/2005   09/09/2005   10/09/2005   03/10/2005  

This page is powered by Blogger. Isn't yours?

<body>

  How to create a Slackware environment using chroot

 


How to create a Slackware environment using chroot

Version [1.6.0], 24 May 2005 - for Slackware 10.1


 

This procedure is part of a modular series which allow building of various components using as a base the chroot Slackware environment described here. You will need a Linux machine connected to the internet, with basic GNU compiler tools installed (gcc, make, perhaps others).


Why?

A a fairly minimal Slackware Linux environment in a chroot install such as this could have a few purposes. You could use it to kickstart a cross-install, from another Linux such as Red Hat (Fedora), Debian, gentoo, if you already have Linux but would like Slackware on a spare drive or partition. I will leave it to you to figure out the necessary steps to arrange for the files to end up there, and to make the Slackware bootable.

Other typical uses include isolating things which may go crazy, such as new software or external network services. Yet another use could be to keep a pristine development environment in template form, which you can duplicate for several projects.
 


How?

Using BusyBox as the initial environment, it turns out to be easy! The full procedure can be performed in under a couple of hours, if you have a fast net connection and a fast cpu. Compiling BusyBox may take longer if your cpu is slow, and downloading the files may take longer if you are on a slow connection.

I installed a whole lot of packages that you may not want yourself. The core Slackware packages which you have to install alongside BusyBox, before you can use Slackware's simple package management tool installpkg is about this set:
 

  • aaa_base
  • etc
  • bash
  • e2fsprogs
  • glibc-2.3.2
  • libtermcap
  • tar
  • gzip
  • coreutils
  • pkgtools
  • grep
  • bin

Information on all the official Slackware packages can be found on whatever Slackware mirror you get them from, in a file called PACKAGES.TXT. The file MANIFEST.bz2 is useful for identifying which package contains a particular program.

You should also check the Slackware Security Advisories before using this procedure in a production environment, there may be security issues which have been discovered since the procedure was written.
 


The procedure

Conventions used

Throughout this procedure, red text denotes a literal command, or input or output, when that command, input or output is mentioned in the midst of a non-literal context.

Text in orange boxes is input to be typed at the Linux terminal command line. All wrapped input lines have a backslash character \ at the wrap-point, which the shell recognises. You should be able to simply copy-and-paste the input text, omitting the prompt, straight into a terminal window using the mouse.

Note that no spaces occur after the backslash, if you add spaces, the shell will misunderstand and correspondingly, appear to misbehave.

If an input line looks like it is wrapped, but has no terminating \, then it is not wrapped, and the subsequent lines are output shown for your information.

Commands which are to be entered while logged in as a regular user are shown prefixed with a common user prompt character, the dollar sign $.

Commands which are to be entered while logged in as root (after using su to become root) are denoted with a common root user prompt, the hash sign #.

Prompts are shown as markers, and should be omitted when copy-and-paste'ing the input to the terminal.

Text in blue boxes is informational, or may contain text to be entered into script or configuration files, again copy-and-paste is the best way to do this.


BusyBox

First obtain and compile BusyBox, which is used as the initial environment before there are enough Slackware tools to install the Slackware tools. BusyBox is like an entire one-file Linux distro! We should all praise and worship Erik, the guy who made it! Thanks Erik!

gpg is used to verify the file integrity of the downloaded tarball. The first gpg command given is simply to quietly initialise gpg in case it has never been used before (it may need to create some config files).

$ mkdir -p ~/incoming/slack10.1 $ cd ~/incoming/slack10.1 $ wget -c http://busybox.net/downloads/busybox-1.00.tar.gz \ http://busybox.net/downloads/busybox-1.00.tar.gz.sign  $ gpg --refresh-keys --keyserver pgp.mit.edu  $ gpg --keyserver pgp.mit.edu --recv-keys 0x30D39057 $ gpg --verify busybox-1.00.tar.gz.sign   $ tar -xvzf busybox-1.00.tar.gz $ cd busybox-1.00 

Now to configure busybox. Several methods exist. make config or make menuconfig can be used. A quick and repeatable shortcut though is presented here.

The first command creates a default configuration, using a series of files, ultimately resulting in .config in the current directory.

Next we modify this resultant configuration file, by simply echoing text to be appended at the end of it.

Lastly, make is instructed to rebuild the in-between files which would generate a configuration such as the one we have now created. This is necessary, but beyond the scope of this document.

$ make defconfig  $ echo CONFIG_STATIC=y >> .config $ echo CONFIG_USE_BB_PWD_GRP=y >> .config $ echo CONFIG_FEATURE_SH_STANDALONE_SHELL=y >> .config $ echo CONFIG_MD5SUM=y >> .config $ echo CONFIG_FEATURE_MD5_SHA1_SUM_CHECK=y >> .config  $ make oldconfig 

OK, now to compile it. The parameter given to make, -j3, should hurry things up a bit, by using three compiler threads when possible. Correspondingly, nice -n 19 will prevent this load from suppressing other tasks.

$ nice -n 19 make -j3 

That's it! Now you have a busybox executable, which we later copy to the chroot filetree and use the self-install feature enabled during the make config, above.


Slackware packages

Now to retrieve the Slackware files needed. It's up to you to decide if you want different files than I have used below. This should be enough so that the BusyBox tool isn't needed any more, which is good since BusyBox is slower than the tools it replaces.

The fileset given here is a good base set, from which you will be able to download and install other Slackware packages.

At the start of the wget command is the mirror I have chosen to use - it's a very fast mirror, in Switzerland. Perhaps for some reason you'd prefer a different mirror, if so, just replace that obvious part of the command.

$ cd ~/incoming/slack10.1  $ wget -c \ http://mirror.switch.ch/ftp/mirror/slackware/slackware-10.1/slackware\ {/a/aaa_base-10.1.0-noarch-2.tgz,/a/aaa_base-10.1.0-noarch-2.tgz.asc,\ /a/aaa_elflibs-10.1.0-i486-1.tgz.asc,/a/aaa_elflibs-10.1.0-i486-1.tgz,\ /a/bash-3.0-i486-2.tgz.asc,/a/bash-3.0-i486-2.tgz,\ /a/bin-9.2.0-i486-2.tgz.asc,/a/bin-9.2.0-i486-2.tgz,\ /a/bzip2-1.0.2-i486-5.tgz.asc,/a/bzip2-1.0.2-i486-5.tgz,\ /a/coreutils-5.2.1-i486-1.tgz.asc,/a/coreutils-5.2.1-i486-1.tgz,\ /a/e2fsprogs-1.35-i486-1.tgz.asc,/a/e2fsprogs-1.35-i486-1.tgz,\ /a/etc-5.1-noarch-9.tgz.asc,/a/etc-5.1-noarch-9.tgz,\ /a/findutils-4.1.7-i386-1.tgz.asc,/a/findutils-4.1.7-i386-1.tgz,\ /a/gawk-3.1.4-i486-1.tgz.asc,/a/gawk-3.1.4-i486-1.tgz,\ /a/gettext-0.14.1-i486-1.tgz.asc,/a/gettext-0.14.1-i486-1.tgz,\ /a/glibc-solibs-2.3.4-i486-1.tgz.asc,\ /a/glibc-solibs-2.3.4-i486-1.tgz,\ /a/glibc-zoneinfo-2.3.4-noarch-1.tgz.asc,\ /a/glibc-zoneinfo-2.3.4-noarch-1.tgz,\ /a/grep-2.5-i386-2.tgz.asc,/a/grep-2.5-i386-2.tgz,\ /a/gzip-1.3.3-i386-2.tgz.asc,/a/gzip-1.3.3-i386-2.tgz,\ /a/infozip-5.51-i486-1.tgz.asc,/a/infozip-5.51-i486-1.tgz,\ /a/less-382-i486-1.tgz.asc,/a/less-382-i486-1.tgz,\ /a/pkgtools-10.1.0-i486-4.tgz.asc,/a/pkgtools-10.1.0-i486-4.tgz,\ /a/sed-4.0.9-i486-2.tgz.asc,/a/sed-4.0.9-i486-2.tgz,\ /a/shadow-4.0.3-i486-11.tgz.asc,/a/shadow-4.0.3-i486-11.tgz,\ /a/tar-1.15.1-i486-1.tgz.asc,/a/tar-1.15.1-i486-1.tgz,\ /a/util-linux-2.12p-i486-1.tgz.asc,/a/util-linux-2.12p-i486-1.tgz,\ /d/perl-5.8.6-i486-1.tgz.asc,/d/perl-5.8.6-i486-1.tgz,\ /d/strace-4.5.4-i486-1.tgz.asc,/d/strace-4.5.4-i486-1.tgz,\ /l/expat-1.95.7-i486-1.tgz.asc,/l/expat-1.95.7-i486-1.tgz,\ /l/glibc-2.3.4-i486-1.tgz.asc,/l/glibc-2.3.4-i486-1.tgz,\ /l/glibc-i18n-2.3.4-noarch-1.tgz.asc,\ /l/glibc-i18n-2.3.4-noarch-1.tgz,\ /l/libtermcap-1.2.3-i486-6.tgz.asc,/l/libtermcap-1.2.3-i486-6.tgz,\ /l/ncurses-5.4-i486-2.tgz.asc,/l/ncurses-5.4-i486-2.tgz,\ /l/popt-1.7-i386-1.tgz.asc,/l/popt-1.7-i386-1.tgz,\ /l/readline-4.3-i486-3.tgz.asc,/l/readline-4.3-i486-3.tgz,\ /l/zlib-1.2.2-i486-1.tgz.asc,/l/zlib-1.2.2-i486-1.tgz,\ /n/gnupg-1.2.7-i486-1.tgz.asc,/n/gnupg-1.2.7-i486-1.tgz,\ /n/openssl-0.9.7e-i486-3.tgz.asc,/n/openssl-0.9.7e-i486-3.tgz,\ /n/wget-1.9.1-i486-1.tgz.asc,/n/wget-1.9.1-i486-1.tgz,\ /tcl/expect-5.41.0-i486-1.tgz.asc,/tcl/expect-5.41.0-i486-1.tgz,\ /tcl/tcl-8.4.6-i486-1.tgz.asc,/tcl/tcl-8.4.6-i486-1.tgz,\ /tcl/tclx-8.3.5-i386-1.tgz.asc,/tcl/tclx-8.3.5-i386-1.tgz} 


Verify integrity

Having retrieved the files, it's a good idea to check they are authentic and intact, using gpg which is a free PGP application.

First up, import the Slackware GPG key.

$ wget -O - http://slackware.com/gpg-key | gpg --import 

The multi-line command shown below will check each file using the already-downloaded signature files, and prompt you at the end of each page of output using the less command. Press the space bar at the end of each page until you reach END, then press q to quit.

$ for x in *.asc  do echo $x  gpg --verify "$x"  done 2>&1 | less 


Create initial chroot filetree

On with the show! Now to create a few directories for the chroot tree. I put all my chroots under a directory /chroot in the root of the host Linux system.

First step below is to su to root.

An empty directory tree is created, and the necessary files for the initial Slackware chroot environment are copied, including the busybox binary.

Untarring of the aaa_base tarball fleshes out the directory structure.

We also create several device nodes which allow access to kernel features needed by our very basic Slackware system. More nodes could be needed by specific applications, but for now this is enough.

$ su  # mkdir -p /chroot/slack10.1_base01/root/incoming # cp *.tgz /chroot/slack10.1_base01/root/incoming  # tar -xvzpf aaa_base-10.1.0-noarch-2.tgz -C /chroot/slack10.1_base01  # cp busybox-1.00/busybox /chroot/slack10.1_base01/bin/busybox  # mknod /chroot/slack10.1_base01/dev/null    c  1 3 # mknod /chroot/slack10.1_base01/dev/random  c  1 8 # mknod /chroot/slack10.1_base01/dev/urandom c  1 9  # cat /etc/hosts > /chroot/slack10.1_base01/etc/hosts # cat /etc/resolv.conf > /chroot/slack10.1_base01/etc/resolv.conf # cat /etc/localtime > /chroot/slack10.1_base01/etc/localtime 


Enter chroot

The chroot environment is in many ways like an entire, distinct machine of it's own. We need to mount the /proc filesystem within it, to allow kernel communication from within the new chroot, about certain system parameters that change from moment to moment.

The chroot command then puts you in the chroot, running the Ash shell provided by the busybox binary.

For best security using chroot, we always cd to the target chroot root directory before executing the chroot command. Our chroot command is preceded by env - in order to ensure that we do not pass any environment variables from the parent system into the chroot.

# mount -t proc proc /chroot/slack10.1_base01/proc/  # cd /chroot/slack10.1_base01 # env - /usr/sbin/chroot /chroot/slack10.1_base01 /bin/busybox ash 


Install Slackware

Next, . ./install/doinst.sh completes the installation of the aaa_base Slackware package, which was unzipped above, creating the basic Slackware file tree.

For the glibc install shellscript to work, we need to have cp available as a file (don't ask .. busybox's chroot looks for only files, doesn't know about busybox builtins, apparently, and the glibc install script uses chroot. I said not to ask.).

The subsequent steps install the other needed Slackware packages, until we are able to re-enter the chroot, this time using Slackware's provided bash shell, which is needed by pkgtools, then the system is able to install the rest of the packages itself with a single command.

The installation files, no longer needed, are deleted from the chroot - you should still have copies in your own home directory, saving you from re-downloading if you need to repeat the procedure.

Last of all, the /etc/mtab file is fixed up, to use the /proc system status information to track mount points, since otherwise the information given by mount will not keep in sync with your main system outside the chroot.

# . ./install/doinst.sh  # tar -xvpzf /root/incoming/glibc-2.3.4-i486-1.tgz  # ln -s /bin/busybox /bin/cp # . ./install/doinst.sh # rm /bin/cp  # tar -xvpzf /root/incoming/coreutils-5.2.1-i486-1.tgz  # . ./install/doinst.sh  # tar -xvpzf /root/incoming/etc-5.1-noarch-9.tgz  # . ./install/doinst.sh  # tar -xvpzf /root/incoming/libtermcap-1.2.3-i486-6.tgz  # . ./install/doinst.sh  # tar -xvpzf /root/incoming/bash-3.0-i486-2.tgz  # . ./install/doinst.sh  # tar -xvpzf /root/incoming/tar-1.15.1-i486-1.tgz  # . ./install/doinst.sh  # tar -xvpzf /root/incoming/gzip-1.3.3-i386-2.tgz  # . ./install/doinst.sh  # tar -xvpzf /root/incoming/grep-2.5-i386-2.tgz  # . ./install/doinst.sh  # tar -xvpzf /root/incoming/bin-9.2.0-i486-2.tgz  # . ./install/doinst.sh  # exit # env - /usr/sbin/chroot /chroot/slack10.1_base01 /bin/bash  # tar -xvpzf /root/incoming/pkgtools-10.1.0-i486-4.tgz  # . ./install/doinst.sh  # /sbin/installpkg /root/incoming/*.tgz  # rm -f /root/incoming/*  # rm -f /etc/mtab  # ln -s /proc/mounts /etc/mtab 


End of procedure

Congratulations! If you've followed the procedure succesfully, you should now have a working Slackware environment, in a chroot tree, on your own system!

Close down and exit chroot

Note that /proc is still mounted, and your login is still chrooted. Before trying to delete or copy the chroot environment, you must remember, to umount /proc.

If deleting, then you also need to have killed any processes which are running in the chroot, and have logged yourself out of it!

For now, we have no processes running, so just do this:

# umount /proc # exit 

You can use the environment interactively, typically first mounting /proc within the chroot, if it isn't already mounted there, then using chroot and the su command, as shown next.

This chroot command puts you in as the root user within the chroot environment.

# mount -t proc proc /chroot/slack10.1_base01/proc/  # cd /chroot/slack10.1_base01/ && \ env - /usr/sbin/chroot /chroot/slack10.1_base01 su - 

Later in this series I show you how to use the chroot environment to run services, such as a web server.

If you 'stuff up', and find you need to umount the /proc tree from outside of the chroot, here is the command to use.

# umount /chroot/slack10.1_base01/proc 

Template chroots

The completed chroot can be used as a template to start another chroot tree, (after first observing the points given above), eg to copy the now-inactive chroot we have just finished building as a template to start a new chroot,

# cp -a /chroot/slack10.1_base01 /chroot/slack10.1_sqlite01 

This technique is used throughout our series, so make sure you have plenty of space on tap! (Some hundreds of MB should be enough).

Good luck, and happy chrooting!


Changelog

  • 2005 May 24, 1.6.0 - Add info on requirements, fix up errors and poor HTML source formatting introduced when search-replace was used to add paragraph-close markup. Add bullets in changelog. Fix names.

    Update openssl. Copy parent environment /etc/localtime. Relocate busybox build in fs. Adopt more extensible chroot naming convention. Tested build on reiserfs, works OK without reiserfsprogs, despite need for e2fsprogs (see below). Use make nicely.

  • 2005 February 8, 1.5.0 - update for Slackware 10.1 - needed to add e2fsprogs or error on umount /proc

  • 2004 July 17, 1.4.0 - add red-text explanation to Conventions section

  • 2004 July 8, 1.2.0 - adopt changelog, change to Slackware version 10.0, better way of doing busybox config. Fix /etc/mtab symlink


To do

  • Evaluate.


Simeon Scott 2004-2005 <email shevek at bur dot st>
Please copy, modify and distribute this file, acknowledging me as author and link to original source.



<< InĂ­cio
Site Meter