Debian Chroot Install 

Revision r1.12 - 17 May 2004 - DrewKime

http://twiki.iwethey.org/twiki/bin/view/Main/DebianChrootInstall

Summary 

Debian GNU/Linux offers a number of installation options. These are well documented in the Debian Installation Instructions. Instructions for a remote Debian chroot install are available in HOWTO - Install Debian Onto a Remote Linux System. http://www.underhanded.org/papers/debian-conversion/remotedeb.html

The instructions here have been largely incorporated into Installing Debian GNU/Linux 3.0 For Intel x86 http://www.debian.org/releases/stable/i386/install also covers this as Installing Debian GNU/Linux from a Unix/Linux System, describing a "zero downtime" Debian install. The primary difference is use of debootstrap rather than the Potato base filesystem image to bootstrap the process. I've tried both, both work well.

The goal is to end up with an unpacked tarball of the base system on a partition, with a working, bootable, kernel, and networking, from which additional configuration may be performed. The means:

  1. Booting some other OS on the system.
  2. Partitioning the system as desired.
  3. Transferring the base image.
  4. Unpacking the base image.
  5. Chrooting into the base system.
  6. Completing installation tasks normally handled by the Debian installer.
  7. Further OS configuration and package installs.

Note that this really is an exercise in flexibility. That is: there's more than one way to do it. Adapting methods to your circumstances is encouraged, though we're going to try providing instructions which, if followed, result in a working Debian GNU/Linux install.

Also note that there's more than one way to do it. A method for installing Debian under an existing GNU/Linux or other Unix system, remotely, is described at http://trilldev.sourceforge.net/files/remotedeb.html, as well as the official Debian installation documentation mentioned earlier.

Why Do It This Way? 

The advantage to this method is that you're working in a chrooted environment. Outside this "chroot jail", you've got a fully capable GNU/Linux system — more so if you're using KNOPIX, the LNX-BBC, other bootable "desktop" GNU/Linux systems, or an existing install. If you're booting from removable media, you can modify any fixed storage (aka hard drives) on the installation system without affecting the system that's running.

Once you've got the new Debian system configured to your preference, you can migrate your existing user data (if any) to it, and keep on rolling. Thus this is also a "zero downtime" GNU/Linux install. It's also a damned good way for dealing with hardware that otherwise doesn't play friendly with various boot or installation media.

Method 

A Few General Notes and Caveats 

A chroot changes the system root for the chrooted process (your chroot shell) and its children. You're in an environment, not a "new instance" of GNU/Linux — you're running the original system kernel, and have access to resources such as networking, device drivers (kernel modules) and (if you provide mountpoints) removable or fixed media as well. What you do have is a new "effective" top level root directory for the purposes of the install.

Your host environment will provide you much of the support that's difficult to get during a standard install. So while you will be configuring, say, networking and module support for the new install while in the chroot, you won't actually be applying these configurations until after you boot into the chroot (or move the chroot drive to a target system and boot it).

Services are a special concern. Debian likes to start up services after they've been installed. Running a chroot, you may find yourself with two instances of, say, Apache running. Since network ports are external to the chroot (they're a kernel interface), you can run into problems. Use care when setting up services, especially if your host is a production box of some sort.

Getting Started 

Boot whatever your bootable system that works and you're comfortable with.

Transferring The Base Image 

Note: if you are performing a debootstrap install, this section does not apply to you, as debootstrap obtains the base installation system by different means. Please see the Debian Installation Manual for this step

Change to the installation root and unpack: cd /mnt/debinst TRB's tar doesn't handle gzipped archives natively… zcat < /mnt/utility/base2_2.tgz | tar xvf

When you're sure you're done with the image tarball itself, you can delete it. This can happen at any later time.

Configuring The Base System 

Note: deboostrap folks can largely follow the remaining instructions in this article.

You've now got a real Debian system, though rather lean, on disk. Chroot into it:

chroot . bin/bash

