Debian Basics
Base Installation
Debian Stable: First, download the stable netinstall iso from the debian.org website and install Debian without any desktop environment.
Debian Testing: Once you have installed a minimal Debian system, you can upgrade the system to testing in case you need a Debian Testing system.
First, upgrade your current stable system:
apt update
apt upgrade
Second, change the sources.list so your system tracks debian testing:
sed -i s/stretch/testing/g /etc/apt/sources.list
Now, update, upgrade, and reboot your system again:
apt update
apt upgrade
reboot
Debian Unstable: Once you have installed a minimal Debian testing system, you can upgrade the system to Debian Unstable in case you need a development system:
First, upgrade your current stable system:
apt update
apt upgrade
Second, change the sources.list so your system tracks debian testing:
sed -i s/testing/unstable/g /etc/apt/sources.list
Now, update, upgrade, and reboot your system again:
apt update
apt upgrade
reboot
APT CLI Interface
Command | Description |
---|---|
apt install [s] <pkg> | <deb-file> |
Install package <pkg> |
apt remove [s] <pkg> |
Remove package <pkg> and keep config files |
apt purge <pkg> |
Remove package <pkg> and config files |
apt update |
Update package sources |
apt upgrade [s] |
Upgrade installed packages |
apt full-upgrade [s] |
Upgrade system |
apt download <pkg> |
Download package <pkg> |
apt source <pkg> |
Download sourcecode of package <pkg> |
apt show <pkg> |
Show information of package <pkg> |
apt policy <pkg> |
Show information of package <pkg> |
apt edit-sources |
Edit sources.list file |
Examples:
Simulate APT actions:
apt install -s <pkg>
apt upgrade -s
apt full-upgrade -s
Downloading packages:
apt download <pkg>
Downloading sourcecode of a package:
apt source <pkg>
Upgrading packages:
apt update
apt upgrade
Upgrading a system:
apt update
apt upgrade
sed -i s/stretch/buster/g /etc/apt/sources.list
apt update
apt full-upgrade
Base Installation from Scratch
The best way to install a base Debian system from scratch is to use the Grml Live Linux, which is a bootable Live-CD based on Debian.
Installation Procedure: The basic steps for installing a Debian system from scratch on a BIOS system are as follows:
- Boot from a Linux Live CD
- Enter the shell
- Setup keyboard and network configuration
- Create partitions and format them
- Run debootstrap
- Chroot to the new Linux system
- Install linux-kernel image and the bootloader.
- Configure the bootloader.
- Add a non-root user and setup sudo.
- Change root password.
- Reboot, update the system, and install missing packages using the apt paket manager.
Create the partitions:
Run fdisk
and partition the main drive.
In my case, I decided to use the following partitiing scheme for a lightweight
system:
partition | type | size | Note |
---|---|---|---|
/dev/sda1 | ef02 | 3MB | Bios legacy partition |
/dev/sda2 | 8200 (swap) | 512MB | Swap space |
/dev/sda3 | 8300 Linux fs | Rest | Root |
Format the partitions:
In this step, format the bios partition with vfat
and the root partition with
ext4
:
mkfs.vfat /dev/sda1
mkfs.ext4 /dev/sda3
mkswap /dev/sda2
Debootstrap the base system:
In this step, we install the Debian base system using debootstrap
.
First, mount the root partition on a directory called /mnt/debian
.
Second, bootstrap the Debian root filesytem using debootstrap
.
mkdir -p /mnt/debian
mount /dev/sda3 /mnt/debian
debootstrap --arch amd64 testing /mnt/debian http://ftp.ch.debian.org/debian/
Chrooting the base system: Now, we can chroot into the root filesystem. But before we can do that, we need to mount some necessary device and system files from the host system.
So first mount the follwing directories on /mnt/debian
:
mount -o bind /dev /mnt/debian/dev
mount -o bind /dev/pts /mnt/dev/pts
mount -o bind /dev/shm /mnt/dev/shm
mount -t sysfs /sys /mnt/debian/sys
mount -t proc /proc /mnt/debian/proc
Next, copy the resolv.conf
from the host system to /mnt/debian/etc
.
Otherwise, you won't have a working DNS resolution once you boot into the new
system.
cp /etc/resolv.conf /mnt/debian/etc/resolv.conf
Lastly, chroot into the root filesystem:
chroot /mnt/debian /bin/bash
Configuration: Once you chroot into root filesystem, we can install the missing packages and configure the system so it becomes bootable.
First, give your system a new hostname:
echo debian > /etc/hostname
Second, set a root password for user root:
passwd root
Next, edit /etc/fstab
:
# /etc/fstab: static file system information
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
/dev/sda3 / ext4 defaults 0 1
/dev/sda1 /boot ext4 defaults 0 2
/dev/sda2 none swap defaults 0 0
Configure the locales:
apt install locales
dpkg-reconfigure locales
Configure the timezone:
apt install tzdata
dpkg-reconfigure tzdata
Configure the network settings by editing /etc/network/interfaces
.
Use ip addr
on the figure out the network device interface and edit
interfaces
as follows in case you use LAN and DHCP:
auto lo
iface lo inet loopback
auto enp0s3
allow-hotplug enp0s3
iface enp0s3 inet dhcp
iface enp0s3 inet6 dhcp
Sudo:
To setup a sudo user install the package sudo
and create a new user that
belongs to the group sudo
:
apt install sudo
adduser username
usermod -aG sudo username
Install Linux kernel & Boot loader: First, install the Linux kernel image:
apt install linux-image-amd64
Afterwards, you can install a boot loader such as Grub. Note that to make your Debian system bootable, set up your boot loader to load the installed kernel with your new root partition.
apt install grub-pc
grub-install /dev/sda
update-grub
Reboot: Reboot the system and pray that the system boots up :-)
reboot