Installing Debian From Scratch

4138

Author: Bruce Byfield

Debian From Scratch (DFS) is not everyone’s distribution. It’s not an easy install. You need to know your hardware. You need to be prepared to take pains. And, at the end of the process, the result looks like any Debian system installed by another, usually easier and quicker, means. So why take the time?

One answer is that DFS offers a chance to learn about aspects of installation that you’ve never explored. Even if you have no background in computing, the do-it-yourself mentality of the free and open source communities is contagious. You may want to explore DFS out of sheer curiosity.

A more practical answer is that you want the security of building a GNU/Linux installation from the ground up, so that you know exactly what it contains and how the contents are installed. This behavior is in marked contrast to most distributions, which make choices that are not only unknown to the user, but which sometimes sacrifice security for convenience. For security-minded system administrators (that is, any who know their jobs), DFS not only gives them the control they want, but also saves them time when hardening a system. Since the base system installs without any graphical interfaces, this lack of assumptions makes DFS especially convenient for servers.

The basic steps for installing DFS are similar to those for Gentoo. Unfortunately, DFS current has only the bare minimum of documentation. The instructions that are available assume that the install posesses a reasonable amount of knowledge. That’s why, although installation is usually the least interesting part of a distro review, most of the rest of this article explains the installation process at length. DFS isn’t difficult to install if have the knowledge and take your time, but detailed instructions make the installation easier. They also save you from duplicating the mistakes I made in preparing this article.

DFS origins

DFS started last summer when John Goerzen, a long-time Debian developer and author of several books on Debian and Linux, found himself faced with two problems at the same time. He wanted an installer for Debian’s AMD64 port, and a rescue CD that would support filesystems like Reiser4 that are not available in the standard Debian rescue set. (The new Debian-Installer has since made DFS’s AMD64 installer unnecessary.) A bootable CD, he decided, would solve both problems. Modifying an existing bootable CD such as Knoppix seemed too complex, so he developed his own.

Once he had the LiveCD, adding the kind of fine-grained customizability that the Gentoo distro is known for was a small step. However, unlike Gentoo, by itself DFS doesn’t optimize packages for a specific system. To duplicate the complete Gentoo experience, you would have to combine DFS with apt-build.

Preparing to install

While you’re downloading the latest CD image for DFS and burning it to CD, take time to:

  • Review the man pages for /etc/resolv.conf, /etc/apt/sources.list, and /etc/network/interfaces to help you edit your DFS installation. You may also want to print out copies of these files from an existing Linux installation.
  • Run dpkg-query -l |more on an existing installation. You’ll get a list of packages, displayed one screen of text at a time. Study the list to decide what packages you’ll install.
  • Find an archive for packages from Debian’s server mirror list.
  • Plan how to partition your DFS system. You need at least a root and a swap partition. Many users also prefer separate partitions for /home, /var, /boot, and other directories.
  • Review how the GRUB boot manager works. In particular, pay attention to GRUB’s unique system of numbering hard drive partitions, in which /dev/hda1 or /dev/sda1 (that is, the first partition on either an EIDE or SCSI drive) is labeled hd0,0. You may want to print out an existing /boot/GRUB/menu.lst to consult.

If you want to run Windows on the same machine as DFS, install Windows first.

Starting the installation

As you start the DFS CD, the GRUB boot manager opens with a choice of 2.4 and 2.6 kernels, as well as 32- and 64-bit architectures. Once the CD finishes booting, log in as root with no password. The first thing you see is a list of useful commands. You can return to this list using the dfshints command.

With average luck, you won’t need the dfscd command to reset the drive that holds the CD. Many of the other commands may also be unnecessary. All the same, to be sure that DFS is detecting your hardware and setup, run at least /etc/init.d/hotplug start to detect USB devices, followed by /etc/init.d/discover start for general hardware detection. The order of these commands matters, because discover hangs if USB devices have not been detected before it runs. You can run other commands as your setup requires. The alternative is load kernel modules from the directory for the correct kernel version in /lib/modules/. If any hardware is not detected, you may need to recompile the kernel after installation is complete.

Once the system’s hardware is detected, you can start a DHCP connection by typing ifup eth0 (or whatever Ethernet card you are using). If you are not using a DHCP connection, then edit /etc/networking/interfaces, referring to the printout of the file’s content on another installation. A wireless connection works the same way, unless it’s encrypted, in which case you should read /usr/share/doc/wireless-tools/README.Debian on the CD, or search for information online. No matter what your setup, you will need the Internet to complete the installation, so do not continue until you have successfully configured a connection.

Partitioning, formatting, and mounting

The first step in installation is preparing the hard drive partitions. DFS includes fdisk and cfdisk, but by far the most powerful partitioning tool on the CD is parted, free software’s response to Partition Magic. Although parted seems limited to shrinking NTFS partitions by no more than 7 gigabytes, it otherwise provides reliable on-the-fly partitioning. If the help that accompanies parted isn’t enough, you can find full documentation on its home page.

