Set up the files to write to the image.

master
Tom Alexander 2 years ago
parent d5b80b6a03
commit 8df79dfc4f
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

@ -7,12 +7,27 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
############## Setup #########################
function cleanup {
for f in "${jails[@]}"; do
>&2 echo "Stopping jail $f"
sudo jail -r "$f"
done
for f in "${mountedfolders[@]}"; do
>&2 echo "Unmounting folder $f"
umount "$f"
done
for f in "${memorydevices[@]}"; do
>&2 echo "Removing memory device $f"
mdconfig -d -u "$f"
done
for f in "${folders[@]}"; do
>&2 echo "Deleting $f"
rm -rf "$f"
sudo rm -rf "$f"
done
}
folders=()
jails=()
memorydevices=()
mountedfolders=()
for sig in EXIT INT QUIT HUP TERM; do
trap "set +e; cleanup" "$sig"
done
@ -123,20 +138,6 @@ function precheck {
done
}
function make_chroot {
bsdtar -C "$chroot" -xpf "${download_directory}/${ALPINE_TARBALL}"
# Steal the DNS info from the host
(umask 022 && resolvconf -l > "${chroot}/etc/resolv.conf")
# Enter the jail
# install mkinitfs
sudo jail -c path="$chroot" ip4=inherit ip6=inherit host=inherit allow.raw_sockets=true command=/bin/sh
# Remove the resolv.conf file since it should get populated via dhcp
rm "${chroot}/etc/resolv.conf"
}
function download_alpine {
if [ "$LOCAL_DEV" == "true" ] && [ -e "${NETIZEN_CACHE}/${ALPINE_TARBALL}" ]; then
# Cache for local development to avoid stressing alpine servers
@ -156,6 +157,43 @@ function download_alpine {
gpg --no-default-keyring --keyring "$keyring" --trust-model always --verify <(cat <<<"$ALPINE_SIGNATURE") "${download_directory}/${ALPINE_TARBALL}"
}
function make_chroot {
bsdtar -C "$chroot" -xpf "${download_directory}/${ALPINE_TARBALL}"
# Steal the DNS info from the host
(umask 022 && resolvconf -l > "${chroot}/etc/resolv.conf")
# Enter the jail
# install mkinitfs
jid=$(sudo jail -c -i path="$chroot" ip4=inherit ip6=inherit host=inherit allow.raw_sockets=true persist)
jails+=("$jid")
sudo jexec "$jid" apk add --no-cache mkinitfs docker linux-virt
sudo jexec "$jid" apk add --no-cache --repository 'http://dl-cdn.alpinelinux.org/alpine/edge/testing' refind
sudo jexec "$jid" mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / 5.15.16-0-virt
sudo jexec "$jid" mkdir /boot/efi
sudo jexec "$jid" cp -r /usr/share/refind /boot/efi/boot
sudo jexec "$jid" cp /boot/efi/boot/refind_x64.efi /boot/efi/boot/bootx64.efi
(umask 022 && sudo tee "${chroot}/boot/refind_linux.conf" <<EOF
"Boot normal" "rw root=PARTLABEL=DIB console=ttyS0,115200"
EOF
)
# Open shell to look/experiment
# sudo jexec "$jid" /bin/sh
# Remove the resolv.conf file since it should get populated via dhcp
rm "${chroot}/etc/resolv.conf"
}
function make_image {
dd if=/dev/zero of="$image_file" bs=1 count=0 seek=10G
# image_device=$(mdconfig -a -t vnode -f "$image_file")
local image_device=$(mdconfig -f "$image_file")
memorydevices+=("$image_device")
# mountedfolders+=("$mount_directory")
}
function main {
precheck
@ -170,6 +208,15 @@ function main {
mkdir "$chroot"
log "Building chroot in $chroot"
make_chroot
image_directory="${work_directory}/images"
mount_directory="${work_directory}/mount"
mkdir "$image_directory" "$mount_directory"
image_file="$image_directory/dib.img"
make_image
log "Copying final image to $DIR"
cp "$image_file" "$DIR"
}
main

Loading…
Cancel
Save