Compare commits

...

5 Commits

Author SHA1 Message Date
bbb88746ad Remove unused and deprecated function 2023-06-12 01:42:00 -04:00
81f387c340 Updated debianzfs for Debian 12 (Bookworm)
- Shifted release info to packer variables
- Doubled boot_command initial wait to 20s
- Renamed Packer source to debian-live
- Removed .sh from debianzfs script path
- Tweaked comment wording
- Replaced hardcoded codename
- Used 'ln -fs' for existing /etc/mtab
2023-06-12 00:47:58 -04:00
9977148dd6 Localize all the variables! 2022-12-01 02:33:31 -05:00
df45e39d42 Follow block device symlinks 2022-11-30 01:54:20 -05:00
7ea2454c70 Add an option to switch the partition suffix 2022-11-30 01:04:13 -05:00
4 changed files with 68 additions and 62 deletions

View File

@@ -1,6 +1,13 @@
all: debianzfs.qcow2
# Generate password
debianzfs.qcow2: export PKR_VAR_password="$(pwgen -s 8 1)"
# Release info
debianzfs.qcow2: export PKR_VAR_release=12.0.0
debianzfs.qcow2: export PKR_VAR_codename=bookworm
debianzfs.qcow2: export PKR_VAR_sha256=fa3960f6f692fc60a43eec4362d60f754b4a246ab64aa662270dd879a946de84
debianzfs.qcow2:
packer build -color=false . | tee debianzfs.log

View File

