This commit is contained in:
Kris Lamoureux 2022-09-26 00:28:13 -04:00
parent 7811cdb945
commit d86871c76b
5 changed files with 95 additions and 44 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
packer_cache packer_cache
output output
*.log

View File

@ -1,6 +1,6 @@
# Debian ZFS installation # Debian ZFS installation
## Development ## Development
`PKR_VAR_password=$(pwgen -s 8 1) packer build .` `PKR_VAR_password=$(pwgen -s 8 1) packer build -color=false . > build_$(date +%s).log`
## Using `debianzfs.sh` ## Using `debianzfs.sh`
1. Download script 1. Download script

View File

@ -5,8 +5,7 @@ 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_url = "https://cdimage.debian.org/debian-cd/current-live/amd64/iso-hybrid/debian-live-11.5.0-amd64-standard.iso"
iso_checksum = "sha256:8172b188061d098080bb315972becbe9bd387c856866746cee018102cd00fc9b" iso_checksum = "sha256:8172b188061d098080bb315972becbe9bd387c856866746cee018102cd00fc9b"
output_directory = "output" output_directory = "output"
#shutdown_command = "echo 'packer' | sudo -S shutdown -P now" shutdown_command = "echo 'packer' | sudo -S shutdown -P now"
shutdown_command = "loljk"
disk_size = "5000M" disk_size = "5000M"
memory = 2048 memory = 2048
format = "qcow2" format = "qcow2"
@ -15,7 +14,7 @@ source "qemu" "bullseye-live" {
ssh_username = "user" ssh_username = "user"
ssh_password = var.password ssh_password = var.password
ssh_timeout = "5m" ssh_timeout = "5m"
vm_name = "debianzfs" vm_name = "debianzfs.qcow2"
net_device = "virtio-net" net_device = "virtio-net"
disk_interface = "virtio" disk_interface = "virtio"
boot_wait = "5s" boot_wait = "5s"
@ -43,11 +42,10 @@ build {
provisioner "shell" { provisioner "shell" {
scripts = ["scripts/setup.sh"] scripts = ["scripts/setup.sh"]
#scripts/autoinstall.exp"]
} }
provisioner "shell" { provisioner "shell" {
inline = ["sleep 99999999999"] inline = ["sudo /tmp/debianzfs.sh /dev/vda"]
} }
} }

View File

