Home     Blog     Rss     Contact     Donate

Debian Debootstrap Install (AKA Installing Debian "the Arch way")


I’m not going to start by listing a number of reasons why you might want to do this. Chances are, if you found this guide it’s because you wanted to try it out, and have your reasons. If you don’t have any, then perhaps just the fun of it and the learning experience is more than valid enough.

I do want to point out that if you’re doing this expecting something even more minimal than a standard netinstall with nothing selected at tasksel (which is already minimal enough), you may or may not be disappointed. We’ll be using the –variant=minbase option, which will omit some packages, but chances are you’ll end up installing some of them later. Regardless, it’s still worth doing, so let’s get to it right away.

Pre Installation Notes


Switching to the root account


It’s a lot more convenient to switch to the root account. That way, no need to constantly type sudo. If the root account is locked, just typing sudo su or sudo su - will do.

Get the dependencies


We don’t need much dependencies. Only debootstrap and the Arch install scripts for convenience.


    # apt update && apt install debootstrap arch-install-scripts -y

Formatting and partitioning


Format your drive. I’m not going to go into detail on that one, because there’s a lot of different tools that does the job (fdisk, cfdisk, parted, etc) and which one is the best is merely a question of preference. I use cfdisk just because it’s what I’m used to. This guide, however, assumes you’re going to use separate boot (if installing on EFI systems), swap, root and home partitions.

Note: in KVM/QEMU, it’ll be vdX, rather than sdX.

Once the disk is formatted, make the partitions and mount them.


    # mkfs.fat -F 32 /dev/sdX1
    # mkswap /dev/sdX2
    # swapon /dev/sdX2
    # mkfs.ext4 /dev/sdX3
    # mkfs.ext4 /dev/sdX4

    # mount /dev/sdX3 /mnt
    # mkdir -p /mnt/{boot,home}
    # mount /dev/sdX1 /boot/efi
    # mount /dev/sdX4 /mnt/home

    # mkswap /dev/sdX1
    # swapon /dev/sdX1
    # mkfs.ext4 /dev/sdX2
    # mkfs.ext4 /dev/sdX3

    # mount /dev/sdX2 /mnt
    # mkdir -p /mnt/home
    # mount /dev/sdX3 /mnt/home

Deboostrap


With the disk partitioned and partitions mounted, we now run the debootstrap command. We will need a cli text editor in the chroot to modify some files, so we include one already. I use vim, but choose whatever floats your boat.


    # /usr/sbin/debootstrap --variant=minbase --include=vim bookworm \
    # /mnt http://deb.debian.org/debian/

Generate the fstab file


We need to create the fstab file. This is where the Arch install scripts come in handy. We’ll be using UUIDs with the -U option, rather than disk labels.


    # genfstab -U /mnt >> /mnt/etc/fstab

Before chrooting


Before we chroot, it's not a bad idea to properly set up apt's sources.list file. You can either copy the one from the iso to /mnt/etc/apt/, as long as it has all the proper sections, or, create the file with your preferred cli text editor. A good /etc/apt/sources.list file for Debian Bookworm:


    deb http://deb.debian.org/debian/ bookworm main non-free-firmware
    deb-src http://deb.debian.org/debian/ bookworm main non-free-firmware

    deb http://security.debian.org/debian-security bookworm-security main non-free-firmware
    deb-src http://security.debian.org/debian-security bookworm-security main non-free-firmware

    deb http://deb.debian.org/debian/ bookworm-updates main non-free-firmware
    deb-src http://deb.debian.org/debian/ bookworm-updates main non-free-firmware

If you’re planning on using ifupdown as your networking tool, and you’re doing this from a system which uses it, copy the interfaces file to the chroot.


    # cp /etc/network/interfaces /mnt/etc/network/interfaces

Do the same for the /etc/network/interfaces.d/ directory if it contains any files.

Chroot


Now is the time to chroot into the deboostrapped system


    # arch-chroot /mnt

Then, run apt update for good measure.

Installing init and the kernel


We need a kernel and init system. This could be done later but I prefer getting it out of the way first.


    # apt instal systemd systemd-sysv libpam-systemd libsystemd0

    # apt install sysvinit-core sysv-rc orphan-sysvinit-scripts elogind libpam-elogind

    # apt install linux-image-amd64

Swap amd64 for another architecture if you need.

Set Timezone


Run the follwing command and go through the steps


    # dpkg-reconfigure tzdata

Networking


This step depends on which networking tool you plan on using. I’ll use ifupdown (I’m a simple man, so it’s what I use) as an example.


    # apt install ifupdown wpasupplicant

Next, if you couldn't copy /etc/network/interfaces to the chroot because it was missing, you will need to create the proper file. You can refer to my ifupdown guide[2] on how to configure /etc/network/interfaces for either wired or wireless networks, or both, in detail, but for now, here’s a quick way to setup a basic ethernet connection with a dynamic IP address.

Find your interface's name with the find /sys/class/net command. Wired networks usually start with enp (eg. enp1s0). Then create /etc/network/interfaces, and add:


    source /etc/network/interfaces.d/*

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

    # The primary network-interface
    allow-hotplug enp1s0
    iface enp1s0 inet dhcp

Subsitute network-interface with your interface's name.

Hostname and hosts file


Choose a hostname for your system and add it to /etc/hostname:


    # echo "yourhostname" > /etc/hostname

Now, fill /etc/hosts with the following:


    127.0.0.1   localhost
    127.0.1.1   yourhostname

    # IPv6
    ::1         localhost ip6-localhost ip6-loopback
    ff02::1     ip6-allnodes
    ff02::2     ip6-allrouters

Locales and keyboard configuration



    # apt install locales
    # dpkg-reconfigure locales

    # apt install console-setup
    # dpkg-reconfigure keyboard-configuration

You may not want to run dpkg-reconfigure keyboard-configuration. I find it more trouble than it’s worth and it seems to me like it is not required, though it’s mentioned in most guides.

Certain changes to the keymap will only take effect once rebooted into the new install.

Users, passwords and authentication



    # passwd

    # useradd -m username
    # passwd username

Add the user to necessary groups, and give it the proper interactive shell. Debian uses bash as its default interactive shell, but you can choose whatever you like.


    # usermod -aG cdrom,floppy,audio,dip,video,plugdev,netdev username
    # usermod -s /bin/bash username

For doas:


    # apt install opendoas
    # echo "permit username" > /etc/doas.conf

For sudo:


    # apt install sudo
    # usermod -aG sudo username

Debian provides a pre-configured sudoers file, and you probably don’t need to change anything, but it’s wise to verify that the line under “allow members of group sudo …” is not commented out with the cat /etc/sudoers command.

Look at the output, and if the line is commented out, use the visudo command and uncomment it.

Setting up the bootloader


Here, grub is used. For other bootloaders, see their own documentation.


    # apt install grub-efi-amd64
    # grub-install --target=x86_64-efi --efi-directory=/boot/efi
    # update-grub

    # apt install grub-pc
    # grub-install /dev/sdX
    # update-grub

Finalizing


  1. Run apt clean for good measure.
  2. Remove resolv.conf so it gets recreated at boot: rm /etc/resolv.conf
  3. Exit the chroot with the exit command.
  4. Unmount the filesystems with umount just to be extra safe. Hint: unmount the devices mounted to /boot/efi and /home first before running umount /dev/sdX.

That's it. Reboot and enjoy.

[1] https://github.com/RagnarokOS/iso/releases
[2] https://lecorbeausvault.wordpress.com/2021/09/09/debian-using-ifup-ifdown-for-network-connections/

Originally posted on October 7, 2021.
Updated on June 18, 2023.