Perform a Custom Debian Hard Drive Install
This article was last edited over 3 years ago. Information here may no longer be accurate. Please proceed with caution, and feel free to contact me.
The stock Debian installer provided by Debian is fantastic. It is intuitive, and simple. However, if you want a custom install for whatever reason (specific configuration, machine deployment, minimal image), you can use these steps to accomplish that.
To do this, we will need any Debian-based live CD. You can use my guide for creating a custom Debian Live CD or USB to generate this, or simply use an Ubuntu or Debian live CD or USB.
The advantage of using a custom live environment is that you can package the tools you need in the live environment so they are always available. If you use the stock Ubuntu or Debian live CDs, you may need a network connection to install the required tools.
This article is periodically updated.
See other related articles here:
Warning: I have highlighted all the places you should be in the target install chroot.
-
Boot the machine using your live CD or USB and install the necessary tools (assuming they are not already available).
sudo apt-get install debootstrap
-
Determine the device where you want to install your customized Debian.
I am assuming that the hard disk you plan to use is at/dev/sdz
, that you only want one partition on that disk, and that you want to use MBR with grub2. You must replace any instance of/dev/sdz
in these steps with the with the location of your hard drive or you may accidentally lose data. -
Create an MBR table with one bootable Linux partition.
echo -e "o\nn\np\n1\n\n\nw" | sudo fdisk /dev/sdz
echo -e "a\nw\n" | sudo fdisk /dev/sdz
-
Format the partition.
sudo mkfs.ext4 /dev/sdz1
-
Create a mount point if it does not already exist.
sudo mkdir -p /mnt
-
Mount the partition.
sudo mount /dev/sdz1 /mnt
-
Set up the base Debian install. I am using Stretch for my distribution and i386 for the architecture. Please change your mirror if you are not in the U.S. or if you know of a mirror closer to you.
sudo debootstrap \ --arch=i386 \ --variant=minbase \ stretch /mnt http://ftp.us.debian.org/debian/
-
Bind
/dev
and/proc
from the host to the chroot.sudo mount -o bind /dev /mnt/dev
sudo mount -t proc /proc /mnt/proc
-
Chroot to our Debian install.
sudo chroot /mnt
-
chroot
Figure out which Linux Kernel you want in your install.
apt-cache search linux-image
I chose the image
linux-image-586
.systemd-sys
(or an equivalent) is necessary to provideinit
.apt-get update && \ apt-get install --no-install-recommends \ linux-image-586 systemd-sysv
-
chroot
Install programs of your choosing. I use
--no-install-recommends
to avoid superfluous packages. You should decide what you need for your install.apt-get install --no-install-recommends \ network-manager net-tools wireless-tools wpagui \ tcpdump wget openssh-client \ blackbox xserver-xorg-core xserver-xorg x11-xserver-utils \ xinit xterm \ pciutils usbutils gparted nano
-
chroot
Create an
/etc/fstab
file for the install.We can generate it with a script like so.
UUID=`blkid -s UUID -o value /dev/sdz1`
echo "UUID=${UUID} / ext4 defaults 1 1" > /etc/fstab
-
chroot
Install the grub bootloader.
apt-get install grub2
When prompted, be sure to choose
/dev/sdz
(not/dev/sdz1
) as theGrub install device
. -
chroot
Set the root password.
passwd root
-
chroot
exit
-
Reboot to your Debian installation!