2022-10-04 07:10:43 +00:00
|
|
|
#!/bin/bash
|
2022-11-05 04:36:26 +00:00
|
|
|
|
|
|
|
# Script is based off official guide: see "Debian Bullseye Root on ZFS"
|
|
|
|
# https://openzfs.github.io/openzfs-docs/Getting%20Started/Debian/Debian%20Bullseye%20Root%20on%20ZFS.html
|
2022-10-04 07:10:43 +00:00
|
|
|
|
2022-11-27 08:35:55 +00:00
|
|
|
#################
|
|
|
|
### Functions ###
|
|
|
|
#################
|
|
|
|
function usage () {
|
2022-11-28 00:51:30 +00:00
|
|
|
echo "Usage: ./$(basename "$0") [-mpPr] <DISK> <HOSTNAME>"
|
2022-11-27 08:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function disk_check () {
|
2022-11-28 00:48:44 +00:00
|
|
|
DISK_TYPE=$(file "$1" | awk '{ print $2$3 }')
|
|
|
|
if [ "$DISK_TYPE" != "blockspecial" ]; then
|
|
|
|
echo "ERROR: Disk '$1' is not a block device"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-11-27 08:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function disk_status () {
|
2022-11-28 00:48:44 +00:00
|
|
|
OUTPUT=$(wipefs "$1")
|
|
|
|
if [ -n "$OUTPUT" ]; then
|
|
|
|
echo "ERROR: $1 is not empty"
|
|
|
|
echo "$OUTPUT"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-11-27 08:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function password_prompt () {
|
2022-11-28 00:48:44 +00:00
|
|
|
unset PASSWORD_PROMPT_RESULT
|
|
|
|
while true; do
|
|
|
|
read -r -s -p "${1}: " password
|
|
|
|
echo ''
|
|
|
|
read -r -s -p "${1} (confirm): " password_confirm
|
|
|
|
echo ''
|
|
|
|
if [ "$password" == "$password_confirm" ]; then
|
|
|
|
if [ -z "$password" ]; then
|
|
|
|
echo "Password can not be empty, try again."
|
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Passwords did not match, try again."
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
PASSWORD_PROMPT_RESULT="$password"
|
|
|
|
export PASSWORD_PROMPT_RESULT
|
2022-11-27 08:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function disk_format () {
|
2022-11-28 00:48:44 +00:00
|
|
|
sgdisk -n2:1M:+512M -t2:EF00 "$1"
|
|
|
|
sgdisk -n3:0:+1G -t3:BF01 "$1"
|
|
|
|
sgdisk -n4:0:0 -t4:BF00 "$1"
|
2022-11-27 08:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function create_boot_pool () {
|
2022-11-28 00:48:44 +00:00
|
|
|
zpool create -f \
|
|
|
|
-o ashift=12 \
|
|
|
|
-o autotrim=on -d \
|
|
|
|
-o cachefile=/etc/zfs/zpool.cache \
|
|
|
|
-o feature@async_destroy=enabled \
|
|
|
|
-o feature@bookmarks=enabled \
|
|
|
|
-o feature@embedded_data=enabled \
|
|
|
|
-o feature@empty_bpobj=enabled \
|
|
|
|
-o feature@enabled_txg=enabled \
|
|
|
|
-o feature@extensible_dataset=enabled \
|
|
|
|
-o feature@filesystem_limits=enabled \
|
|
|
|
-o feature@hole_birth=enabled \
|
|
|
|
-o feature@large_blocks=enabled \
|
|
|
|
-o feature@livelist=enabled \
|
|
|
|
-o feature@lz4_compress=enabled \
|
|
|
|
-o feature@spacemap_histogram=enabled \
|
|
|
|
-o feature@zpool_checkpoint=enabled \
|
|
|
|
-O devices=off \
|
|
|
|
-O acltype=posixacl -O xattr=sa \
|
|
|
|
-O compression=lz4 \
|
|
|
|
-O normalization=formD \
|
|
|
|
-O relatime=on \
|
|
|
|
-O canmount=off -O mountpoint=/boot -R "$1" \
|
2022-11-27 08:35:55 +00:00
|
|
|
bpool "$2"
|
|
|
|
}
|
|
|
|
|
|
|
|
function create_root_pool () {
|
2022-11-28 00:48:44 +00:00
|
|
|
echo "$3" | zpool create -f \
|
|
|
|
-o ashift=12 \
|
|
|
|
-o autotrim=on \
|
|
|
|
-O encryption=on -O keylocation=prompt -O keyformat=passphrase \
|
|
|
|
-O acltype=posixacl -O xattr=sa -O dnodesize=auto \
|
|
|
|
-O compression=lz4 \
|
|
|
|
-O normalization=formD \
|
|
|
|
-O relatime=on \
|
|
|
|
-O canmount=off -O mountpoint=/ -R "$1" \
|
2022-11-27 08:35:55 +00:00
|
|
|
rpool "$2"
|
|
|
|
}
|
|
|
|
|
2022-11-28 01:50:20 +00:00
|
|
|
function mirror_grub () {
|
|
|
|
umount /boot/efi
|
|
|
|
dd if="${1}-part2" of="${2}-part2"
|
|
|
|
efibootmgr -c -g -d "$2" -p 2 \
|
|
|
|
-L "debian-${3}" -l '\EFI\debian\grubx64.efi'
|
|
|
|
mount /boot/efi
|
|
|
|
}
|
|
|
|
|
2022-11-28 05:53:09 +00:00
|
|
|
function disk_by_id () {
|
|
|
|
disk_check "$1"
|
|
|
|
OUTPUT=$(find /dev/disk/by-id -lname "../../$(basename "$1")" | tail -n1)
|
|
|
|
if [ -z "$OUTPUT" ]; then
|
|
|
|
echo "ERROR: No disk by-id label found for: $1"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "$OUTPUT"
|
|
|
|
}
|
|
|
|
|
2022-11-27 08:35:55 +00:00
|
|
|
################
|
|
|
|
### Settings ###
|
|
|
|
################
|
|
|
|
# Static
|
2022-10-04 07:10:43 +00:00
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
2022-11-27 08:35:55 +00:00
|
|
|
CODENAME="bullseye"
|
|
|
|
|
|
|
|
# Options
|
2022-11-28 01:50:20 +00:00
|
|
|
while getopts ':gm:p:P:r:' OPTION; do
|
2022-11-28 00:48:44 +00:00
|
|
|
case "$OPTION" in
|
2022-11-28 01:50:20 +00:00
|
|
|
g) GRUB_MIRROR="true";;
|
2022-11-28 00:48:44 +00:00
|
|
|
m) MIRROR="$OPTARG";;
|
|
|
|
p) ROOTPW="$OPTARG";;
|
|
|
|
P) RPOOLPW="$OPTARG";;
|
|
|
|
r) ZFSROOT="$OPTARG";;
|
|
|
|
?)
|
|
|
|
usage
|
|
|
|
exit 1;;
|
|
|
|
esac
|
2022-11-27 08:35:55 +00:00
|
|
|
done
|
|
|
|
shift "$((OPTIND -1))"
|
|
|
|
|
|
|
|
# Parameters
|
2022-11-05 04:36:26 +00:00
|
|
|
DISK=$1
|
|
|
|
ZFSHOST=$2
|
2022-11-27 08:35:55 +00:00
|
|
|
|
2022-11-28 01:50:20 +00:00
|
|
|
# Post-boot grub mirror?
|
|
|
|
if [ "$GRUB_MIRROR" == "true" ]; then
|
|
|
|
while true; do
|
|
|
|
echo -e "ORIGINAL GRUB: $DISK\nMIRROR TO: $MIRROR"
|
|
|
|
read -r -p "Would you like to mirror GRUB? [y/N]: " yn
|
|
|
|
case $yn in
|
|
|
|
[Yy]*)
|
|
|
|
disk_check "$DISK"
|
|
|
|
disk_check "$MIRROR"
|
|
|
|
mirror_grub "$DISK" "$MIRROR" 2
|
|
|
|
exit 0;;
|
|
|
|
?)
|
|
|
|
echo "ABORTED: User did not confirm mirroring"
|
|
|
|
exit 1;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2022-11-27 08:35:55 +00:00
|
|
|
# Verify variables
|
|
|
|
[ -z "$ZFSROOT" ] && ZFSROOT="/mnt"
|
|
|
|
|
|
|
|
if [ -z "$DISK" ]; then
|
2022-11-28 00:48:44 +00:00
|
|
|
echo "ERROR: DISK not set"
|
|
|
|
usage
|
|
|
|
exit 1
|
2022-11-27 08:35:55 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$ZFSHOST" ]; then
|
2022-11-28 00:48:44 +00:00
|
|
|
echo "ERROR: HOSTNAME not set"
|
|
|
|
usage
|
|
|
|
exit 1
|
2022-11-27 08:35:55 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$ROOTPW" ]; then
|
2022-11-28 00:48:44 +00:00
|
|
|
password_prompt "Root Passphrase"
|
|
|
|
ROOTPW="$PASSWORD_PROMPT_RESULT"
|
|
|
|
unset PASSWORD_PROMPT_RESULT
|
2022-11-27 08:35:55 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$RPOOLPW" ]; then
|
2022-11-28 00:48:44 +00:00
|
|
|
password_prompt "ZFS Encryption Passphrase"
|
|
|
|
RPOOLPW="$PASSWORD_PROMPT_RESULT"
|
|
|
|
unset PASSWORD_PROMPT_RESULT
|
2022-11-27 08:35:55 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$DEBUG" == "true" ]; then
|
2022-11-28 00:48:44 +00:00
|
|
|
echo "CODENAME=${CODENAME}"
|
|
|
|
echo "DISK=${DISK}"
|
|
|
|
echo "ZFSHOST=${ZFSHOST}"
|
|
|
|
echo "ZFSROOT=${ZFSROOT}"
|
|
|
|
echo "MIRROR=${MIRROR}"
|
|
|
|
echo "ROOTPW=${ROOTPW}"
|
|
|
|
echo "RPOOLPW=${RPOOLPW}"
|
2022-11-27 08:35:55 +00:00
|
|
|
fi
|
2022-10-04 07:10:43 +00:00
|
|
|
|
2022-11-27 08:35:55 +00:00
|
|
|
# Are the DISK paths block devices? AND
|
|
|
|
# Are the DISK pathes empty devices? i.e., no filesystem signatures
|
|
|
|
disk_check "$DISK"
|
|
|
|
disk_status "$DISK"
|
|
|
|
if [ -n "$MIRROR" ]; then
|
2022-11-28 00:48:44 +00:00
|
|
|
disk_check "$MIRROR"
|
|
|
|
disk_status "$MIRROR"
|
2022-10-04 07:10:43 +00:00
|
|
|
fi
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
###############################################
|
|
|
|
### Step 1: Prepare The Install Environment ###
|
|
|
|
###############################################
|
|
|
|
|
2022-11-28 00:51:30 +00:00
|
|
|
# Display commands
|
|
|
|
set -x
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 1. Boot the Debian GNU/Linux Live CD... done
|
|
|
|
# 2. Setup and update the repositories
|
2022-10-04 07:10:43 +00:00
|
|
|
SOURCES_LIST="/etc/apt/sources.list"
|
|
|
|
[ -f "$SOURCES_LIST" ] && mv "$SOURCES_LIST" "$SOURCES_LIST.$(date +%s).bak"
|
|
|
|
echo "deb http://deb.debian.org/debian/ ${CODENAME} main contrib" > "$SOURCES_LIST"
|
|
|
|
apt-get update
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 3. Optional: Install and start the OpenSSH server in the Live CD environment... done
|
|
|
|
# 4. Disable automounting... skipping, no GUI-based automounting present
|
|
|
|
# 5. Become root... done
|
|
|
|
# 6. Install ZFS in the Live CD environment (plus some tools)
|
2022-11-27 08:35:55 +00:00
|
|
|
apt-get install -y debootstrap gdisk zfsutils-linux
|
2022-10-04 07:10:43 +00:00
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
###############################
|
|
|
|
### Step 2: Disk Formatting ###
|
|
|
|
###############################
|
|
|
|
|
|
|
|
# 1. Set a variable with the disk name
|
|
|
|
# 2. If you are re-using a disk, clear it as necessary... skipping: do this yourself :)
|
|
|
|
# Ensure swap partitions are not in use
|
2022-10-04 07:10:43 +00:00
|
|
|
swapoff --all
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 3. Partition your disk(s)
|
2022-11-27 08:35:55 +00:00
|
|
|
# UEFI booting + boot pool + ZFS native encryption
|
|
|
|
disk_format "$DISK"
|
|
|
|
[ -n "$MIRROR" ] && disk_format "$MIRROR"
|
2022-10-04 07:10:43 +00:00
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 4. Create the boot pool
|
2022-11-27 08:35:55 +00:00
|
|
|
if [ -z "$MIRROR" ]; then
|
2022-11-28 00:48:44 +00:00
|
|
|
create_boot_pool "$ZFSROOT" "${DISK}3"
|
2022-11-27 08:35:55 +00:00
|
|
|
else
|
2022-11-28 00:48:44 +00:00
|
|
|
create_boot_pool "$ZFSROOT" "mirror ${DISK}3 ${MIRROR}3"
|
2022-11-27 08:35:55 +00:00
|
|
|
fi
|
2022-10-04 07:10:43 +00:00
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 5. Create the root pool
|
2022-11-27 08:35:55 +00:00
|
|
|
if [ -z "$MIRROR" ]; then
|
2022-11-28 00:48:44 +00:00
|
|
|
create_root_pool "$ZFSROOT" "${DISK}4" "$RPOOLPW"
|
2022-11-27 08:35:55 +00:00
|
|
|
else
|
2022-11-28 00:48:44 +00:00
|
|
|
create_root_pool "$ZFSROOT" "mirror ${DISK}4 ${MIRROR}4" "$RPOOLPW"
|
2022-11-27 08:35:55 +00:00
|
|
|
fi
|
2022-10-04 07:10:43 +00:00
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
###################################
|
|
|
|
### Step 3: System Installation ###
|
|
|
|
###################################
|
|
|
|
|
|
|
|
# 1. Create filesystem datasets to act as containers
|
2022-10-04 07:10:43 +00:00
|
|
|
zfs create -o canmount=off -o mountpoint=none rpool/ROOT
|
|
|
|
zfs create -o canmount=off -o mountpoint=none bpool/BOOT
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 2. Create filesystem datasets for the root and boot filesystems
|
2022-10-04 07:10:43 +00:00
|
|
|
zfs create -o canmount=noauto -o mountpoint=/ rpool/ROOT/debian
|
|
|
|
zfs mount rpool/ROOT/debian
|
|
|
|
zfs create -o mountpoint=/boot bpool/BOOT/debian
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 3. Create datasets
|
2022-10-04 07:10:43 +00:00
|
|
|
zfs create rpool/home
|
|
|
|
zfs create -o mountpoint=/root rpool/home/root
|
|
|
|
chmod 700 "$ZFSROOT/root"
|
|
|
|
zfs create -o canmount=off rpool/var
|
|
|
|
zfs create -o canmount=off rpool/var/lib
|
|
|
|
zfs create rpool/var/log
|
|
|
|
zfs create rpool/var/spool
|
2022-11-05 04:36:26 +00:00
|
|
|
|
|
|
|
# If you wish to separate these to exclude them from snapshots
|
2022-10-04 07:10:43 +00:00
|
|
|
zfs create -o com.sun:auto-snapshot=false rpool/var/cache
|
|
|
|
zfs create -o com.sun:auto-snapshot=false rpool/var/lib/nfs
|
|
|
|
zfs create -o com.sun:auto-snapshot=false rpool/var/tmp
|
|
|
|
chmod 1777 "$ZFSROOT/var/tmp"
|
2022-11-05 04:36:26 +00:00
|
|
|
|
|
|
|
# If you use /usr/local on this system
|
2022-10-04 07:10:43 +00:00
|
|
|
zfs create -o canmount=off rpool/usr
|
|
|
|
zfs create rpool/usr/local
|
2022-11-05 04:36:26 +00:00
|
|
|
|
|
|
|
# If this system will have a GUI
|
2022-10-04 07:10:43 +00:00
|
|
|
zfs create rpool/var/lib/AccountsService
|
|
|
|
zfs create rpool/var/lib/NetworkManager
|
2022-11-05 04:36:26 +00:00
|
|
|
|
|
|
|
# If this system will use Docker (which manages its own datasets & snapshots)
|
2022-10-04 07:10:43 +00:00
|
|
|
zfs create -o com.sun:auto-snapshot=false rpool/var/lib/docker
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 4. Mount a tmpfs at /run
|
2022-10-04 07:10:43 +00:00
|
|
|
mkdir "$ZFSROOT/run"
|
|
|
|
mount -t tmpfs tmpfs /mnt/run
|
|
|
|
mkdir "$ZFSROOT/run/lock"
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 5. Install the minimal system
|
2022-10-04 07:10:43 +00:00
|
|
|
debootstrap "$CODENAME" /mnt
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 6. Copy in zpool.cache
|
2022-10-04 07:10:43 +00:00
|
|
|
mkdir "$ZFSROOT/etc/zfs"
|
|
|
|
cp /etc/zfs/zpool.cache "$ZFSROOT/etc/zfs/"
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
####################################
|
|
|
|
### Step 4: System Configuration ###
|
|
|
|
####################################
|
|
|
|
|
|
|
|
# 1. Configure the hostname
|
2022-10-04 07:10:43 +00:00
|
|
|
hostname "$ZFSHOST"
|
|
|
|
hostname > "$ZFSROOT/etc/hostname"
|
|
|
|
sed "/^127.0.0.1.*localhost/a 127.0.1.1\\t$ZFSHOST" "$ZFSROOT/etc/hosts" | tee "$ZFSROOT/etc/hosts"
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 2. Configure the network interfaces
|
2022-10-04 07:10:43 +00:00
|
|
|
NETWORK_DEVICES=$(ip a | awk '$1 ~ /^[0-9][:]/ {print substr($2, 0, length($2)-1)}')
|
|
|
|
while read -r INTER; do
|
|
|
|
if [ ! "$INTER" = "lo" ]; then
|
|
|
|
cat <<-EOF > "$ZFSROOT/etc/network/interfaces.d/$INTER"
|
|
|
|
auto ${INTER}
|
|
|
|
iface ${INTER} inet dhcp
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
done <<< "$NETWORK_DEVICES"
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 3. Configure the package sources
|
2022-10-04 07:10:43 +00:00
|
|
|
ZFS_SOURCES_LIST="$ZFSROOT/etc/apt/sources.list"
|
|
|
|
[ -f "$ZFS_SOURCES_LIST" ] && mv "$ZFS_SOURCES_LIST" "$ZFS_SOURCES_LIST.$(date +%s).bak"
|
|
|
|
cat <<-EOF > "$ZFS_SOURCES_LIST"
|
|
|
|
deb http://deb.debian.org/debian ${CODENAME} main contrib
|
|
|
|
deb-src http://deb.debian.org/debian ${CODENAME} main contrib
|
|
|
|
|
|
|
|
deb http://deb.debian.org/debian-security ${CODENAME}-security main contrib
|
|
|
|
deb-src http://deb.debian.org/debian-security ${CODENAME}-security main contrib
|
|
|
|
|
|
|
|
deb http://deb.debian.org/debian ${CODENAME}-updates main contrib
|
|
|
|
deb-src http://deb.debian.org/debian ${CODENAME}-updates main contrib
|
|
|
|
EOF
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 4. Bind the virtual filesystems from the LiveCD environment to the new system and chroot into it
|
2022-11-27 08:35:55 +00:00
|
|
|
# Copy DISK/MIRROR vars under ZFSROOT
|
|
|
|
echo -e "DISK=${DISK}\nROOTPW=${ROOTPW}" > "$ZFSROOT/var/tmp/zfsenv"
|
2022-10-04 07:10:43 +00:00
|
|
|
|
2022-11-28 01:50:20 +00:00
|
|
|
# Copy self and GRUB mirror helper script into chroot
|
|
|
|
if [ -n "$MIRROR" ]; then
|
|
|
|
cp "$0" "$ZFSROOT/usr/local/bin/debianzfs"
|
|
|
|
chmod u+x "$ZFSROOT/usr/local/bin/debianzfs"
|
|
|
|
HELPER_SCRIPT="/root/MIRROR_GRUB_POSTINSTALL.sh"
|
|
|
|
cat <<-GRUBMIRROR > "${ZFSROOT}${HELPER_SCRIPT}"
|
|
|
|
#!/bin/bash
|
|
|
|
# Post-install GRUB mirror helper script
|
|
|
|
/usr/local/bin/debianzfs \
|
2022-11-28 05:53:09 +00:00
|
|
|
-gm $(disk_by_id "$MIRROR") \
|
|
|
|
$(disk_by_id "$DISK")
|
2022-11-28 01:50:20 +00:00
|
|
|
GRUBMIRROR
|
|
|
|
fi
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# Bind
|
2022-10-04 07:10:43 +00:00
|
|
|
mount --make-private --rbind /dev /mnt/dev
|
|
|
|
mount --make-private --rbind /proc /mnt/proc
|
|
|
|
mount --make-private --rbind /sys /mnt/sys
|
|
|
|
|
|
|
|
# Chroot
|
|
|
|
cat << CHROOT | chroot /mnt bash --login
|
|
|
|
# Setup
|
2022-11-05 04:36:26 +00:00
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
export LC_CTYPE=en_US.UTF-8
|
|
|
|
export LC_ALL=en_US.UTF-8
|
2022-10-04 07:10:43 +00:00
|
|
|
set -ex
|
|
|
|
. /var/tmp/zfsenv
|
|
|
|
unset CDPATH
|
|
|
|
cd
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 5. Configure a basic system environment
|
2022-10-04 07:10:43 +00:00
|
|
|
ln -s /proc/self/mounts /etc/mtab
|
2022-11-05 04:36:26 +00:00
|
|
|
apt-get update && apt-get upgrade -y
|
2022-10-04 07:10:43 +00:00
|
|
|
apt-get install -y console-setup locales
|
2022-11-05 04:36:26 +00:00
|
|
|
|
|
|
|
# Even if you prefer a non-English system language, always ensure that en_US.UTF-8 is available
|
2022-10-04 07:10:43 +00:00
|
|
|
dpkg-reconfigure locales tzdata keyboard-configuration console-setup
|
2022-11-05 04:36:26 +00:00
|
|
|
|
|
|
|
# 6. Install ZFS in the chroot environment for the new system
|
2022-10-04 07:10:43 +00:00
|
|
|
apt-get install -y dpkg-dev linux-headers-generic linux-image-generic zfs-initramfs
|
|
|
|
echo REMAKE_INITRD=yes > /etc/dkms/zfs.conf
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 7. For LUKS installs only, setup /etc/crypttab... skipping
|
|
|
|
# 8. Install GRUB
|
|
|
|
# Install GRUB for UEFI booting
|
2022-10-04 07:10:43 +00:00
|
|
|
apt-get install -y dosfstools
|
2022-11-05 04:36:26 +00:00
|
|
|
|
2022-10-27 05:16:57 +00:00
|
|
|
mkdosfs -F 32 -s 1 -n EFI "\${DISK}2"
|
2022-10-04 07:10:43 +00:00
|
|
|
mkdir /boot/efi
|
2022-10-27 05:16:57 +00:00
|
|
|
BLKID_BOOT="/dev/disk/by-uuid/\$(blkid -s UUID -o value \${DISK}2)"
|
|
|
|
echo "\${BLKID_BOOT} /boot/efi vfat defaults 0 0" >> /etc/fstab
|
2022-10-04 07:10:43 +00:00
|
|
|
mount /boot/efi
|
|
|
|
apt-get install -y grub-efi-amd64 shim-signed
|
2022-11-05 04:36:26 +00:00
|
|
|
|
|
|
|
# 9. Optional: Remove os-prober
|
2022-10-04 07:10:43 +00:00
|
|
|
apt-get purge -y os-prober
|
2022-11-05 04:36:26 +00:00
|
|
|
|
|
|
|
# 10. Set a root password
|
2022-10-04 07:10:43 +00:00
|
|
|
echo "root:\$ROOTPW" | chpasswd
|
|
|
|
unset ROOTPW
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 11. Enable importing bpool
|
2022-10-04 07:10:43 +00:00
|
|
|
cat <<- BPOOL > /etc/systemd/system/zfs-import-bpool.service
|
|
|
|
[Unit]
|
|
|
|
DefaultDependencies=no
|
|
|
|
Before=zfs-import-scan.service
|
|
|
|
Before=zfs-import-cache.service
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Type=oneshot
|
|
|
|
RemainAfterExit=yes
|
|
|
|
ExecStart=/sbin/zpool import -N -o cachefile=none bpool
|
|
|
|
# Work-around to preserve zpool cache:
|
|
|
|
ExecStartPre=-/bin/mv /etc/zfs/zpool.cache /etc/zfs/preboot_zpool.cache
|
|
|
|
ExecStartPost=-/bin/mv /etc/zfs/preboot_zpool.cache /etc/zfs/zpool.cache
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=zfs-import.target
|
|
|
|
BPOOL
|
|
|
|
|
|
|
|
systemctl enable zfs-import-bpool.service
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 12 Optional (but recommended): Mount a tmpfs to /tmp
|
2022-10-04 07:10:43 +00:00
|
|
|
cp /usr/share/systemd/tmp.mount /etc/systemd/system/
|
|
|
|
systemctl enable tmp.mount
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 13. Optional: Install SSH... skipping
|
|
|
|
# 14. Optional: For ZFS native encryption or LUKS, configure Dropbear for remote unlocking... skipping
|
|
|
|
# 15. Optional (but kindly requested): Install popcon... skipping
|
|
|
|
|
|
|
|
#################################
|
|
|
|
### Step 5: GRUB Installation ###
|
|
|
|
#################################
|
|
|
|
|
|
|
|
# 1. Verify that the ZFS boot filesystem is recognized
|
2022-10-04 07:10:43 +00:00
|
|
|
grub-probe /boot
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 2. Refresh the initrd files
|
2022-10-04 07:10:43 +00:00
|
|
|
update-initramfs -c -k all
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 3. Workaround GRUB's missing zpool-features support
|
2022-10-04 07:10:43 +00:00
|
|
|
sed -i "s/^\(GRUB_CMDLINE_LINUX=\).*/\1\"root=ZFS=rpool\/ROOT\/debian\"/" /etc/default/grub
|
2022-11-05 04:36:26 +00:00
|
|
|
|
|
|
|
# 4. Optional (but highly recommended): Make debugging GRUB easier
|
2022-10-04 07:10:43 +00:00
|
|
|
sed -i "s/^\(GRUB_CMDLINE_LINUX_DEFAULT=\).*/\1\"\"/" /etc/default/grub
|
|
|
|
sed -i '/GRUB_TERMINAL/s/^#//g' /etc/default/grub
|
|
|
|
cat /etc/default/grub
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 5. Update the boot configuration
|
2022-10-04 07:10:43 +00:00
|
|
|
update-grub
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 6. Install the boot loader
|
|
|
|
# For UEFI booting, install GRUB to the ESP
|
2022-10-04 07:10:43 +00:00
|
|
|
grub-install --target=x86_64-efi --efi-directory=/boot/efi \
|
2022-11-28 00:51:30 +00:00
|
|
|
--bootloader-id=debian --recheck --no-floppy
|
2022-10-04 07:10:43 +00:00
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 7. Fix filesystem mount ordering
|
2022-10-04 07:10:43 +00:00
|
|
|
mkdir /etc/zfs/zfs-list.cache
|
|
|
|
touch /etc/zfs/zfs-list.cache/bpool
|
|
|
|
touch /etc/zfs/zfs-list.cache/rpool
|
|
|
|
timeout 10 zed -F || \
|
2022-11-05 04:36:26 +00:00
|
|
|
|
|
|
|
# Verify that zed updated the cache by making sure these are not empty
|
2022-10-04 07:10:43 +00:00
|
|
|
test -s /etc/zfs/zfs-list.cache/bpool &&
|
|
|
|
test -s /etc/zfs/zfs-list.cache/rpool
|
|
|
|
|
|
|
|
# Fix the paths to eliminate /mnt
|
|
|
|
sed -Ei "s|/mnt/?|/|" /etc/zfs/zfs-list.cache/*
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
##########################
|
|
|
|
### Step 6: First Boot ###
|
|
|
|
##########################
|
|
|
|
|
|
|
|
# 1. Optional: Snapshot the initial installation
|
2022-10-04 07:10:43 +00:00
|
|
|
zfs snapshot bpool/BOOT/debian@install
|
|
|
|
zfs snapshot rpool/ROOT/debian@install
|
2022-11-05 04:36:26 +00:00
|
|
|
|
|
|
|
# 2. Exit from the chroot environment back to the LiveCD environment
|
2022-10-04 07:10:43 +00:00
|
|
|
exit
|
|
|
|
CHROOT
|
|
|
|
|
2022-11-05 04:36:26 +00:00
|
|
|
# 3. Run these commands in the LiveCD environment to unmount all filesystems
|
2022-10-04 07:10:43 +00:00
|
|
|
mount | grep -v zfs | tac | awk '/\/mnt/ {print $3}' | \
|
2022-11-28 00:48:44 +00:00
|
|
|
xargs -I{} umount -lf {}
|
2022-11-05 04:36:26 +00:00
|
|
|
|
|
|
|
# 4. If this fails for rpool, mounting it on boot will fail and you will need to
|
|
|
|
# zpool import -f rpool, then exit in the initamfs prompt
|
2022-10-04 07:10:43 +00:00
|
|
|
zpool export -a || exit 0
|
2022-11-28 01:50:20 +00:00
|
|
|
[ -n "$HELPER_SCRIPT" ] && \
|
|
|
|
echo "NOTICE: A GRUB mirror helper script was placed at $HELPER_SCRIPT"
|
2022-10-04 07:10:43 +00:00
|
|
|
exit 0
|