7374756666

Installing Ubuntu using debootstrap

An updated version for Bionic is here

In some scenarios you may wish to install vanilla Ubuntu without the ability to use an iso.

In my case this was an OVH dedicated server which the default Ubuntu install they provide comes loaded with stuff I don't want.

First reboot into a rescue medium or separate install which is debian based and doesn't use the parition you want to install ubuntu on.

If the install OS is old you may need to run: apt-get update && apt-get -y upgrade To update debootstrap

If the install OS isn't ubuntu you may need to run: apt-get install ubuntu-archive-keyring

This guide assumes /dev/sda will be the root device and you will be installing a 64 bit arch.

First format your install disk using fdisk/cfdisk/parted/whatever your tool of choice is.

Next mount the install root:

mkdir /debootstrap
mount /dev/sda1 /debootstrap

Now install the base OS

debootstrap --arch=amd64 xenial /debootstrap

Replace xenial with whatever the codename of the distro to install is.

Now edit /debootstrap/etc/apt/soruces.list to include the following (again replacing xenial with the codename)

#main repo
deb http://gb.archive.ubuntu.com/ubuntu/ xenial main
deb http://gb.archive.ubuntu.com/ubuntu/ xenial-updates main
#restricted repo
deb http://gb.archive.ubuntu.com/ubuntu/ xenial restricted
deb http://gb.archive.ubuntu.com/ubuntu/ xenial-updates restricted
#universe repo
deb http://gb.archive.ubuntu.com/ubuntu/ xenial universe
deb http://gb.archive.ubuntu.com/ubuntu/ xenial-updates universe
#multiverse repo
deb http://gb.archive.ubuntu.com/ubuntu/ xenial multiverse
deb http://gb.archive.ubuntu.com/ubuntu/ xenial-updates multiverse
#security repo
deb http://security.ubuntu.com/ubuntu xenial-security main restricted
deb http://security.ubuntu.com/ubuntu xenial-security universe
deb http://security.ubuntu.com/ubuntu xenial-security multiverse

Now set up device mounts etc and chroot to the new install

mkdir -p /debootstrap/dev /debootstrap/proc /debootstrap/sys
mount --bind /dev /debootstrap/dev
mount -t proc proc /debootstrap/proc
mount -t sysfs sys /debootstrap/sys
chroot /debootstrap

Set up the locale and timezone

cp /usr/share/zoneinfo/UTC /etc/localetime
echo 'LANG="en_US.UTF-8"' > /etc/default/locale
echo 'Etc/UTC' > /etc/timezone
locale-gen  en_US.UTF-8
dpkg-reconfigure -f non-interactive tzdata
apt update
apt install language-pack-en-base

If you are using software raid, LVM or cryptsetup run

apt install lvm2 mdadm cryptsetup

Install the kernel and grub

apt install linux-image-generic grub2

Install openssh

apt install openssh-server

Important You must add your ssh key to /root/.ssh/authorized_keys by default ubuntu only allows key access for root

Add an fstab entry

echo '/dev/sda1 /   ext4    errors=remount-ro   0   1' > /etc/fstab

Edit the network configuration, edit /etc/network/interfaces and add your config it may look like this:

auto eth0
iface eth0 inet dhcp

Now reboot and enjoy!