# The Art of Installing Debian the Arch-way
Around 2005, I published in my personal blog in Wordpress a small tutorial on _how to install Debian the Nerd-way_. That post is long gone now, and it was more like a small reference guide for myself than anything else. Recently I tried some of those steps again just for fun to see they still work and they do!
As you move on in this tutorial, you will notice it resembles a lot the Arch Linux installation method (hence the title). That's not a surprise since all of this existed even before Arch was popularized.
This work grabs some steps from the [Instaling Debian GNU/Linux from a Unix/Linux System](https://www.debian.org/releases/stable/amd64/apds03.en.html), in the Random Bits appendix from the Debian documentation. I decided to create one of my own because some of those steps could be either abbreviated or more detailed.
**DISCLAIMER**: as you already suspect, these steps will _potentially break your system_! **Read every step carefully** and check what applies to your scenario. I will try to be the more detailed and thorough I can, but I cannot predict every situation. I recommend practicing these steps in a virtual machine before trying in your real PC.
## Why?
Mainly, for two reasons. First, as a _Linux enthusiast_, I've been a Debian-fan for decades now. Debian pioneered the art of installing software in Linux environments, something they bundled and called _packages_. The `dpkg` and `apt-get` tools revolutionized the way software is installed on Linux, and they remain relevant up to today. Second, as a _software developer_, I like my OS environment **lean and clean**. That means I dislike useless packages floating around my system. Manually installing only what you need gives you the power to build the environment as you like.
In the end, you will understand how any Linux Distro works. _Mastering the art of Linux installation_ will give you powers to modify and recover virtually any Linux installation from any situation.
## Booting and preparing the live environment
The first thing you'll need is a running environment to start on. I recommend downloading one of the [Ubuntu live CD's](https://ubuntu.com/download/desktop). Even better are the [Ubuntu flavors](https://ubuntu.com/desktop/flavours), as they are generally smaller than Ubuntu. I'll be using Xubuntu because that's what I had at first, but you can choose any live system you like (with small adaptations). I even have already gone through these steps with a Gentoo live CD!
I will not go into the details of how to boot from CD or pendrive. I recommend reading your PC manufacturer's manual to do that. Generally, it boils down to enabling media boot and disabling the Secure Boot in the BIOS configuration. After you installed the system, you can move back to the factory defaults. In a virtual environment, this is not needed.
Once you booted your live environment, open a terminal and install the `debootstrap` and `vim` tools. If you are on a Debian-based live distro, that would be:
```
$ sudo apt update
$ sudo apt install debootstrap vim
```
If the package manager of your live environment does not contain `debootstrap` (most of them do), then you'll have to manually download it from the [Debian mirrors](https://www.debian.org/mirror/list). Navigate to one of your preference and go to `pool/main/d/debootstrap/` path. Download the latest `debootstrap_X.Y.ZZZ_all.deb` file, extract, and install it:
```
# ar -x debootstrap_X.Y.ZZZ_all.deb
# cd /
# zcat /full-path-to-extracted-deb/data.tar.gz | tar xv
```
That's all for this step!
## Partitioning the disk and formatting
Before going into this, if your disk is already partitioned, make sure that your SWAP partition is not already in use, if you have one. If it is in use, it will prevent synchronizing the changes you make. If that's the case, simply `swapoff /dev/sdXY`, where `sdXY` is your SWAP partition.
I'll use `cfdisk` for partitioning the disk since I find it easier to use than `fdisk`. You can use any partitioning tool you feel comfortable with. You can even use `gparted`, if you have a graphical live environment. Usually, you'll need at least two partitions, one for your OS and one for swap. If you opt to use a swapfile instead of a partition, then all you need is the OS partition.
If you are in a UEFI system, be sure to create an `EFI System` partition, if it is not already existent. Make it at least 1 GiB, and positioned at the beginning of the device. In this case, it's advisable to use GPT as your partition label, instead of MBR, to avoid some headaches with compatibility. One suggestion of layout for an UEFI system partition table is:
| dev | mount point |
|-----------|-------------|
| /dev/sda1 | /boot |
| /dev/sda2 | SWAP |
| /dev/sda3 | / |
### Formatting
If you created a boot partition, format it as FAT 32, since it is compliant with the UEFI spec. For example:
```
# mkfs.fat -F 32 /dev/sda1
```
If you created a SWAP partition, format and activate it:
```
# mkswap /dev/sda2
# swapon /dev/sda2
```
Any other data partition, you may format with the file system you want. Every FS has its pros and cons; I recommend using Ext4, as it is more widely adopted.
```
# mkfs.ext4 /dev/sda3
```
Now you are ready to install the system.
## Installing the basic system
### Mounting the partitions
You'll need to mount all of your partitions in the tree they will end up. The `/mnt` directory in our live system is perfect for that.
First, mount the root partition:
```
# mount /dev/sda3 /mnt
```
If you created one, mount the EFI system partition to `/mnt/boot`:
```
# mount --mkdir /dev/sda1 /mnt/boot
```
Finally, mount other partitions you created to their respective directories (for example, the home partition to `/mnt/home`, etc.).
### Installing the base packages
Do you remember the `debootstrap` tool we installed before? Here it will come to action!
```
# debootstrap --arch=amd64 trixie /mnt http://ftp.debian.org/debian
```
Replace the `amd64` arch, the `trixie` suite (current testing as of the writing of this tutorial), and the `http://ftp.debian.org/debian` mirror to more convenient values to you.
### Configuring the `fstab`
Now, if you list the directories in `/mnt`, you'll see the basic structure of a Linux installation.
It is time to configure the `fstab` file for this environment. If you open it, it should be empty. Start it by dumping the partitions UUIDs into it:
```
# blkid >> /mnt/etc/fstab
```
And edit it with your favorite editor (I use VIM, BTW):
```
# vim /mnt/etc/fstab
```
Add the following content, using the `blkid` dump already present in the file to complete the required values.
```
# /etc/fstab: static file system information.
#
# file system mount point type options dump pass
# /dev/sda3
UUID=xxxx / ext4 defaults 0 1
# /dev/sda1
UUID=yyyy /boot vfat ro,nosuid,nodev 0 2
# /dev/sda2
UUID=zzzz none swap sw 0 0
# cdrom
/dev/cdrom /media/cdrom iso9660 noauto,ro,user,exec 0 0
```
## Prepare for `chroot`
Now it is time to `chroot` to our newly created system. Before going into that, it is good to mount a few things in the structure of the Debian environment, so everything runs Ok:
```
# mount --rbind /dev /mnt/dev
# mount --rbind /sys /mnt/sys
# mount --rbind /run /mnt/run
# mount --rbind /proc /mnt/proc
```
Then the installed system will "act" very much like our live environment. Now we can `chroot` to it:
```
# chroot /mnt bash
```
From now on, all commands must be executed in this "chroot'ed" environment, unless when noted otherwise.
## Setup locales and configure the keyboard
Install the `locales` package and configure it. Select all languages that make sense to you.
```
# apt-get install locales
# dpkg-reconfigure locales
```
Install the `console-setup` package to configure the keyboard layout (won't take effect until reboot):
```
# apt-get install console-setup
# dpkg-reconfigure keyboard-configuration
```
## Adjust time and date
Let's setup the time and date for the system. First, adjust if the system should interpret the hardware clock as "UTC" or "LOCAL" time. Generally, choosing UTC makes sense:
```
# vim /etc/adjtime
```
Insert the following contet:
```
0.0 0 0.0
0
UTC
```
Now, configure your timezone:
```
# dpkg-reconfigure tzdata
```
## Installing the Kernel
Now we need to install a Linux Kernel version for our system. The `debootstrap` tool will leave you with a really bare minimal system. You can pick up the one available using `apt-cache search linux-image`, or simply use the meta-package to install the latest one:
```
# apt-get install linux-image-amd64 linux-headers-amd64
```
(Install the Linux headers only if you want to install specific drivers; it is not required.)
## Installing and configuring the bootloader
Our system is almost complete and bootable by now. But there's no bootloader installed yet! The list of available bootloaders for Debian can be found at . A very popular choice is using Grub (GRand Unified Bootloader) and that's the one I'll be using.
If you want Grub to automatically detect other OSes, you must uncomment the `GRUB_DISABLE_OS_PROBER=false` line at `/etc/default/grub` file. This will enable Grub to execute the `os-prober` to detect other bootable operating systems.
→ _If you are using BIOS with MBR partition label_, then you can simply execute the following commands:
```
# apt-get install grub-pc
# grub-install /dev/sda
# update-grub
```
→ _If you are using UEFI with GPT partition label_, then you'll need the EFI version of Grub:
```
# apt-get install grub-efi
# grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB
# update-grub
```
This should be enough to be able to boot your new environment. If you installed Grub with UEFI system, you may want to enable Secure Boot. Currently, Grub fully supports Secure Boot mode. In my experience, the steps above are enough for booting a system with Secure Boot enabled, but in your case you may need extra steps. They can be found [here](https://wiki.debian.org/SecureBoot) and [here](https://wiki.archlinux.org/title/GRUB#Secure_Boot_support).
## Configuring APT sources and the network
If you check the `/etc/apt/sources.list` of our new system, you'll see it only has one entry. A better configuration for it, if you are installing the `testing` release as me, would be:
```
deb http://deb.debian.org/debian trixie main non-free-firmware
deb-src http://deb.debian.org/debian trixie main non-free-firmware
deb http://deb.debian.org/debian-security/ trixie-security main non-free-firmware
deb-src http://deb.debian.org/debian-security/ trixie-security main non-free-firmware
```
Refresh list of packages:
```
# apt update
```
Remember to keep the mirror you chose when executing the `debootstrap`.
Now, change your hostname by editing the `/etc/hostname` file:
```
# vim /etc/hostname
```
For configuring connection, you can statically set up the configuration, or you can set up DHCP. Although it is not hard to set up static configuration, it is better to enable DHCP. For this, we'll install the `networkmanager` package:
```
# apt install network-manager
```
## Cleaning up and rebooting
We finally arrived the end of installing a bootable base system. You must set a password for your root user:
```
# passwd
```
Clean up everything:
```
# apt clean
```
And exit the live environment. Remember to remove any media before booting the new system. This will leave you with an extra minimal installation of Debian, fully functional.
## Extra bits
### Creating your first un-privileged user
We have a nice, running OS now. But we only have root, which is not recommended to be frequently used! Creating your first un-privileged user is as easy as running a single command:
```
# adduser debie
```
This will create an unprivileged user, create the user's group (`debie`, in this case), and this user to the `users` group. Theoretically, this is all your user needs, for now. You can install `sudo` tool and add the new user to the `sudo` group, granting it privileges to run `sudo` commands:
```
# adduser debie sudo
```
There is a list of groups available in any Debian installation [here](https://wiki.debian.org/SystemGroups). You may consider adding your user to `cdrom`, `audio`, `floppy`, and `lp` (if you plan to use a printer) groups.
```
# usermod -aG cdrom,audio,floppy,lp debie
```
### Installing the graphical interface
Here is where things get cooler. See, up to now, we installed and controlled every single bit of data that entered our installation. One could simply execute in the terminal:
```
$ sudo apt install task-xfce-desktop
```
Or any other of the pre-cooked tasks (anything `task-*-desktop`), and install all packages for running a graphical environment. But that would defeat our purpose here! We want **lean and clean**!
#### Display Managers
Debian offers a myriad of [Display Managers](https://wiki.debian.org/DisplayManager?highlight=%28display%29%7C%28managers%29) to work with. You can install one of your choice. I like `lightdm`, so I'll keep it:
```
$ sudo apt install lightdm
```
One aspect I like about `lightdm` is that you may configure the look and feel as you wish. This look and feel is called `greeters`. By default, `lightdm` comes with the `lightdm-gtk-greeter`, but you can configure:
- the Arctica greeter;
- the slick greeter;
- and [others](https://packages.debian.org/trixie/lightdm-greeter)...
#### Desktop Environments