@ -7,22 +7,24 @@ ZFSHOST=$2
[ -z "$ZFSHOST" ] && ZFSHOST="debianzfs" [ -z "$ZFSHOST" ] && ZFSHOST="debianzfs"
# Settings # Settings
export DEBIAN_FRONTEND=noninteractive
CODENAME="bullseye" CODENAME="bullseye"
ZFSROOT="/mnt" ZFSROOT="/mnt"
# Confirm DISK choice # Confirm DISK choice
if [ -n "$DISK" ]; then #if [ -n "$DISK" ]; then
read -rp "You selected to OVERWRITE '${DISK}' as hostname '${ZFSHOST}', are you sure? [y/N] " yn # read -rp "You selected to OVERWRITE '${DISK}' as hostname '${ZFSHOST}', are you sure? [y/N] " yn
else # echo "assuming yes lol"
echo "ERROR: No disk selected. Pass through a disk path, e.g., ./zfslive.sh /dev/sdX" #else
exit 1; # echo "ERROR: No disk selected. Pass through a disk path, e.g., ./zfslive.sh /dev/sdX"
fi # exit 1;
#fi
case $yn in #case $yn in
[yY] ) ;; # [yY] ) ;;
* ) echo "ERROR: User aborted" # * ) echo "ERROR: User aborted"
exit 1;; # exit 1;;
esac #esac
# Stop on error # Stop on error
set -x set -x
@ -40,8 +42,8 @@ SOURCES_LIST="/etc/apt/sources.list"
echo "deb http://deb.debian.org/debian/ ${CODENAME} main contrib" > "$SOURCES_LIST" echo "deb http://deb.debian.org/debian/ ${CODENAME} main contrib" > "$SOURCES_LIST"
apt-get update apt-get update
# Install ZFS # Install ZFS (and pwgen)
apt-get install -y debootstrap gdisk zfsutils-linux apt-get install -y debootstrap gdisk pwgen zfsutils-linux
# Ensure swap isn't in use # Ensure swap isn't in use
swapoff --all swapoff --all
@ -78,6 +80,8 @@ zpool create -f \
bpool "${DISK}3" bpool "${DISK}3"
# Create root pool # Create root pool
ZFSPW="$(pwgen 8 2)"
echo "$ZFSPW" | \
zpool create -f \ zpool create -f \
-o ashift=12 \ -o ashift=12 \
-o autotrim=on \ -o autotrim=on \
@ -88,6 +92,7 @@ zpool create -f \
-O relatime=on \ -O relatime=on \
-O canmount=off -O mountpoint=/ -R "$ZFSROOT" \ -O canmount=off -O mountpoint=/ -R "$ZFSROOT" \
rpool "${DISK}4" rpool "${DISK}4"
unset ZFSPW
# Create filesystem datasets to act as containers # Create filesystem datasets to act as containers
zfs create -o canmount=off -o mountpoint=none rpool/ROOT zfs create -o canmount=off -o mountpoint=none rpool/ROOT
@ -148,14 +153,14 @@ done <<< "$NETWORK_DEVICES"
ZFS_SOURCES_LIST="$ZFSROOT/etc/apt/sources.list" ZFS_SOURCES_LIST="$ZFSROOT/etc/apt/sources.list"
[ -f "$ZFS_SOURCES_LIST" ] && mv "$ZFS_SOURCES_LIST" "$ZFS_SOURCES_LIST.$(date +%s).bak" [ -f "$ZFS_SOURCES_LIST" ] && mv "$ZFS_SOURCES_LIST" "$ZFS_SOURCES_LIST.$(date +%s).bak"
cat <<-EOF > "$ZFS_SOURCES_LIST" cat <<-EOF > "$ZFS_SOURCES_LIST"
deb http://deb.debian.org/debian bullseye main contrib deb http://deb.debian.org/debian ${CODENAME} main contrib
deb-src http://deb.debian.org/debian bullseye main contrib deb-src http://deb.debian.org/debian ${CODENAME} main contrib
deb http://deb.debian.org/debian-security bullseye-security main contrib deb http://deb.debian.org/debian-security ${CODENAME}-security main contrib
deb-src http://deb.debian.org/debian-security bullseye-security main contrib deb-src http://deb.debian.org/debian-security ${CODENAME}-security main contrib
deb http://deb.debian.org/debian bullseye-updates main contrib deb http://deb.debian.org/debian ${CODENAME}-updates main contrib
deb-src http://deb.debian.org/debian bullseye-updates main contrib deb-src http://deb.debian.org/debian ${CODENAME}-updates main contrib
EOF EOF
# Copy DISK var under ZFSROOT # Copy DISK var under ZFSROOT
@ -167,7 +172,7 @@ mount --make-private --rbind /proc /mnt/proc
mount --make-private --rbind /sys /mnt/sys mount --make-private --rbind /sys /mnt/sys
# Chroot # Chroot
cat << CHROOTEND | chroot /mnt bash --login cat << CHROOT | chroot /mnt bash --login
# Setup # Setup
set -ex set -ex
. /var/tmp/zfsenv . /var/tmp/zfsenv
@ -175,6 +180,9 @@ unset CDPATH
cd cd
# Configure a basic system environment # Configure a basic system environment
export DEBIAN_FRONTEND=noninteractive
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
ln -s /proc/self/mounts /etc/mtab ln -s /proc/self/mounts /etc/mtab
apt-get update apt-get update
apt-get upgrade -y apt-get upgrade -y
@ -193,7 +201,9 @@ echo "${DISK}2" /boot/efi vfat defaults 0 0 >> /etc/fstab
mount /boot/efi mount /boot/efi
apt-get install -y grub-efi-amd64 shim-signed apt-get install -y grub-efi-amd64 shim-signed
apt-get purge -y os-prober apt-get purge -y os-prober
passwd ROOTPW=$(pwgen 8 1)
echo "root:\$ROOTPW" | chpasswd
unset ROOTPW
# Add bpool import service # Add bpool import service
cat <<- BPOOL > /etc/systemd/system/zfs-import-bpool.service cat <<- BPOOL > /etc/systemd/system/zfs-import-bpool.service
@ -218,8 +228,8 @@ cat <<- BPOOL > /etc/systemd/system/zfs-import-bpool.service
systemctl enable zfs-import-bpool.service systemctl enable zfs-import-bpool.service
# Mount a tmpfs to /tmp # Mount a tmpfs to /tmp
systemctl enable tmp.mount
cp /usr/share/systemd/tmp.mount /etc/systemd/system/ cp /usr/share/systemd/tmp.mount /etc/systemd/system/
systemctl enable tmp.mount
# Verify that the ZFS boot filesystem is recognized # Verify that the ZFS boot filesystem is recognized
grub-probe /boot grub-probe /boot
@ -229,6 +239,9 @@ update-initramfs -c -k all
# Workaround GRUB's missing zpool-features support # Workaround GRUB's missing zpool-features support
cat /etc/default/grub cat /etc/default/grub
sed -i "s/^\(GRUB_CMDLINE_LINUX=\).*/\1\"root=ZFS=rpool\/ROOT\/debian\"/" /etc/default/grub
sed -i "s/^\(GRUB_CMDLINE_LINUX_DEFAULT=\).*/\1\"\"/" /etc/default/grub
sed -i '/GRUB_TERMINAL/s/^#//g' /etc/default/grub
# Update the boot configuration # Update the boot configuration
update-grub update-grub
@ -241,5 +254,18 @@ grub-install --target=x86_64-efi --efi-directory=/boot/efi \
mkdir /etc/zfs/zfs-list.cache mkdir /etc/zfs/zfs-list.cache
touch /etc/zfs/zfs-list.cache/bpool touch /etc/zfs/zfs-list.cache/bpool
touch /etc/zfs/zfs-list.cache/rpool touch /etc/zfs/zfs-list.cache/rpool
timeout 10 zed -F
CHROOTEND # Fix the paths to eliminate /mnt
sed -Ei "s|/mnt/?|/|" /etc/zfs/zfs-list.cache/*
# Snapshot the initial installation
zfs snapshot bpool/BOOT/debian@install
zfs snapshot rpool/ROOT/debian@install
exit
CHROOT
mount | grep -v zfs | tac | awk '/\/mnt/ {print $3}' | \
xargs -I{} umount -lf {}
zpool export -a
exit 0

26
test.txt Normal file
View File

@ -0,0 +1,26 @@
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
GRUB_CMDLINE_LINUX=""
# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"
# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console
# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480
# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true
# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"
# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"