diff --git a/generate/src/entrypoint.sh b/generate/src/entrypoint.sh index 95238521a..16f760aec 100644 --- a/generate/src/entrypoint.sh +++ b/generate/src/entrypoint.sh @@ -2,6 +2,8 @@ set -e +LOOPBACK_DEVICE=$(losetup -f) + function size() { du -sm ./ | cut -f1 } @@ -27,13 +29,13 @@ function raw() { parted -s -a optimal /dianemo.raw mkpart ESP fat32 0 50M parted -s -a optimal /dianemo.raw mkpart ROOT xfs 50M $(($(size) + 100))M parted -s -a optimal /dianemo.raw mkpart DATA xfs $(($(size) + 100))M 100% - losetup /dev/loop0 /dianemo.raw - partx -av /dev/loop0 - sgdisk /dev/loop0 --attributes=1:set:2 - mkfs.vfat /dev/loop0p1 - mkfs.xfs -n ftype=1 -L ROOT /dev/loop0p2 - mkfs.xfs -n ftype=1 -L DATA /dev/loop0p3 - mount /dev/loop0p1 /mnt + losetup ${LOOPBACK_DEVICE} /dianemo.raw + partx -av ${LOOPBACK_DEVICE} + sgdisk ${LOOPBACK_DEVICE} --attributes=1:set:2 + mkfs.vfat ${LOOPBACK_DEVICE}p1 + mkfs.xfs -n ftype=1 -L ROOT ${LOOPBACK_DEVICE}p2 + mkfs.xfs -n ftype=1 -L DATA ${LOOPBACK_DEVICE}p3 + mount ${LOOPBACK_DEVICE}p1 /mnt mkdir -p /mnt/boot/extlinux extlinux --install /mnt/boot/extlinux cat </mnt/boot/extlinux/extlinux.conf @@ -46,14 +48,14 @@ LABEL Dianemo EOF cp -v /rootfs/boot/* /mnt/boot umount /mnt - mount /dev/loop0p2 /mnt + mount ${LOOPBACK_DEVICE}p2 /mnt cp -Rv ./* /mnt rm -rf /mnt/boot rm -rf /mnt/var/* umount /mnt - mount /dev/loop0p3 /mnt + mount ${LOOPBACK_DEVICE}p3 /mnt cp -Rv ./var/* /mnt - dd if=/usr/local/src/syslinux/efi64/mbr/gptmbr.bin of=/dev/loop0 + dd if=/usr/local/src/syslinux/efi64/mbr/gptmbr.bin of=${LOOPBACK_DEVICE} cleanup cp -v /dianemo.raw /out qemu-img convert -f raw -O vmdk /out/dianemo.raw /out/dianemo.vmdk @@ -64,16 +66,16 @@ function rootfs() { parted -s /rootfs.raw mklabel gpt parted -s -a optimal /rootfs.raw mkpart ROOT xfs 0 $(($(size) + 50))M parted -s -a optimal /rootfs.raw mkpart DATA xfs $(($(size) + 50))M 100% - losetup /dev/loop0 /rootfs.raw - partx -av /dev/loop0 - mkfs.xfs -n ftype=1 -L ROOT /dev/loop0p1 - mkfs.xfs -n ftype=1 -L DATA /dev/loop0p2 - mount /dev/loop0p1 /mnt + losetup ${LOOPBACK_DEVICE} /rootfs.raw + partx -av ${LOOPBACK_DEVICE} + mkfs.xfs -n ftype=1 -L ROOT ${LOOPBACK_DEVICE}p1 + mkfs.xfs -n ftype=1 -L DATA ${LOOPBACK_DEVICE}p2 + mount ${LOOPBACK_DEVICE}p1 /mnt cp -Rv ./* /mnt rm -rf /mnt/boot rm -rf /mnt/var/* umount /mnt - mount /dev/loop0p2 /mnt + mount ${LOOPBACK_DEVICE}p2 /mnt cp -Rv ./var/* /mnt cleanup cp -v ./boot/vmlinuz /out @@ -83,8 +85,8 @@ function rootfs() { function cleanup { umount /mnt || true - partx -dv /dev/loop0 || true - losetup -d /dev/loop0 || true + partx -dv ${LOOPBACK_DEVICE} || true + losetup -d ${LOOPBACK_DEVICE} || true } trap cleanup EXIT