Add support for template with partition table on root.img
When TEMPLATE_ROOT_WITH_PARTITIONS is set, include (GPT) partition table and install actual OS on the first one. This allows installing grub, or other bootloader. Fixes QubesOS/qubes-issues#2577
This commit is contained in:
parent
a97fe13c1b
commit
9b2078d346
@ -1,30 +1,24 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
export IMG=$1
|
export INSTALLDIR=$1
|
||||||
|
|
||||||
. ./builder_setup
|
. ./builder_setup
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
if ! [ $# -eq 1 ]; then
|
if ! [ $# -eq 1 ]; then
|
||||||
echo "usage $0 <img_file_name>"
|
echo "usage $0 <mount_point>"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if ! [ -f $IMG ]; then
|
if ! [ -d $INSTALLDIR ]; then
|
||||||
echo $IMG does not exist
|
echo $INSTALLDIR does not exist
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
ls -als $IMG
|
|
||||||
mount -o loop $IMG mnt || exit 1
|
|
||||||
export INSTALLDIR=`pwd`/mnt/
|
|
||||||
|
|
||||||
echo "--> Cleaning up image file..."
|
echo "--> Cleaning up image file..."
|
||||||
$SCRIPTSDIR/09_cleanup.sh
|
$SCRIPTSDIR/09_cleanup.sh
|
||||||
|
|
||||||
echo "--> Compacting image file..."
|
echo "--> Compacting image file..."
|
||||||
fstrim mnt/
|
fstrim -v "$INSTALLDIR"
|
||||||
umount mnt
|
|
||||||
ls -als $IMG
|
|
||||||
|
|
||||||
|
@ -45,15 +45,41 @@ echo "-> Preparing instalation of ${DIST} template..."
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
if [ -f "${IMG}" ]; then
|
if [ -f "${IMG}" ]; then
|
||||||
echo "-> Image file already exists, assuming *update*..."
|
echo "-> Image file already exists, assuming *update*..."
|
||||||
|
if [ "0$TEMPLATE_ROOT_WITH_PARTITIONS" -eq 1 ]; then
|
||||||
|
IMG_LOOP=$(losetup -P -f --show "$IMG")
|
||||||
|
IMG_DEV=${IMG_LOOP}p1
|
||||||
|
else
|
||||||
|
IMG_LOOP=$(losetup -f --show "$IMG")
|
||||||
|
IMG_DEV=${IMG_LOOP}
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "-> Initializing empty image..."
|
echo "-> Initializing empty image..."
|
||||||
truncate -s 10G "${IMG}" || exit 1
|
truncate -s 10G "${IMG}" || exit 1
|
||||||
|
|
||||||
|
if [ "0$TEMPLATE_ROOT_WITH_PARTITIONS" -eq 1 ]; then
|
||||||
|
echo "-> Creating partition table"
|
||||||
|
# have static UUIDs to make partition table reproducible
|
||||||
|
sfdisk "$IMG" <<EOF || exit 1
|
||||||
|
label: gpt
|
||||||
|
label-id: f4796a2a-e377-45bd-b539-d6d49e569055
|
||||||
|
|
||||||
|
size=10000MiB, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=693244e6-3e07-47bf-ad79-acade4293fe7, name="Root filesystem"
|
||||||
|
size=200MiB, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=fa4d6529-56da-47c7-ae88-e2dfecb72621, name="EFI System"
|
||||||
|
size=2MiB, type=21686148-6449-6E6F-744E-656564454649, uuid=1e6c9db4-1e91-46c4-846a-2030dcb13b8c, name="BIOS boot partition"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
IMG_LOOP=$(losetup -P -f --show "$IMG")
|
||||||
|
IMG_DEV=${IMG_LOOP}p1
|
||||||
|
else
|
||||||
|
IMG_LOOP=$(losetup -f --show "$IMG")
|
||||||
|
IMG_DEV=${IMG_LOOP}
|
||||||
|
fi
|
||||||
|
|
||||||
echo "-> Creating filesystem..."
|
echo "-> Creating filesystem..."
|
||||||
mkfs.ext4 -q -F "${IMG}" || exit 1
|
mkfs.ext4 -q -F "${IMG_DEV}" || exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mount -o loop "${IMG}" "${INSTALLDIR}" || exit 1
|
mount "${IMG_DEV}" "${INSTALLDIR}" || exit 1
|
||||||
trap "umount_kill $(readlink -m ${INSTALLDIR})" EXIT
|
trap "umount_kill $(readlink -m ${INSTALLDIR})" EXIT
|
||||||
"${SCRIPTSDIR}/01_install_core.sh"
|
"${SCRIPTSDIR}/01_install_core.sh"
|
||||||
|
|
||||||
@ -70,5 +96,6 @@ trap - EXIT
|
|||||||
|
|
||||||
echo "-> Unmounting prepared_image..."
|
echo "-> Unmounting prepared_image..."
|
||||||
umount_kill "$(readlink -m ${INSTALLDIR})" || true
|
umount_kill "$(readlink -m ${INSTALLDIR})" || true
|
||||||
|
losetup -d ${IMG_LOOP}
|
||||||
|
|
||||||
exit ${RETCODE}
|
exit ${RETCODE}
|
||||||
|
@ -50,6 +50,7 @@ function cleanup() {
|
|||||||
trap - ERR
|
trap - ERR
|
||||||
trap
|
trap
|
||||||
umount_kill "$PWD/mnt" || true
|
umount_kill "$PWD/mnt" || true
|
||||||
|
losetup -d ${IMG_LOOP}
|
||||||
exit $errval
|
exit $errval
|
||||||
}
|
}
|
||||||
trap cleanup ERR
|
trap cleanup ERR
|
||||||
@ -65,7 +66,14 @@ cp "$CLEANIMG" "$IMG" || exit 1
|
|||||||
|
|
||||||
echo "--> Mounting $IMG"
|
echo "--> Mounting $IMG"
|
||||||
mkdir -p mnt
|
mkdir -p mnt
|
||||||
mount -o loop "$IMG" mnt || exit 1
|
if [ "0$TEMPLATE_ROOT_WITH_PARTITIONS" -eq 1 ]; then
|
||||||
|
IMG_LOOP=$(losetup -P -f --show "$IMG")
|
||||||
|
IMG_DEV=${IMG_LOOP}p1
|
||||||
|
else
|
||||||
|
IMG_LOOP=$(losetup -f --show "$IMG")
|
||||||
|
IMG_DEV=${IMG_LOOP}
|
||||||
|
fi
|
||||||
|
mount "$IMG_DEV" mnt || exit 1
|
||||||
export INSTALLDIR=mnt
|
export INSTALLDIR=mnt
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
@ -100,14 +108,18 @@ echo "--> Linking /usr/local to /rw/usrlocal..."
|
|||||||
mv mnt/usr/local mnt/usr/local.orig
|
mv mnt/usr/local mnt/usr/local.orig
|
||||||
ln -sf /rw/usrlocal mnt/usr/local
|
ln -sf /rw/usrlocal mnt/usr/local
|
||||||
|
|
||||||
|
echo "Reducing image size (calling cleanup_image)..."
|
||||||
|
ls -als $IMG
|
||||||
|
./cleanup_image "$INSTALLDIR"
|
||||||
|
ls -als $IMG
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Finsh - unmount image
|
# Finsh - unmount image
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
echo "--> Unmounting $IMG"
|
echo "--> Unmounting $IMG"
|
||||||
umount_kill "$PWD/mnt" || true
|
umount_kill "$PWD/mnt" || true
|
||||||
|
losetup -d ${IMG_LOOP}
|
||||||
|
|
||||||
echo "Qubeized image stored at: $IMG"
|
echo "Qubeized image stored at: $IMG"
|
||||||
|
|
||||||
echo "Reducing image size (calling cleanup_image)..."
|
|
||||||
./cleanup_image "$IMG"
|
|
||||||
chown -R --reference=. qubeized_images/$NAME
|
chown -R --reference=. qubeized_images/$NAME
|
||||||
|
Loading…
Reference in New Issue
Block a user