Require root and build inside image instead of separate chroot.
This commit is contained in:
parent
e57607b3be
commit
3b131ed462
@ -9,19 +9,19 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
function cleanup {
|
||||
for f in "${jails[@]}"; do
|
||||
>&2 echo "Stopping jail $f"
|
||||
sudo jail -r "$f"
|
||||
jail -r "$f"
|
||||
done
|
||||
for (( idx=${#mountedfolders[@]}-1 ; idx>=0 ; idx-- )) ; do
|
||||
>&2 echo "Unmounting folder ${mountedfolders[idx]}"
|
||||
sudo umount "${mountedfolders[idx]}"
|
||||
umount "${mountedfolders[idx]}"
|
||||
done
|
||||
for f in "${memorydevices[@]}"; do
|
||||
>&2 echo "Removing memory device $f"
|
||||
sudo mdconfig -d -u "$f"
|
||||
mdconfig -d -u "$f"
|
||||
done
|
||||
for f in "${folders[@]}"; do
|
||||
>&2 echo "Deleting $f"
|
||||
# sudo rm -rf "$f"
|
||||
# rm -rf "$f"
|
||||
done
|
||||
}
|
||||
folders=()
|
||||
@ -127,6 +127,10 @@ Mkc=
|
||||
|
||||
function precheck {
|
||||
# Checks to run before building the image
|
||||
if [ $(id -u) -ne 0 ]; then
|
||||
die 1 "Must run as root."
|
||||
fi
|
||||
|
||||
if ! grep -q 'linux.ko' <<<"$(kldstat)"; then
|
||||
die 1 "Need linux kernel module for building initramfs."
|
||||
fi
|
||||
@ -165,21 +169,21 @@ function make_chroot {
|
||||
|
||||
# Enter the jail
|
||||
# install mkinitfs
|
||||
jid=$(sudo jail -c -i path="$chroot" ip4=inherit ip6=inherit host=inherit allow.raw_sockets=true persist)
|
||||
jid=$(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
|
||||
jexec "$jid" apk add --no-cache mkinitfs docker linux-virt
|
||||
jexec "$jid" apk add --no-cache --repository 'http://dl-cdn.alpinelinux.org/alpine/edge/testing' refind
|
||||
jexec "$jid" mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / 5.15.16-0-virt
|
||||
jexec "$jid" mkdir /boot/efi
|
||||
jexec "$jid" cp -r /usr/share/refind /boot/efi/boot
|
||||
jexec "$jid" cp /boot/efi/boot/refind_x64.efi /boot/efi/boot/bootx64.efi
|
||||
(umask 022 && 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
|
||||
# jexec "$jid" /bin/sh
|
||||
|
||||
# Remove the resolv.conf file since it should get populated via dhcp
|
||||
rm "${chroot}/etc/resolv.conf"
|
||||
@ -188,31 +192,25 @@ EOF
|
||||
function make_image {
|
||||
dd if=/dev/zero of="$image_file" bs=1 count=0 seek=10G
|
||||
local image_device
|
||||
# image_device=$(sudo mdconfig -a -t vnode -f "$image_file")
|
||||
image_device=$(sudo mdconfig -f "$image_file")
|
||||
# image_device=$(mdconfig -a -t vnode -f "$image_file")
|
||||
image_device=$(mdconfig -f "$image_file")
|
||||
memorydevices+=("$image_device")
|
||||
|
||||
efi_partition="${image_device}p1"
|
||||
data_partition="${image_device}p2"
|
||||
|
||||
sudo gpart create -s gpt "$image_device"
|
||||
sudo gpart add -t efi -l efi -a4k -s492k "$image_device"
|
||||
sudo newfs_msdos "${efi_partition}"
|
||||
sudo gpart add -t linux-data -l DIB -a4k "$image_device"
|
||||
sudo mkfs.ext4 "/dev/${data_partition}"
|
||||
gpart create -s gpt "$image_device"
|
||||
gpart add -t efi -l efi -a4k -s492k "$image_device"
|
||||
newfs_msdos "${efi_partition}"
|
||||
gpart add -t linux-data -l DIB -a4k "$image_device"
|
||||
mkfs.ext4 "/dev/${data_partition}"
|
||||
|
||||
sudo mount -t ext2fs "/dev/${data_partition}" "${mount_directory}"
|
||||
mount -t ext2fs "/dev/${data_partition}" "${mount_directory}"
|
||||
mountedfolders+=("$mount_directory")
|
||||
boot_directory="${mount_directory}/boot"
|
||||
sudo mkdir -p "$boot_directory"
|
||||
sudo mount_msdosfs "/dev/${efi_partition}" "${boot_directory}"
|
||||
mkdir -p "$boot_directory"
|
||||
mount_msdosfs "/dev/${efi_partition}" "${boot_directory}"
|
||||
mountedfolders+=("$boot_directory")
|
||||
|
||||
sudo cp -pr "${chroot}/*" "${mount_directory}/"
|
||||
|
||||
|
||||
# mount -t ext2fs /dev/ada1s1 /mnt
|
||||
# mountedfolders+=("$mount_directory")
|
||||
}
|
||||
|
||||
function main {
|
||||
@ -225,17 +223,17 @@ function main {
|
||||
mkdir "$download_directory"
|
||||
download_alpine
|
||||
|
||||
chroot="${work_directory}/chroot"
|
||||
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
|
||||
|
||||
chroot="${mount_directory}"
|
||||
# mkdir "$chroot"
|
||||
log "Building chroot in $chroot"
|
||||
make_chroot
|
||||
|
||||
log "Copying final image to $DIR"
|
||||
cp "$image_file" "$DIR"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user