OK. You've got a few things to configure that would ordinarily be handled by the installed (dbootstrap):

  • partitioning
  • networking
  • keyboard
  • language
  • time zone
  • user account
  • apt sources
Partitioning and Filesystems 

You've already dealt with partitioning, no need to revisit this. You need to create /etc/fstab, however. While you don't need mount additional filesystems, this is a good time to do so. You'll probably want to activate swap and the proc filesystem.

You can mount the proc filesystem multiple times and to arbitrary locations, though /proc is customary. It will make certain other tasks easier, so do this now:

mount -t proc proc /proc

Mount any additional filesystems. Note that these filesystems are mounted under the chroot.

Networking 

I'll assume you've got networking handled through your boot system, for the duration of your chroot installation process. This section mostly covers configuring networking for use after installation, when you actually boot your newly installed system.

It's possible that name resolution won't work until /etc/resolv.conf is properly configured. Under Knoppix, this may be symlinked outside the chroot. You'll have to break (delete) the link and create a regular file with your nameserver(s), and (optionally) domain and search directives.

You still likely don't have networking configured to come up on the installed system. This requires hand edits of:

  • /etc/resolv.conf — your nameserver(s) and search directives go here.
  • /etc/network/interfaces — see /usr/share/doc/ifupdown/examples for examples. This configures your interfaces. In general, you need to know your IP, network, netmask, network, broadcast, and gateway.
  • /etc/hostname — your system's host name — 2 - 63 characters.
  • /etc/hosts — 127.0.0.1 your_system's_host_name (required for some services)
Keyboard, Language, & Timezone: base-config 

Note: Applying these settings will affect both the chroot and host environment, though the configuration files themselves are persistant only in the chroot install.

Basics of system setup are handled by base-config

dpkg-reconfigure base-config
base-config

(You may have to run 'dpkg —install —reinstall base-config' instead to force this).

User Account 

And, if the system hasn't already prompted you, set up a nonpriviledged user account:

adduser <username>        # ...and follow prompts.
passwd <username>
Configure apt sources 

OK, now, munge /etc/apt/sources.list to your preference. You can use apt-setup or edit the file by hand. If you want to run a 'testing' or 'unstable' system, you can make this switch now. After the edits (and setting the $http_proxy environment variable if necessary:

apt-get update
apt-get dist-upgrade
Delete "unconfigured.sh" 
[Note]

Not sure this applies in a deboostrap install, but make sure the file isn't present.

The file /sbin/unconfigured.sh will prevent your system from starting up normally if it exists (it is checked for in /etc/init.d/rcS). Delete or rename this file prior to rebooting your system.

Rebooting 

You'll need to umount any filesystems mounted under the chroot manually, before exiting your chroot process. Your chroot mountpoint itself is generally not mounted under the chroot, but under the host system. Remember which environment you're in when running your shutdown or reboot command, particularly if your host is a live install. Bootable CD distros are considerably more tolerant to unclean shutdowns.

Reboot to confirm your settings. If your system doesn't come up, you've got your boot disk (TRB/LNX-BBC) to salvage you. Chroot into the installation, mess with your bootloader, and try again.

Common boot errors include:

  • Not installing a kernel.
  • Not installing a bootloader.
  • Not configuring your bootlader ('lilo', or 'grub-install; vi * /boot/grub/menu.list; update-grub', or whatever's appropriate for your bootloader).
  • Not properly specifying your root, boot, or kernel image filesystems.
  • Not properly configuring initrd support in your bootloader.
  • Not properly configuring filesystem modules in your kernel, initrd, or base system.

Further Configuration and Package Installs 

From here, you can build out the system by:

Applying an existing package list to your new system 

# On other box:
dpkg --get-selections > file
$EDIT file

# Transfer file to your new system (floppy, network, carrier
# pigeon, whatever).

dpkg --set-selections < file

# In theory, the following works, though I had to kick it a few
# times to make it go right:

apt-get dist-upgrade            # This should work.
apt-get dselect-upgrade         # This is what I ended up using.

documented on: 2006.06.20