@@ -1,9 +1,11 @@
# Set 'password' using shell var: PKR_VAR_password=$(pwgen -s 8 1)
variable "password" {}
variable "release" {}
variable "sha256" {}
source "qemu" "bullseye-live" {
iso_url = "https://cdimage.debian.org/debian-cd/current-live/amd64/iso-hybrid/debian-live-11.5.0-amd64-standard.iso"
iso_checksum = "sha256:8172b188061d098080bb315972becbe9bd387c856866746cee018102cd00fc9b"
source "qemu" "debian-live" {
iso_url = "https://cdimage.debian.org/debian-cd/current-live/amd64/iso-hybrid/debian-live-${var.release}-amd64-standard.iso"
iso_checksum = "sha256:${var.sha256}"
output_directory = "output"
shutdown_command = "echo 'packer' | sudo -S shutdown -P now"
disk_size = "5000M"
@@ -19,7 +21,7 @@ source "qemu" "bullseye-live" {
disk_interface = "virtio"
boot_wait = "5s"
boot_command = [
"<enter><wait10>",
"<enter><wait20>",
"<enter><wait>",
"sudo -i<enter><wait>",
"read -s userpw<enter><wait>",
@@ -33,11 +35,11 @@ source "qemu" "bullseye-live" {
build {
name = "zfs"
sources = ["source.qemu.bullseye-live"]
sources = ["source.qemu.debian-live"]
provisioner "file" {
source = "debianzfs.sh"
destination = "/tmp/debianzfs.sh"
destination = "/tmp/debianzfs"
}
provisioner "shell" {
@@ -45,7 +47,7 @@ build {
}
provisioner "shell" {
inline = ["sudo /tmp/debianzfs.sh -ip changeme -P letmeinzfs! /dev/vda debianzfs"]
inline = ["sudo /tmp/debianzfs -i -s0 -p 'changeme' -P 'letmeinzfs!' /dev/vda debianzfs"]
}
}

View File

@@ -1,31 +1,37 @@
#!/bin/bash
# Script is based off official guide: see "Debian Bullseye Root on ZFS"
# This script is originally based off the "Debian Bullseye Root on ZFS" guide
# https://openzfs.github.io/openzfs-docs/Getting%20Started/Debian/Debian%20Bullseye%20Root%20on%20ZFS.html
#################
### Functions ###
#################
function usage () {
echo "Usage: $(basename "$0") [-ghimpPr] <DISK> [HOSTNAME]"
echo "Usage: $(basename "$0") [-ghimpPrs] <DISK> [HOSTNAME]"
echo -e "\t-g\n\t\tMirror GRUB after the installation. Requires: -m"
echo -e "\n\t-h\n\t\tThe help menu, i.e., the menu you're seeing now."
echo -e "\n\t-i\n\t\tIgnore the check for the /dev/disk/by-id/* format."
echo -e "\n\t-i\n\t\tIgnore the check for the /dev/disk/by-id/* format. You'll likely want: -s"
echo -e "\n\t-m <MIRROR>\n\t\tSet the MIRROR disk for a ZFS mirror installation."
echo -e "\n\t-p <PASSWORD>\n\t\tSet the password for root. Caution: saves to file temporarily."
echo -e "\n\t-P <PASSWWORD>\n\t\tSet the password for encrypting the root zpool."
echo -e "\n\t-r <ZFSROOT>\n\t\tSet the path for the new ZFS chroot. Defaults to /mnt"
echo -e "\n\t-s <PARTSUFFIX>\n\t\tSet the partition suffix for disks, defaults to: -part"
echo -e "\t\tSet to a zero '0' to remove the suffix entirely, i.e., -s0"
}
function disk_check () {
DISK_TYPE=$(file "$1" | awk '{ print $2$3 }')
local DISK="$1"
local DISK_TYPE
[ -L "$DISK" ] && DISK=$(readlink -f "$DISK")
DISK_TYPE=$(file "$DISK" | awk '{ print $2$3 }')
if [ "$DISK_TYPE" != "blockspecial" ]; then
echo "ERROR: Disk '$1' is not a block device"
echo "ERROR: Disk '$DISK' is not a block device"
exit 1
fi
}
function disk_status () {
local OUTPUT
OUTPUT=$(wipefs "$1")
if [ -n "$OUTPUT" ]; then
echo "ERROR: $1 is not empty"
@@ -35,6 +41,8 @@ function disk_status () {
}
function password_prompt () {
local password
local password_confirm
unset PASSWORD_PROMPT_RESULT
while true; do
read -r -s -p "${1}: " password
@@ -104,24 +112,6 @@ function create_root_pool () {
rpool $2
}
function part_path () {
DISK="$1"
PART="$2"
[ "$(disk_check "$DISK")" == 1 ] && exit 1
if [ "${DISK:0:7}" == "/dev/sd" ]; then
DISK_PART="${DISK}${PART}"
elif [ "${DISK:0:9}" == "/dev/nvme" ]; then
DISK_PART="${DISK}p${PART}"
else
echo "ERROR: Disk not recognized"
exit 1
fi
[ "$(disk_check "$DISK_PART")" == 1 ] && exit 1
echo "$DISK_PART"
exit 0
}
function mirror_grub () {
umount /boot/efi
dd if="$1" of="$2"
@@ -131,7 +121,7 @@ function mirror_grub () {
}
function disk_byid_check () {
BYID="/dev/disk/by-id/"
local BYID="/dev/disk/by-id/"
if [ ! "${1:0:${#BYID}}" == "$BYID" ]; then
echo "ERROR: DISK needs to be ${BYID}* format"
exit 1
@@ -143,10 +133,10 @@ function disk_byid_check () {
################
# Static
export DEBIAN_FRONTEND=noninteractive
CODENAME="bullseye"
CODENAME="bookworm"
# Options
while getopts ':ghim:p:P:r:' OPTION; do
while getopts ':ghim:p:P:r:s:' OPTION; do
case "$OPTION" in
g) GRUB_MIRROR="true";;
i) IGNORE_BYID="true";;
@@ -154,6 +144,7 @@ while getopts ':ghim:p:P:r:' OPTION; do
p) ROOTPW="$OPTARG";;
P) RPOOLPW="$OPTARG";;
r) ZFSROOT="$OPTARG";;
s) PARTSUFFIX="$OPTARG";;
?)
usage
exit 1;;
@@ -188,6 +179,12 @@ fi
# Verify variables
[ -z "$ZFSROOT" ] && ZFSROOT="/mnt"
if [ -z "$PARTSUFFIX" ]; then
PARTSUFFIX="-part"
elif [ "$PARTSUFFIX" == "0" ]; then
PARTSUFFIX=""
fi
if [ -z "$DISK" ]; then
echo "ERROR: DISK not set"
usage
@@ -213,13 +210,16 @@ if [ -z "$RPOOLPW" ]; then
fi
if [ "$DEBUG" == "true" ]; then
echo "CODENAME=${CODENAME}"
echo "DISK=${DISK}"
echo "ZFSHOST=${ZFSHOST}"
echo "ZFSROOT=${ZFSROOT}"
echo "MIRROR=${MIRROR}"
echo "ROOTPW=${ROOTPW}"
echo "RPOOLPW=${RPOOLPW}"
echo "CODENAME='${CODENAME}'"
echo "DISK='${DISK}'"
echo "ZFSHOST='${ZFSHOST}'"
echo "ZFSROOT='${ZFSROOT}'"
echo "MIRROR='${MIRROR}'"
echo "ROOTPW='${ROOTPW}'"
echo "RPOOLPW='${RPOOLPW}'"
echo "PARTSUFFIX='${PARTSUFFIX}'"
echo "GRUB_MIRROR='${GRUB_MIRROR}'"
echo "IGNORE_BYID='${IGNORE_BYID}'"
fi
# Are the DISK paths block devices? AND
@@ -269,23 +269,23 @@ disk_format "$DISK"
sleep 5
# Check for partitions 3 and 4
disk_check "$DISK-part3"
disk_check "$DISK-part4"
disk_check "${DISK}${PARTSUFFIX}3"
disk_check "${DISK}${PARTSUFFIX}4"
if [ -n "$MIRROR" ]; then
disk_check "$MIRROR-part3"
disk_check "$MIRROR-part4"
disk_check "${DISK}${PARTSUFFIX}3"
disk_check "${DISK}${PARTSUFFIX}4"
fi
# 4. Create the boot pool
# 5. Create the root pool
if [ -z "$MIRROR" ]; then
create_boot_pool "$ZFSROOT" "$DISK-part3"
create_root_pool "$ZFSROOT" "$DISK-part4" "$RPOOLPW"
create_boot_pool "$ZFSROOT" "${DISK}${PARTSUFFIX}3"
create_root_pool "$ZFSROOT" "${DISK}${PARTSUFFIX}4" "$RPOOLPW"
else
create_boot_pool "$ZFSROOT" \
"mirror ${DISK}-part3 $MIRROR-part3"
"mirror ${DISK}${PARTSUFFIX}3 ${MIRROR}${PARTSUFFIX}3"
create_root_pool "$ZFSROOT" \
"mirror ${DISK}-part4 $MIRROR-part4" "$RPOOLPW"
"mirror ${DISK}${PARTSUFFIX}4 ${MIRROR}${PARTSUFFIX}4" "$RPOOLPW"
fi
###################################
@@ -373,30 +373,27 @@ deb http://deb.debian.org/debian ${CODENAME}-updates main contrib
deb-src http://deb.debian.org/debian ${CODENAME}-updates main contrib
EOF
# 4. Bind the virtual filesystems from the LiveCD environment to the new system and chroot into it
# Copy DISK/MIRROR vars under ZFSROOT
echo -e "DISK=\"$DISK\"\nROOTPW=\"${ROOTPW}\"" > "$ZFSROOT/var/tmp/zfsenv"
# 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"
chmod +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 \
-gm $MIRROR-part2 \
$DISK-part2)
-gm ${MIRROR}${PARTSUFFIX}2 \
${DISK}${PARTSUFFIX}2
GRUBMIRROR
fi
# Bind
# 4. Bind the virtual filesystems from the LiveCD environment to the new system and chroot into it
mount --make-private --rbind /dev /mnt/dev
mount --make-private --rbind /proc /mnt/proc
mount --make-private --rbind /sys /mnt/sys
# Chroot
# Copy DISK/MIRROR vars under ZFSROOT and chroot
echo -e "DISK=\"$DISK\"\nPARTSUFFIX=\"${PARTSUFFIX}\"\nROOTPW=\"${ROOTPW}\"" > "$ZFSROOT/var/tmp/zfsenv"
cat << CHROOT | chroot /mnt bash --login
# Setup
export DEBIAN_FRONTEND=noninteractive
@@ -407,7 +404,7 @@ unset CDPATH
cd
# 5. Configure a basic system environment
ln -s /proc/self/mounts /etc/mtab
ln -fs /proc/self/mounts /etc/mtab
apt-get update && apt-get upgrade -y
apt-get install -y console-setup locales
@@ -423,9 +420,9 @@ echo REMAKE_INITRD=yes > /etc/dkms/zfs.conf
# Install GRUB for UEFI booting
apt-get install -y dosfstools
mkdosfs -F 32 -s 1 -n EFI "\${DISK}-part2"
mkdosfs -F 32 -s 1 -n EFI "\${DISK}\${PARTSUFFIX}2"
mkdir /boot/efi
BLKID_BOOT="/dev/disk/by-uuid/\$(blkid -s UUID -o value \${DISK}-part2)"
BLKID_BOOT="/dev/disk/by-uuid/\$(blkid -s UUID -o value \${DISK}\${PARTSUFFIX}2)"
echo "\${BLKID_BOOT} /boot/efi vfat defaults 0 0" >> /etc/fstab
mount /boot/efi
apt-get install -y grub-efi-amd64 shim-signed

View File

@@ -1,3 +1,3 @@
#!/bin/bash
sudo passwd -d user
sudo chmod u+x /tmp/debianzfs.sh
sudo chmod u+x /tmp/debianzfs