CLI Magic: Installing Debian GNU/Linux using debootstrap

715

Author: Manolis Tzanidakis

Most Debian GNU/Linux neophytes find that distribution’s default installer a bit difficult and ugly. While developers are working on a new installer for Debian Etch, there is a fully baked command-line alternative today: debootstrap.

With the current installer, installing Debian on newer systems with exotic hardware is not always a trivial process. The installation CD-ROMs include older versions of the Linux kernel that often lack support for modern hardware such as hard disk or RAID controllers and network adapters. Plus, the drivers for some hardware — most notably wireless LAN interfaces — are not part of the mainline kernel, or require binary firmware images that cannot be distributed by Debian.

If you’re not afraid of getting your hands dirty with the command line, you can try an alternative method for installing Debian. Debootstrap creates a basic Debian installation, and can also be used for creating custom, minimal installations on embedded systems or for replacing a pre-installed Linux distribution with Debian on a co-located server.

To try debootstrap, you will need a live CD that supports your hardware. I suggest using the latest version of GRML (0.8 at the time of this writing), which supports a wide range of hardware (check its kernel page for a complete list), and — because it is based on Debian — includes debootstrap by default.

After booting your system, verify that all hardware is detected. Since all required packages are downloaded off the Net, make sure that network works correctly. Next, set the timezone for your location with the tzconfig command on Debian-based distributions or manually create a symlink for your location from /usr/share/zoneinfo to /etc/localtime (e.g. ln -sf /usr/share/zoneinfo/Europe/Athens /etc/localtime). Set the clock with the date command (e.g. for 13:10, 08/25/2006 run date 082513102006), or if ntpdate is available, run ntpdate -u -v pool.ntp.org to synchronize to an Internet NTP server.

Now partition your hard disk with your favorite program (fdisk, cfdisk, parted, etc.). If you have an IDE hard disk, make sure to reboot so that the kernel picks the partition changes correctly. We’ll assume that your disk is hda (primary master IDE), and we’ll create three partitions: hda1 for / and hda3 for /home, both with the ext3 filesystem, and hda2 for swap. Create filesystems on the new partitions (feel free to replace mke2fs with the newfs command of your filesystem of choice), create a /mnt/debinst mount point, and mount the filesystems:


mkswap /dev/hda2
swapon /dev/hda2
mke2fs -j -b 4096 -O dir_index /dev/hda1
mke2fs -j -b 4096 -O dir_index /dev/hda3
mkdir /mnt/debinst
mount /dev/hda1 /mnt/debinst
mkdir /mnt/debinst/home
mount /dev/hda3 /mnt/debinst/home

If you aren’t using GRML, you need to download and unpack the debootstrap package at this point (the ar command used below is part of the binutils package):


mkdir /mnt/debinst/work
cd /mnt/debinst/work
wget http://ftp.debian.org/debian/pool/main/d/debootstrap/debootstrap-udeb_0.3.3_i386.udeb
ar -x debootstrap-udeb_0.3.3_i386.udeb
tar zxvpf data.tar.gz
export DEBOOTSTRAP_DIR=`pwd`/usr/lib/debootstrap
export PATH=$PATH:`pwd`/usr/sbin

Run debootstrap with debootstrap --arch i386 FLAVOR /mnt/debinst http://ftp.debian.org, replacing FLAVOR with either sarge, etch, or sid, depending on whether you want to install the stable, testing, or unstable branch of Debian, respectively. Also replace http://ftp.debian.org with your nearest mirror, and i386 with your CPU’s architecture. The debootstrap command will download all the required packages for a minimal Debian system and install them on /mnt/debinst. It will take a while too, depending on your connection.

After debootstrap finishes, chroot to the new installation and configure the system:


mount -t proc proc /mnt/debinst/proc
mount -o bind /dev /mnt/debinst/dev
LC_ALL= chroot /mnt/debinst /bin/bash

To configure things you will need an editor. Nano and NVI are available, but since it’s a Debian system you can apt-get install any editor at this point. First you need to create /etc/fstab with information about the filesystems (of course adjust it to match your setup):


# /etc/fstab: static file system information.
#
# file system	mount point	type	options		dump    pass
proc		/proc           proc    defaults	0	0
/dev/hda1       /		ext3	defaults	0	1
/dev/hda2	none		swap	sw		0	0
/dev/hda3	/home		ext3	nosuid,nodev	0	2
/dev/cdrom	/mnt/cdrom	iso9660	user,noauto,ro	0	0

Then you must configure the network. Set the hostname with echo Hostname > /etc/hostname and create /etc/network/interfaces. The following includes commented examples for DHCP and static IP configurations for the eth0 interface. Read the interfaces man page for more information:


## The loopback network interface
auto lo
iface lo inet loopback

## The primary network interface (eth0)
#auto eth0

# DHCP
#iface eth0 inet dhcp

# Static IP
#iface eth0 inet static
#	address 192.168.0.1
#	netmask 255.255.255.0
# 	broadcast 192.168.0.255
#	gateway 192.168.0.254

If you don’t use DHCP, make sure to create /etc/resolv.conf with DNS information for your network with the following command: echo -e "search domainnamennameserver 192.168.0.253nnameserver 192.168.0.254" > /etc/resolv.conf (replacing the words in italics). Also create /etc/hosts: echo -e "127.0.0.1tlocalhost.localdomaintHostname" > /etc/hosts.

To configure the keymap and other console options (such as screen-blanking timeout) install the console-tools and console-data packages and edit /etc/console-tools/config (the file includes commented examples). If you want to use a language other than English, install the locales package and select specific locales with dpkg-reconfigure locales. Don’t forget to set your time zone with tzconfig. Set the root’s password with passwd and optionally add a non-root user with the adduser USERNAME command; read the adduser man page for more information and available options.

The last remaining step is to install a kernel and a boot loader. Run apt-cache search linux-image to view available kernel packages and install one built for your CPU; e.g. for a system with dual Pentium 3s, apt-get install linux-image-2.6-686-smp. You can also build a custom kernel package; just install the kernel-package, libncurses5-dev, and bzip2 packages and read the make-kpkg man page for more information. I prefer the GRUB boot loader; run apt-get install grub to install it. To install GRUB on the master boot record of the first hard drive, run grub-install hd0. If the command fails with “Could not find device for /boot: Not found or not a block device,” run cat /proc/mounts > /etc/mtab and repeat. Debian has the wonderful tool update-grub, which creates GRUB’s configuration file automatically, so run it and answer y when it asks to create /boot/grub/menu.lst.

That’s it — your system should now be installed. You can install any additional packages you might need — udev, openntpd, sudo, etc. Leave the chroot environment with exit, unmount the filesystems (umount /mnt/debinst/{dev,proc,home} /mnt/debinst; swapoff /dev/hda2), and reboot to your new Debian system.