From d86871c76b5aea51002bbd9d4262582d7c3effd0 Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Mon, 26 Sep 2022 00:28:13 -0400 Subject: [PATCH] testing --- .gitignore | 3 +- README.md | 2 +- debianzfs.pkr.hcl | 8 ++-- debianzfs.sh | 100 +++++++++++++++++++++++++++++----------------- test.txt | 26 ++++++++++++ 5 files changed, 95 insertions(+), 44 deletions(-) create mode 100644 test.txt diff --git a/.gitignore b/.gitignore index f3f5545..57c14b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ packer_cache -output \ No newline at end of file +output +*.log \ No newline at end of file diff --git a/README.md b/README.md index 6b9c920..39b1b6b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Debian ZFS installation ## 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` 1. Download script diff --git a/debianzfs.pkr.hcl b/debianzfs.pkr.hcl index 591b215..f23f939 100644 --- a/debianzfs.pkr.hcl +++ b/debianzfs.pkr.hcl @@ -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_checksum = "sha256:8172b188061d098080bb315972becbe9bd387c856866746cee018102cd00fc9b" output_directory = "output" - #shutdown_command = "echo 'packer' | sudo -S shutdown -P now" - shutdown_command = "loljk" + shutdown_command = "echo 'packer' | sudo -S shutdown -P now" disk_size = "5000M" memory = 2048 format = "qcow2" @@ -15,7 +14,7 @@ source "qemu" "bullseye-live" { ssh_username = "user" ssh_password = var.password ssh_timeout = "5m" - vm_name = "debianzfs" + vm_name = "debianzfs.qcow2" net_device = "virtio-net" disk_interface = "virtio" boot_wait = "5s" @@ -43,11 +42,10 @@ build { provisioner "shell" { scripts = ["scripts/setup.sh"] - #scripts/autoinstall.exp"] } provisioner "shell" { - inline = ["sleep 99999999999"] + inline = ["sudo /tmp/debianzfs.sh /dev/vda"] } } diff --git a/debianzfs.sh b/debianzfs.sh index c54aece..f336469 100644 --- a/debianzfs.sh +++ b/debianzfs.sh @@ -7,22 +7,24 @@ ZFSHOST=$2 [ -z "$ZFSHOST" ] && ZFSHOST="debianzfs" # Settings +export DEBIAN_FRONTEND=noninteractive CODENAME="bullseye" ZFSROOT="/mnt" # Confirm DISK choice -if [ -n "$DISK" ]; then - read -rp "You selected to OVERWRITE '${DISK}' as hostname '${ZFSHOST}', are you sure? [y/N] " yn -else - echo "ERROR: No disk selected. Pass through a disk path, e.g., ./zfslive.sh /dev/sdX" - exit 1; -fi +#if [ -n "$DISK" ]; then +# read -rp "You selected to OVERWRITE '${DISK}' as hostname '${ZFSHOST}', are you sure? [y/N] " yn +# echo "assuming yes lol" +#else +# echo "ERROR: No disk selected. Pass through a disk path, e.g., ./zfslive.sh /dev/sdX" +# exit 1; +#fi -case $yn in - [yY] ) ;; - * ) echo "ERROR: User aborted" - exit 1;; -esac +#case $yn in +# [yY] ) ;; +# * ) echo "ERROR: User aborted" +# exit 1;; +#esac # Stop on error set -x @@ -40,8 +42,8 @@ SOURCES_LIST="/etc/apt/sources.list" echo "deb http://deb.debian.org/debian/ ${CODENAME} main contrib" > "$SOURCES_LIST" apt-get update -# Install ZFS -apt-get install -y debootstrap gdisk zfsutils-linux +# Install ZFS (and pwgen) +apt-get install -y debootstrap gdisk pwgen zfsutils-linux # Ensure swap isn't in use swapoff --all @@ -78,6 +80,8 @@ zpool create -f \ bpool "${DISK}3" # Create root pool +ZFSPW="$(pwgen 8 2)" +echo "$ZFSPW" | \ zpool create -f \ -o ashift=12 \ -o autotrim=on \ @@ -88,6 +92,7 @@ zpool create -f \ -O relatime=on \ -O canmount=off -O mountpoint=/ -R "$ZFSROOT" \ rpool "${DISK}4" +unset ZFSPW # Create filesystem datasets to act as containers 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" [ -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 bullseye main contrib -deb-src http://deb.debian.org/debian bullseye main contrib +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 bullseye-security main contrib -deb-src 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 ${CODENAME}-security main contrib -deb http://deb.debian.org/debian bullseye-updates main contrib -deb-src 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 ${CODENAME}-updates main contrib EOF # Copy DISK var under ZFSROOT @@ -167,7 +172,7 @@ mount --make-private --rbind /proc /mnt/proc mount --make-private --rbind /sys /mnt/sys # Chroot -cat << CHROOTEND | chroot /mnt bash --login +cat << CHROOT | chroot /mnt bash --login # Setup set -ex . /var/tmp/zfsenv @@ -175,6 +180,9 @@ unset CDPATH cd # 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 apt-get update apt-get upgrade -y @@ -193,33 +201,35 @@ echo "${DISK}2" /boot/efi vfat defaults 0 0 >> /etc/fstab mount /boot/efi apt-get install -y grub-efi-amd64 shim-signed apt-get purge -y os-prober -passwd +ROOTPW=$(pwgen 8 1) +echo "root:\$ROOTPW" | chpasswd +unset ROOTPW # Add bpool import service cat <<- BPOOL > /etc/systemd/system/zfs-import-bpool.service - [Unit] - DefaultDependencies=no - Before=zfs-import-scan.service - Before=zfs-import-cache.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 +[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 +[Install] +WantedBy=zfs-import.target +BPOOL # Enable importing bpool service systemctl enable zfs-import-bpool.service # Mount a tmpfs to /tmp -systemctl enable tmp.mount cp /usr/share/systemd/tmp.mount /etc/systemd/system/ +systemctl enable tmp.mount # Verify that the ZFS boot filesystem is recognized grub-probe /boot @@ -229,6 +239,9 @@ update-initramfs -c -k all # Workaround GRUB's missing zpool-features support 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-grub @@ -241,5 +254,18 @@ grub-install --target=x86_64-efi --efi-directory=/boot/efi \ mkdir /etc/zfs/zfs-list.cache touch /etc/zfs/zfs-list.cache/bpool touch /etc/zfs/zfs-list.cache/rpool +timeout 10 zed -F -CHROOTEND \ No newline at end of file +# 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 \ No newline at end of file diff --git a/test.txt b/test.txt new file mode 100644 index 0000000..bbb5700 --- /dev/null +++ b/test.txt @@ -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"