First, create a GPT partition table.
- boot partition, label: EFI, flags: boot + ESP; size: 1GB, format to FAT32;
- root partition (label: root), must same size on all devices!
- swap partition.
First, install the debootstrap
and btrfs-tools
package.
Then, format the partition as btrfs (raid1) on two devices and use debootstrap to install the OS:
DEV1=/dev/sdc2 # modify to installation root partition.
DEV2=/dev/sdd2 # modify to mirror root partition.
UBUNTU_VERSION=xenial
MNT=/mnt
mkfs.btrfs -m raid1 -d raid1 $DEV1 $DEV2
# alt: mkfs.ext4 /dev/sdX2
mount $DEV1 $MNT
debootstrap --arch=amd64 --variant=buildd $UBUNTU_VERSION "$MNT" http://archive.ubuntu.com/ubuntu/
sudo cp /etc/resolv.conf "$MNT/etc/resolv.conf"
cat <<REPO_LIST | sudo tee "$MNT/etc/apt/sources.list"
# Repositories
deb http://archive.ubuntu.com/ubuntu $UBUNTU_VERSION main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu $UBUNTU_VERSION-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu $UBUNTU_VERSION-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu $UBUNTU_VERSION-backports main restricted universe multiverse
REPO_LIST
Chroot to the newly installed root filesystem:
mount $DEV1 $MNT
mount --bind /dev $MNT/dev
mount --bind /proc $MNT/proc
mount --bind /sys $MNT/sys
chroot "$MNT" /usr/bin/env PATH=/usr/sbin:/usr/bin/:/bin:/sbin bash -i
In the chroot, configure the system:
apt-get update
apt-get install -y btrfs-tools ubuntu-minimal language-pack-en-base vim ssh iputils-arping \
grub-efi-amd64 bash-completion parted
# Install Grub
BOOT_DEV=/dev/sdc1
mount "$BOOT_DEV" /boot
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub
mkdir /boot/EFI/boot
cp /boot/EFI/grub/grubx64.efi /boot/EFI/boot/bootx64.efi
# also install a kernel
apt-get install linux-generic
Then fill out /etc/fstab:
echo "" > /etc/fstab
echo "PARTLABEL=root / btrfs defaults 0 1" >> /etc/fstab
echo "PARTLABEL=EFI /boot vfat defaults 0 2" >> /etc/fstab
Initramfs configuration for btrfs:
cp /usr/share/initramfs-tools/scripts/local-premount/btrfs /etc/initramfs-tools/scripts/local-premount/btrfs
# edit it and enter a "sleep 5" before the line with "btrfs device scan"
vim /etc/initramfs-tools/scripts/local-premount/btrfs
# build the new initramfs:
update-initramfs -u
# backup the boot partition
mkdir /boot_bkp
cp -rf /boot/* /boot_bkp
Change root password, optionally create your account:
passwd
# insert your new root password
At the end, unmount the partition:
exit # from the chroot
umount "$MNT/boot"
umount "$MNT/dev"
umount "$MNT/proc"
umount "$MNT/sys"
umount "$MNT"