Skip to content

Instantly share code, notes, and snippets.

@tyanyaw
Last active March 26, 2022 08:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyanyaw/cf7dc5b48401aa95e025da67960f6f2b to your computer and use it in GitHub Desktop.
Save tyanyaw/cf7dc5b48401aa95e025da67960f6f2b to your computer and use it in GitHub Desktop.
Create Debian minimal server with debootstrap

GOAL : Debian 11 minimal server, size 700 MB

TOOL :

  • Linux : Debian 11 at /dev/sda, Target at /dev/sdb
  • Application : debootstrap, parted
  • User : root

1. Install Debootstrap

apt-get update

apt-get install debootstrap

apt-get install parted


2. Partition Hardisk

parted /dev/sdb

mklabel msdos

mkpart primary ext4 1MB 1800MB

mkpart primary linux-swap 1800MB 2000MB

set 1 boot on

quit

mkfs.ext4 /dev/sdb1

mkswap /dev/sdb2


3. Debootstrap

mount /dev/sdb1 /mnt

debootstrap --arch amd64 stable /mnt http://cdn-fastly.deb.debian.org/debian

NOTE : Don't use --variant=minbase, it gonna screw the build, because default debootstrap already small


4. Borrow Host system

mount -o bind /dev /mnt/dev

mount -o bind /proc /mnt/proc

mount -o bind /sys /mnt/sys

mount -o bind /run /mnt/run


5. Network Configuration

Copy host network configuration

cp /etc/mtab /mnt/etc/mtab

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


6. Chroot target

chroot /mnt /bin/bash

Make chroot bash color different than host

PS1="\e[99;32m$PS1\e[m"


7. Mount Hardisk /etc/fstab

blkid /dev/sdb1 >> /etc/fstab && blkid /dev/sdb2 >> /etc/fstab

nano /etc/fstab

My configuration of fstab, change the UUID with yours

# UNCONFIGURED FSTAB FOR BASE SYSTEM
# <file system>					<dir>	<type>	<options>	<dump>	<pass>
UUID=3ce8b8a7-18e1-4818-908c-e31e53602f04	/	ext4	defaults	0	0
UUID=5be3a736-701c-4c2c-a6f8-0d78e565ac4c	swap	swap	defaults	0	0

8. Install Linux Kernel

apt-get update

apt-get install linux-image-amd64


9. Install Bootloader GRUB

apt-get install grub-pc

update-grub && grub-install --root-directory / /dev/sdb


10. Change target root password

passwd


11. Clean, Exit Chroot

apt-get autoremove

apt-get clean

exit


12. Reboot to target

umount -l /mnt

shutdown now

Remove the target hardisk /dev/sdb and boot it from new Computer or new Virtual Machine.

After boot, update the grub because there lelfover of old Debian (Host).

update-grub

Check the hardisk size, mine 658MB

df -h


DONE

Now you have Debian minimal installation with the size of 700MB

Next step, you can reduce the size of hardisk Reduce Debian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment