debootstrap is used to create a Debian base system from scratch,
without requiring the availability of dpkg or apt. It does this
by downloading .deb files from a mirror site, and carefully
unpacking them into a directory which can eventually be chrooted
into.
debootstrap is not far easier than creating a bootable Ubuntu live USB or burning an Ubuntu ISO image. It is not even easier than booting from the Ubuntu Minimal CD which is a lightweight, text-only Ubuntu installer that can boot on many computers which can't boot the full-sized Ubuntu installer media. The Ubuntu Minimal CD allows you to install package groups which is very convenient, and you can also install the same package groups without using the Ubuntu Minimal CD by installing the tasksel package.
Install debootstrap
If you are installing from a non-Debian based distribution, your
distribution may or may not have debootstrap available. To get
debootstrap, you can download it directly from a Debian mirror.
To view the packages available, use a web browser, or use this
command:
wget --no-remove-listing -O /tmp/deboot.html -q http://ftp.us.debian.org/debian/pool/main/d/debootstrap && grep 'all.deb' /tmp/deboot.html | awk -F 'href' '{print $2}' | cut -d '"' -f2
The latest version of debootstrap is debootstrap_1.0.123_all.deb
wget -P /tmp/debootstrap http://ftp.us.debian.org/debian/pool/main/d/debootstrap/debootstrap_1.0.123_all.deb
Unpacking the .deb file
cd /tmp/debootstrap
ar vx debootstrap_1.0.123_all.deb
tar -xf data.tar.gz
Temporary setup
sudo ln -s /tmp/debootstrap/usr/sbin/debootstrap /usr/sbin/debootstrap
sudo ln -s /tmp/debootstrap/usr/share/debootstrap /usr/share/debootstrap
Setup the target partition for install
Create your filesystem, your mount point, and mount your partition:
sudo mkfs.ext4 -L Debian /dev/sda1
sudo mkdir /mnt/deboot
sudo mount -t ext4 /dev/sda1 /mnt/deboot
Installing the base system with network access
sudo debootstrap --arch amd64 focal /mnt/deboot http://archive.ubuntu.com/ubuntu
Preparing the chroot environment
Copy the mounted file systems table. It keeps the df command happy.
(It will be overwritten upon boot.)
sudo cp /etc/mtab /mnt/deboot/etc/mtab
Binding the virtual filesystems. Until your new install is booting on
it's own, we'll borrow these from the host.
sudo mount -o bind /dev /mnt/deboot/dev
sudo mount -o bind /proc /mnt/deboot/proc
sudo mount -o bind /sys /mnt/deboot/sys
Continuing the installation within chroot
Entering the chroot environment:
sudo chroot /mnt/deboot /bin/bash
Since we used the --include
option to get grub, it was installed,
but not configured.
sudo grub-install /dev/sda
sudo update-grub
Setting up /etc/fstab
for the root filesystem. Use the blkid
command to get the UUID of /dev/sda1.
sudo blkid /dev/sda1
Then add this entry to /etc/fstab
using the UUID output from the
command above:
sudo UUID=79168060-9d9c-4cf6-8ee9-bb846aee589b / ext4 defaults,errors=remount-ro 0 1
Give your new install a name. If not, your new install won't have a
name, or inherit the name of the host you are installing from.
sudo echo "<name-your-host>" > /etc/hostname
Configure your locale.
sudo dpkg-reconfigure locales
Create a password for root.
sudo chroot# passwd
Create a normal user.
sudo adduser <your-user-name>
Setting up the network (eth0)
Some basic tools are already included to manage your network, but
nothing is configured for you yet. If you plan on installing a desktop
environment, that may bring in tools such as network-manager or wicd
to automatically configure your network.
You can bring up your network manually each boot with the tools
dhclient or ifconfig.
For a dynamic IP (DHCP):
sudo dhclient -v eth0
For a static IP:
sudo ifconfig -v eth0 192.0.2.7 netmask 255.255.255.0 up
You can have this automatically done for you when the system boots by
editing the file below.
For DHCP, the /etc/network/interfaces
file should look like this:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
The loopback network interface
auto lo
iface lo inet loopback
The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp
For a static IP, the /etc/network/interfaces
file should look like
this:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
The loopback network interface
auto lo
iface lo inet loopback
The primary network interface
auto eth0
iface eth0 inet static
address 192.0.2.7
netmask 255.255.255.0
gateway 192.0.2.254
Install a display manager and a window manager
Unless you're using this for a headless server, might be nice to have
some sort of desktop to play with. Don't forget to update the package
manager if you wish to install new packages:
sudo apt-get update
Here are some examples of installing a desktop:
sudo apt install xserver-xorg wdm fluxbox xterm # -or -
sudo apt install xserver-xorg lightdm xfce4 # -or -
sudo apt install gdm3 gnome # -or -
sudo apt install kdm kde-standard
You can use also use tasksel to install a desktop for you. To see the
available options:
sudo tasksel --new-install
Finishing the install
Clean the package cache:
sudo apt-get clean
Update the ramdisk:
sudo update-initramfs -u -k all
Exit the chroot environment:
sudo exit