This page describes how to create a minimal bootable amd64 Debian system (usually on an external drive) from a command line of another working Debian installation.
This page assumes some level of familiarity with the basic structure of a Linux system and its common config files.
Contents
Partition the target drive
For a storage device (like an HDD or an NVMe) to be a valid boot device for UEFI CPUs, it needs to have an EFI System Partition (ESP) containing EFI applications: usually just early-stage bootloaders for installed OSes, like shim in case of Linux. In standard cases these applications are just a few to few dozens of MB in size so 500MB is waaay more than enough for an ESP. Per UEFI spec, ESP must be formatted as FAT32. It is a common practice for ESP to be the first physical partition on a given disk, but this is not mandatory.
A standard Debian system requires at least one partition or a logical volume for its root filesystem (rootFS). Optionally, separate subvolumes (partitions or logical volumes) may exist for /var/, /home, /boot, /opt etc. rootFS may be formatted as any Linux-supported, POSIX-compliant filesystem (ext4, xfs, btrfs etc). A text-only Debian system will easily fit within 3GB, for a graphical system at least 10GB is recommended.
There are several different strategies and additional technologies (for example LVM, LUKS etc) for partition layouts, each with different strengths and goals, but this is beyond the scope of this document.
Mount partitions and run mmdebstrap
Create a temporary mount-point for the target system, for example /mnt/tmp-debstrap, it will be referred hereafter to as ${debstrapFolder}. Mount the rootFS volume there, then mount any subvolumes in their respective mount-points. Afterwards run
sudo mmdebstrap --architectures=amd64,i386 --skip=output/dev,output/mknod --variant=standard trixie "${debstrapFolder}" /etc/apt/sources.listThis will create a most basic amd64+i386 foundation of the new system using apt sources copied from host's /etc/apt/sources.list. Replace the last argument if you want to use different sources. Replace trixie with the desired Debian version (the passed version must much the passed sources).
Create or edit basic config files
/etc/fstab
mmdebstrap creates just an empty stub, so you need to list the rootFS and any subvolumes manually, including the ESP at /boot/efi.
/etc/hostname
Put a hostname of your choice into this file.
/etc/hosts
mmdebstrap creates entries necessary for basic networking, so just add an entry for the hostname chosen above:
echo "127.0.1.1 $(cat ${debstrapFolder}/etc/hostname)" | sudo tee -a "${debstrapFolder}/etc/hosts"
/etc/localtime
mmdebstrap by default sets the time to UTC, change the link to point to your desired timezone.
chroot into the new system
Follow the basic procedure as described in chroot and mount /boot/efi if you haven't done it before.
Configure locales
dpkg-reconfigure locales
This will interactively ask for locale configuration.
Install keyboard layout, initramfs tools and grub
apt install keyboard-configuration initramfs-tools grub-efi grub-install
Install a kernel, necessary firmware and other critical packages
Use apt install to install the below packages:
Kernel: linux-image-amd64
- Necessary firmware: this depends on the specific hardware of the target system and typically includes:
At least one of firmware-{amd,intel,nvidia}-graphics for the GPU.
If the target system uses a WiFi, then usually one of firmware-iwlwifi, firmware-mediatek, firmware-brcm80211, firmware-atheros, firmware-ath9k-htc.
If the target system uses a wired ethernet, them its firmware (ToDo: list typical wired eth firmware).
If the target system uses any Thunderbolt devices, then bolt is necessary.
It is recommended not to set a password for root user, in which case sudo is necessary.
Highly recommended network utilities: network-manager, ufw, curl.
After installing all the above packages, run
update-grub
Create user accounts and set passwords
adduser myusername
This will interactively ask for user details and password (replace myusername with a username of your choice, of course).
Install a graphic system (optional)
Desktop environment:
MATE: apt install mate-desktop-environment-extras lightdm gnome-package-updater
Gnome: apt install gnome-session
KDE: ToDo
Common GUI apps:
firefox-esr
gufw
network-manager-gnome
synaptic
Exit chroot and cleanup
Exit the chroot either with exit command or by pressing CTRL+D, then run
sudo umount -R "${debstrapFolder}"
sudo rmdir "${debstrapFolder}"