alpine-overlay/kubezero/zdt-base/boot.sh

53 lines
1.3 KiB
Bash

#!/bin/sh
# We have no metadata nor instance parameters yet!
# We built on top of tiny-cloud
. /lib/tiny-cloud/common
# archive orig /var, mount new var on top and restore orig var
copy_and_mount() {
local dev=$1
tar cf /tmp/var.tar /var 2>/dev/null
mount -t xfs -o noatime "$dev" /var
tar xf /tmp/var.tar -C / && rm -f /tmp/var.tar
}
setup_var() {
local _devices="$(find /dev/xvd[a-z] /dev/sd[a-z] -maxdepth 0 2>/dev/null || true)"
for d in $_devices; do
# resolve to a valid block device
dev="$(realpath "$d")"
[ -b "$dev" ] || continue
# already mounted
mount | grep -q "$d" && continue
case "$CLOUD" in
aws)
# on AWS look for sdx/xvdx
if [ "$d" = "/dev/sdx" -o "$d" = "/dev/xvdx" ]; then
# check volume for existing filesystem
type=$(file -Lbs $d)
if [[ "$type" =~ "XFS filesystem" ]]; then
xfs_repair $d >/dev/null 2>&1
mount -t xfs -o noatime "$d" /var
else
mkfs.xfs -qf $d >/dev/null
copy_and_mount "$d"
fi
add_once /etc/fstab "$d /var xfs defaults,noatime,nofail 0 2"
log -i -t early info "mounted $d at /var"
fi
;;
*)
ewarn "Unsupported cloud: $CLOUD"
return 1
;;
esac
done
}