Skip to content

Commit

Permalink
it verks!
Browse files Browse the repository at this point in the history
  • Loading branch information
thehonker committed May 9, 2024
1 parent 9a2d8da commit 2d57579
Show file tree
Hide file tree
Showing 12 changed files with 249 additions and 184 deletions.
File renamed without changes.
18 changes: 18 additions & 0 deletions conf.yml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---

# Hostname to set
hostname: "potassium-os"

root_password: "potassium"

ssh_pubkey: "ssh-rsa <snip>"

kernel_cmdline: " console=tty0 console=ttyS0,115200 console=ttyS1,115200 "

# Define disks to use in zpools for rpool/bpool
# Only mirroring layouts are supported for now
zpool_disks:
- /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi0
- /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi1

zpool_layout: "mirror"
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ esac
if [ -z "$DISPLAY" ] && [[ $(tty) = "/dev/tty1" || $(tty) = "/dev/ttyS0" ]]; then
echo "Login on $(tty), starting installer" | tee -a "${HOME}/installer.log" | sudo tee /dev/kmesg
screen -S potassium-installer "/usr/local/bin/potassium-installer.sh"
screen -L -Logfile "${HOME}/installer.screen.log" -S potassium-installer "/usr/local/bin/potassium-installer.sh"
else
echo "You logged in on $(tty), so we didn't start the installer for you (that only happens on tty1 and ttyS0)."
echo "Feel free to look around, fix things, etc., and when you're ready, start the installer with"
Expand All @@ -44,7 +44,6 @@ fi
EOF

cat <<'EOF' >> /home/installer/.screenrc
# Enable mouse scrolling and scroll bar history scrolling
termcapinfo xterm* ti@:te@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,3 @@ systemctl enable generate-ssh-hostkeys.service
systemctl enable ssh.service

systemctl enable fetch-ssh-key.service

systemctl disable zfs-import-cache.service
systemctl disable zfs-import.target
38 changes: 0 additions & 38 deletions debian-live/source/config/hooks/live/9999-minimal.hook.chroot

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ gettext
screen
linux-image-amd64
linux-headers-amd64

zfs-dkms
zfsutils-linux

