Use only UUIDs for runtime disk management

This commit is contained in:
Disassembler 2019-06-12 16:27:49 +02:00
parent 4fbeae6f7e
commit 7186daeb1c
Signed by: Disassembler
GPG Key ID: 524BD33A0EE29499
4 changed files with 19 additions and 11 deletions

@ -1 +1 @@
Subproject commit 54d3c1d23b8994eeeac8348c6e820aaf3a56cc7b Subproject commit d9334fd12be8feb11106564d1a3b2e7526c89f43

14
vm.sh
View File

@ -27,7 +27,7 @@ n
p p
1 1
+100m +50m
a a
1 1
n n
@ -63,20 +63,21 @@ mount -t ext4 /dev/sda1 /mnt/boot
setup-disk -m sys /mnt setup-disk -m sys /mnt
# Update boot-time volume information # 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 cat <<EOF >/mnt/etc/fstab
/dev/vg0/root / ext4 rw,noatime,data=ordered 0 1 /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 /dev/vg0/swap swap swap defaults 0 0
EOF EOF
echo "system /dev/sda2 none luks" >/mnt/etc/crypttab echo "system UUID=${CRYPT_UUID} none luks" >/mnt/etc/crypttab
# Rebuild initfs # Rebuild initfs
sed -i 's/lvm/lvm cryptsetup/' /mnt/etc/mkinitfs/mkinitfs.conf sed -i 's/lvm/lvm cryptsetup/' /mnt/etc/mkinitfs/mkinitfs.conf
mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt $(ls /mnt/lib/modules) mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt $(ls /mnt/lib/modules)
# Update extlinux (ignore the errors) # 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 chroot /mnt update-extlinux
sed -i 's/overwrite=1/overwrite=0/' /mnt/etc/update-extlinux.conf 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 # Install basic system
apk --no-cache add apache2-utils gettext apk --no-cache add apache2-utils gettext
wget https://repo.spotter.cz/vm.tar -O - | tar xf - -C /mnt 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 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 chroot /mnt newaliases
mkdir -p /mnt/var/log/lxc mkdir -p /mnt/var/log/lxc
for SERVICE in cgroups consolefont crond iptables networking nginx ntpd postfix swap urandom vmmgr; do 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 ln -s /etc/init.d/${SERVICE} /mnt/etc/runlevels/boot
done 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 # Cleanup
rm -rf /mnt/root rm -rf /mnt/root

View File

@ -6,4 +6,4 @@ DISPLAY vm.txt
LABEL vm LABEL vm
LINUX vmlinuz-virt LINUX vmlinuz-virt
INITRD initramfs-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

View File

@ -1,13 +1,19 @@
#!/bin/sh #!/bin/sh
set -e 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 # 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 [ ${BLOCKS_FREE} -lt 10240 ] && exit 0
# Resize physical partition # Resize physical partition
# Force busybox fdisk as util-linux fdisk breaks subsequent partx command # 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 d
2 2
n n
@ -22,7 +28,7 @@ w
EOF EOF
# Re-read partition table # Re-read partition table
/usr/sbin/partx -u /dev/sda2 /usr/sbin/partx -u ${PART}
# Resize dmcrypt and LVM PV # Resize dmcrypt and LVM PV
/sbin/cryptsetup resize system /sbin/cryptsetup resize system