Use only UUIDs for runtime disk management
This commit is contained in:
parent
4fbeae6f7e
commit
7186daeb1c
@ -1 +1 @@
|
||||
Subproject commit 54d3c1d23b8994eeeac8348c6e820aaf3a56cc7b
|
||||
Subproject commit d9334fd12be8feb11106564d1a3b2e7526c89f43
|
14
vm.sh
14
vm.sh
@ -27,7 +27,7 @@ n
|
||||
p
|
||||
1
|
||||
|
||||
+100m
|
||||
+50m
|
||||
a
|
||||
1
|
||||
n
|
||||
@ -63,20 +63,21 @@ mount -t ext4 /dev/sda1 /mnt/boot
|
||||
setup-disk -m sys /mnt
|
||||
|
||||
# Update boot-time volume information
|
||||
BOOT_UUID=$(blkid /dev/sda1 | cut -d' ' -f2 | tr -d '"')
|
||||
BOOT_UUID=$(blkid -o value /dev/sda1 | head -1)
|
||||
CRYPT_UUID=$(blkid -o value /dev/sda2 | head -1)
|
||||
cat <<EOF >/mnt/etc/fstab
|
||||
/dev/vg0/root / ext4 rw,noatime,data=ordered 0 1
|
||||
${BOOT_UUID} /boot ext4 rw,noatime,data=ordered 0 2
|
||||
UUID=${BOOT_UUID} /boot ext4 rw,noatime,data=ordered 0 2
|
||||
/dev/vg0/swap swap swap defaults 0 0
|
||||
EOF
|
||||
echo "system /dev/sda2 none luks" >/mnt/etc/crypttab
|
||||
echo "system UUID=${CRYPT_UUID} none luks" >/mnt/etc/crypttab
|
||||
|
||||
# Rebuild initfs
|
||||
sed -i 's/lvm/lvm cryptsetup/' /mnt/etc/mkinitfs/mkinitfs.conf
|
||||
mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt $(ls /mnt/lib/modules)
|
||||
|
||||
# Update extlinux (ignore the errors)
|
||||
sed -i 's/rootfstype=ext4/rootfstype=ext4 cryptroot=\/dev\/sda2 cryptdm=system/' /mnt/etc/update-extlinux.conf
|
||||
sed -i "s/rootfstype=ext4/rootfstype=ext4 cryptroot=UUID=${CRYPT_UUID} cryptdm=system/" /mnt/etc/update-extlinux.conf
|
||||
chroot /mnt update-extlinux
|
||||
sed -i 's/overwrite=1/overwrite=0/' /mnt/etc/update-extlinux.conf
|
||||
|
||||
@ -86,13 +87,14 @@ chroot /mnt setup-timezone -z Europe/Prague
|
||||
# Install basic system
|
||||
apk --no-cache add apache2-utils gettext
|
||||
wget https://repo.spotter.cz/vm.tar -O - | tar xf - -C /mnt
|
||||
envsubst </boot/extlinux.conf.old >/boot/extlinux.conf
|
||||
chroot /mnt apk --no-cache add bridge ca-certificates curl e2fsprogs-extra gettext iptables kbd-misc libressl lxc postfix nginx openssh-server openssh-sftp-server util-linux wireguard-virt@vm wireguard-tools-wg@vm acme-sh@vm vmmgr@vm
|
||||
chroot /mnt newaliases
|
||||
mkdir -p /mnt/var/log/lxc
|
||||
for SERVICE in cgroups consolefont crond iptables networking nginx ntpd postfix swap urandom vmmgr; do
|
||||
ln -s /etc/init.d/${SERVICE} /mnt/etc/runlevels/boot
|
||||
done
|
||||
ADMINPWD=$(htpasswd -bnBC 10 "" "${ENCPWD}" | tr -d ':\n' | sed 's/$2y/$2b/') envsubst </mnt/etc/vmmgr/config.default.json >/mnt/etc/vmmgr/config.json
|
||||
ADMINPWD=$(htpasswd -bnBC 10 '' "${ENCPWD}" | tr -d ':\n' | sed 's/$2y/$2b/') envsubst </mnt/etc/vmmgr/config.default.json >/mnt/etc/vmmgr/config.json
|
||||
|
||||
# Cleanup
|
||||
rm -rf /mnt/root
|
||||
|
@ -6,4 +6,4 @@ DISPLAY vm.txt
|
||||
LABEL vm
|
||||
LINUX vmlinuz-virt
|
||||
INITRD initramfs-virt
|
||||
APPEND elevator=noop root=/dev/vg0/root modules=sd-mod,usb-storage,ext4 nomodeset quiet rootfstype=ext4 cryptroot=/dev/sda2 cryptdm=system
|
||||
APPEND elevator=noop root=/dev/vg0/root modules=sd-mod,usb-storage,ext4 nomodeset quiet rootfstype=ext4 cryptroot=UUID=${CRYPT_UUID} cryptdm=system
|
@ -1,13 +1,19 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# Determine partition and hard drive paths
|
||||
UUID=$(/usr/bin/awk '{print substr($2,6)}' /etc/crypttab)
|
||||
PART=$(/sbin/blkid -U ${UUID})
|
||||
DISK=${PART%?}
|
||||
DEV=$(/usr/bin/basename ${DISK})
|
||||
|
||||
# No resizing with less than 10k unused blocks
|
||||
BLOCKS_FREE=$(/usr/bin/awk '/sda$/ {blocks = $3} /sda\d/ {blocks -= $3} END {print blocks}' /proc/partitions)
|
||||
BLOCKS_FREE=$(/usr/bin/awk -v dev="${DEV}" '{if ($0 ~ dev "$") blocks = $3} {if ($0 ~ dev "[0-9]") blocks -= $3} END {print blocks}' /proc/partitions)
|
||||
[ ${BLOCKS_FREE} -lt 10240 ] && exit 0
|
||||
|
||||
# Resize physical partition
|
||||
# Force busybox fdisk as util-linux fdisk breaks subsequent partx command
|
||||
cat <<EOF | /bin/busybox fdisk /dev/sda || /bin/true
|
||||
cat <<EOF | /bin/busybox fdisk ${DISK} || /bin/true
|
||||
d
|
||||
2
|
||||
n
|
||||
@ -22,7 +28,7 @@ w
|
||||
EOF
|
||||
|
||||
# Re-read partition table
|
||||
/usr/sbin/partx -u /dev/sda2
|
||||
/usr/sbin/partx -u ${PART}
|
||||
|
||||
# Resize dmcrypt and LVM PV
|
||||
/sbin/cryptsetup resize system
|
||||
|
Loading…
Reference in New Issue
Block a user