debootstrap
gdisk
efibootmgr
less
dosfstools
tree
3 changes: 2 additions & 1 deletion installer/potassium-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function _main () {
read -rp " Press enter to continue, SIGINT to exit."

# Install steps (in order)
# "finalize-system"
INSTALL_STEPS=( "prerequs" "load-installer-config" "make-zfs-pools" "debootstrap-system" "chroot-system-setup" "finalize-system" )
# run each installation step
for STEP in "${INSTALL_STEPS[@]}"; do
Expand Down Expand Up @@ -59,7 +60,7 @@ LOGO=$(cat <<END
╚════════════════════════════╝
Potassium
root-on-zfs installer v0.0.1
root-on-zfs installer v1.1.0-rc0
END
)
Expand Down
285 changes: 168 additions & 117 deletions installer/potassium/chroot-system-setup.sh

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion installer/potassium/finalize-system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,23 @@ function _main () {
# shellcheck source=common.sh
. "${TOP_DIR}/potassium/common.sh"

sudo chroot \
/mnt \
/bin/bash -c '
umount -R /boot
cd /root
zfs unmount -a || true
cd /
zfs unmount -a || true
'
mount | grep -v zfs | tac | awk '/\/mnt/ {print $3}' | \
xargs -i{} sudo -E umount -lf {}
sudo -E zpool export -a
sudo -E zpool export -a || true

printf '\n\n\n Installation finished\n\n\n'
read -rp " Press enter to reboot, SIGINT to exit to a shell."
sleep 5
sudo systemctl reboot
}

# Call main() to start the script
Expand Down
3 changes: 1 addition & 2 deletions installer/potassium/load-installer-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ function _main () {

echo "${INSTALLER_CONF_YAML}" | tee "${HOME}/potassium-installer-config.yml" | _log
if [ -n "${INSTALLER_CONF_YAML}" ]; then
_log "Loaded config sucessfully:\n\n"
_log "Loaded config sucessfully:"
_log "${INSTALLER_CONF_YAML}"
_log "\n\n"
export INSTALLER_CONF_YAML
else
_log "INSTALLER_CONF_YAML appears to be empty, cannot continue"
Expand Down
40 changes: 24 additions & 16 deletions installer/potassium/make-zfs-pools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,33 @@ function _main () {
. "${TOP_DIR}/potassium/common.sh"

_log "Selecting disks from config yaml"

ZPOOL_DISKS_STRING=$(yq '.zpool_disks[]' <<< "${INSTALLER_CONF_YAML}")
readarray -td, ZPOOL_DISKS <<<"$ZPOOL_DISKS_STRING,"
ZPOOL_DISKS_STRING=$(yq '.zpool_disks[]' <<< "${INSTALLER_CONF_YAML}" | sed 's/"//g')
readarray -t ZPOOL_DISKS <<< "${ZPOOL_DISKS_STRING}"
export ZPOOL_DISKS

_log "${ZPOOL_DISKS}"

_log "Selected disks for installation: ${ZPOOL_DISKS[*]}"

_log "Wiping disks and creating partitions"
for i in "${!ZPOOL_DISKS[@]}"; do
sudo -E /usr/sbin/wipefs -af "${ZPOOL_DISKS[$i]}"
sudo -E /usr/sbin/sgdisk --zap-all "${ZPOOL_DISKS[$i]}"
sudo -E /usr/sbin/sgdisk -n2:1M:+512M -t2:EF00 "${ZPOOL_DISKS[$i]}"
sudo -E /usr/sbin/sgdisk -n3:0:+2G -t3:BF01 "${ZPOOL_DISKS[$i]}"
sudo -E /usr/sbin/sgdisk -n4:0:0 -t4:BF00 "${ZPOOL_DISKS[$i]}"
for DISK in "${ZPOOL_DISKS[@]}"; do
# DISK="$( echo \"${DISK}\" | sed 's/"//g' )"
_log "Wiping and creating partitions on ${DISK}"
sudo -E /usr/sbin/wipefs -af "${DISK}"
sudo -E /usr/sbin/sgdisk --zap-all "${DISK}"
sudo -E /usr/sbin/sgdisk -n2:1M:+512M -t2:EF00 "${DISK}"
sudo -E /usr/sbin/sgdisk -n3:0:+2G -t3:BF01 "${DISK}"
sudo -E /usr/sbin/sgdisk -n4:0:0 -t4:BF00 "${DISK}"
done

for i in "${!ZPOOL_DISKS[@]}"; do
export DISKS_PARTS_ESP[$i]="${ZPOOL_DISKS[$i]}-part2"
export DISKS_PARTS_BPOOL[$i]="${ZPOOL_DISKS[$i]}-part3"
export DISKS_PARTS_RPOOL[$i]="${ZPOOL_DISKS[$i]}-part4"
DISKS_PARTS_ESP[i]="${ZPOOL_DISKS[$i]}-part2"
DISKS_PARTS_BPOOL[i]="${ZPOOL_DISKS[$i]}-part3"
DISKS_PARTS_RPOOL[i]="${ZPOOL_DISKS[$i]}-part4"
done

ZPOOL_LAYOUT=$(yq '.zpool_layout' <<< "${INSTALLER_CONF_YAML}")
export DISKS_PARTS_ESP
export DISKS_PARTS_BPOOL
export DISKS_PARTS_RPOOL

ZPOOL_LAYOUT=$(yq '.zpool_layout' <<< "${INSTALLER_CONF_YAML}" | sed 's/"//g')
export ZPOOL_LAYOUT

_log "Creating bpool on disks ${DISKS_PARTS_BPOOL[*]}"
Expand All @@ -68,8 +70,11 @@ function _main () {
-O normalization=formD \
-O relatime=on \
-O canmount=off -O mountpoint=/boot -R /mnt \
-f \
bpool "${ZPOOL_LAYOUT}" "${DISKS_PARTS_BPOOL[@]}"

_log "Creating rpool on disks ${DISKS_PARTS_RPOOL[*]}"

sudo -E zpool create \
-o ashift=12 \
-o autotrim=on \
Expand All @@ -78,7 +83,10 @@ function _main () {
-O normalization=formD \
-O relatime=on \
-O canmount=off -O mountpoint=/ -R /mnt \
-f \
rpool "${ZPOOL_LAYOUT}" "${DISKS_PARTS_RPOOL[@]}"

_log "Creating datasets"

sudo -E zfs create -o canmount=off -o mountpoint=none rpool/ROOT
sudo -E zfs create -o canmount=off -o mountpoint=none bpool/BOOT
Expand Down
16 changes: 16 additions & 0 deletions installer/potassium/prerequs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ function _main () {

# Ensure apt/dpkg don't try to spawn a tui
export DEBIAN_FRONTEND="noninteractive"

_log "Installing zfs-dkms"

sudo apt-get -yq update

sudo apt-get -yq install \
zfs-dkms \
zfsutils-linux

sudo systemctl disable zfs-import-cache.service
sudo systemctl disable zfs-import.target

sudo systemctl stop zfs-import-cache.service
sudo systemctl stop zfs-import.target

sudo modprobe zfs
}

# Call main() to start the script
Expand Down

0 comments on commit 2d57579

Please sign in to comment.