Compare commits
3 Commits
cef71d557a
...
087070a3d4
Author | SHA1 | Date | |
---|---|---|---|
087070a3d4 | |||
0d99930fa7 | |||
e96a557d9a |
55
debianzfs.sh
55
debianzfs.sh
@ -7,7 +7,7 @@
|
||||
### Functions ###
|
||||
#################
|
||||
function usage () {
|
||||
echo "Usage: ./$(basename "$0") [-mpPr] <DISK> [hostname]"
|
||||
echo "Usage: ./$(basename "$0") [-mpPr] <DISK> <HOSTNAME>"
|
||||
}
|
||||
|
||||
function disk_check () {
|
||||
@ -95,6 +95,14 @@ function create_root_pool () {
|
||||
rpool "$2"
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
################
|
||||
### Settings ###
|
||||
################
|
||||
@ -103,8 +111,9 @@ export DEBIAN_FRONTEND=noninteractive
|
||||
CODENAME="bullseye"
|
||||
|
||||
# Options
|
||||
while getopts ':m:p:P:r:' OPTION; do
|
||||
while getopts ':gm:p:P:r:' OPTION; do
|
||||
case "$OPTION" in
|
||||
g) GRUB_MIRROR="true";;
|
||||
m) MIRROR="$OPTARG";;
|
||||
p) ROOTPW="$OPTARG";;
|
||||
P) RPOOLPW="$OPTARG";;
|
||||
@ -120,6 +129,24 @@ shift "$((OPTIND -1))"
|
||||
DISK=$1
|
||||
ZFSHOST=$2
|
||||
|
||||
# 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
|
||||
|
||||
# Verify variables
|
||||
[ -z "$ZFSROOT" ] && ZFSROOT="/mnt"
|
||||
|
||||
@ -157,9 +184,6 @@ if [ "$DEBUG" == "true" ]; then
|
||||
echo "RPOOLPW=${RPOOLPW}"
|
||||
fi
|
||||
|
||||
# Display commands
|
||||
set -x
|
||||
|
||||
# Are the DISK paths block devices? AND
|
||||
# Are the DISK pathes empty devices? i.e., no filesystem signatures
|
||||
disk_check "$DISK"
|
||||
@ -173,6 +197,9 @@ fi
|
||||
### Step 1: Prepare The Install Environment ###
|
||||
###############################################
|
||||
|
||||
# Display commands
|
||||
set -x
|
||||
|
||||
# 1. Boot the Debian GNU/Linux Live CD... done
|
||||
# 2. Setup and update the repositories
|
||||
SOURCES_LIST="/etc/apt/sources.list"
|
||||
@ -303,6 +330,22 @@ EOF
|
||||
# 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"
|
||||
DDIF=$(find /dev/disk/by-id -lname ../../"$(basename "$DISK")" | tail -n1)
|
||||
DDOF=$(find /dev/disk/by-id -lname ../../"$(basename "$MIRROR")" | tail -n1)
|
||||
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 $DDOF \
|
||||
$DDIF
|
||||
GRUBMIRROR
|
||||
fi
|
||||
|
||||
# Bind
|
||||
mount --make-private --rbind /dev /mnt/dev
|
||||
mount --make-private --rbind /proc /mnt/proc
|
||||
@ -437,4 +480,6 @@ mount | grep -v zfs | tac | awk '/\/mnt/ {print $3}' | \
|
||||
# 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
|
||||
zpool export -a || exit 0
|
||||
[ -n "$HELPER_SCRIPT" ] && \
|
||||
echo "NOTICE: A GRUB mirror helper script was placed at $HELPER_SCRIPT"
|
||||
exit 0
|
||||
|
Loading…
Reference in New Issue
Block a user