Create at least a root and a swap partition, and mount them. As Goerzen suggests, /mnt is a convenient place for the root partition. For example:

mount /dev/hda1 /mnt

Swap partitions need to initiated and mounted. A typical example is:

mkswap -f /dev/hda2
swapon /dev/hda2

Naturally, hda1 and hda2 should be replaced by the actual partitions on the system.

Installing the basic system

Once the partitions are mounted, all you need to do is install the base system with the command:

cdebootstrap sid /mnt file:///opt/packages

Or, with an AMD64 system:

cdebootstrap -a amd64 sid /mnt file:///opt/packages

cdebootstrap is a command that installs a basic Debian system without using the usual package tools such as dpkg or apt. It is used only during installation, so chances are that you’ve never seen it before. The kernel that cdebootstrap installs is the one that you booted from.

Configuring the basic system

Configuring the base system is where installation starts to become finicky. None of the steps is especially difficult, but you do need to pay attention and do each step in order:

  1. Copy to the new system the /etc/resolv.conf file, which contains the basic information for your Internet connection.
  2. Edit /etc/apt/sources.list and copy the mirror addresses that you found before you started installing. You need sources.list for installing packages, so you won’t be able to finish the installation unless you complete this step.
  3. Edit /etc/network/interfaces and add the lines from the version of this file from an existing installation. Probably, the information in the file will be something like:
  4. 	auto lo
    	iface lo inet loopback
    	auto eth0
    	iface eth0 inet dhcp
    
  5. Mount the partition you created as the root partition. For example, if you mounted the partition at /mnt, type chroot /mnt

    The chroot command changes the root directory in the system. Since you have installed the base system, all the directories under /mnt now act as they would on a normal system.

Installing additional packages

Before you begin installing packages via apt-get install, type apt-get update to get a current list of available packages from the archives listed in /etc/apt/sources.list. Because DFS installs nothing except the core packages by default, you’re probably going to have a lot to install. That’s where the list from an existing installation comes in handy. Even if you don’t want to install everything that is on the existing system, the list gives you a place to start.

Remember that what you have already installed is a basic system, without the X Window System or any graphical tools. As a result, you may face problems that you don’t usually see in Debian: broken dependencies. The fastest way out of these problems is to install the gnome-desktop-environment or KDE package. These are dummy packages that will install everything you need to run a desktop.

To finish the configuration of DFS, you should also install the module-init-tools package, and either LILO or GRUB for a boot manager on an Intel system or aboot on an Alpha system. If you have a dialup connection, you should also install the PPP package.

Several factors affect the time that installation takes, including whether you are installing compiled or source packages, the speed of your Internet connection, and the number of packages. However, on a reasonably current computer, you can probably install a complete system of compiled packages in less than an hour. For source packages, expect at least three to five hours, and don’t be surprised if the process takes two or three times longer.

Configuring a boot manager

The final step is to configure a boot manager. Note that you must install a boot manager even if you have only DFS on the system; without one, the system can’t boot. You can use either GRUB or LILO; here are the instructions for using GRUB.

Begin by installing GRUB to the /boot directory with the following commands:

mkdir /boot/GRUB
cp /lib/GRUB/i386-pc/* /boot/GRUB

To configure GRUB, you have two choices. You can use the GRUB command and configure from the program prompt, or you can edit /boot/GRUB/menu.lst. Whichever method you choose, the final result for your root partition should look something like this:

title		Debian GNU/Linux, kernel 2.6
root		(hd0,1)
kernel		/boot/vmlinuz-2.6-1-386 root=/dev/sda2 ro 
initrd		/boot/initrd.img-2.6-1-386
savedefault
boot

If you have a version of Windows on the system, the listing for it in /boot/GRUB/menu.lst should resemble the following:

title		Windows XP
root		(hd0,0)
savedefault
makeactive
chainloader	+1

The main differences from these examples will be the exact kernel and partition names. You may also want to duplicate the GNU/Linux entry with the single option at the end of the kernel line so that you can use single-user mode for troubleshooting.

Should you run into problems with your GRUB entries, you can edit them from the program command line by pressing the c key as the GRUB menu appears at startup.

With this step, the installation of Debian From Scratch is complete. You can now remove the installation CD and reboot into your new system.

DFS as a rescue CD

A customized Debian installation isn’t all that DFS offers. Goerzen himself emphasizes the value of DFS as a rescue CD. DFS supports most major file systems, RAID, and LVM2, and includes several partition editors and a variety of programming environments sufficient to build new kernels and Debian packages. It even includes CD and printing tools, and full networking support. Its only lack is a graphical environment — a lack that, given DFS’s convenience, few users are likely to feel.

In the end, DFS doesn’t offer anything that can’t be found elsewhere. But, whether you want knowledge, security, or simply a handy collection of tools, DFS is a return to the basics that experienced Debian users will value.

Bruce Byfield teaches and writes about open source software.

Category:

  • Linux