banan-os/script/image-create.sh

67 lines
1.5 KiB
Bash
Raw Normal View History

#!/bin/bash
2024-04-24 01:27:59 +03:00
if [ -z $BANAN_DISK_IMAGE_PATH ]; then
echo "You must set the BANAN_DISK_IMAGE_PATH environment variable" >&2
exit 1
fi
2024-04-24 01:27:59 +03:00
if [ -z $BANAN_SYSROOT ]; then
echo "You must set the BANAN_SYSROOT environment variable" >&2
exit 1
fi
2024-04-24 01:27:59 +03:00
if [ -z $BANAN_UEFI_BOOT ]; then
echo "You must set the BANAN_UEFI_BOOT environment variable" >&2
exit 1
fi
2024-04-24 01:27:59 +03:00
if [ -z $BANAN_BUILD_DIR ]; then
echo "You must set the BANAN_BUILD_DIR environment variable" >&2
exit 1
fi
2024-04-24 01:27:59 +03:00
set -u
2024-04-24 01:27:59 +03:00
# create mount directory
MOUNT_DIR="$BANAN_BUILD_DIR/mount"
mkdir -p $MOUNT_DIR
# create empty disk image
DISK_SIZE=$((500 * 1024 * 1024))
truncate -s 0 "$BANAN_DISK_IMAGE_PATH"
truncate -s $DISK_SIZE "$BANAN_DISK_IMAGE_PATH"
2024-04-24 01:27:59 +03:00
# create partition table
if (($BANAN_UEFI_BOOT)); then
2024-04-24 01:27:59 +03:00
parted --script "$BANAN_DISK_IMAGE_PATH" \
mklabel gpt \
mkpart boot 1M 17M \
set 1 esp on \
mkpart root ext2 17M 100%
else
2024-04-24 01:27:59 +03:00
parted --script "$BANAN_DISK_IMAGE_PATH" \
mklabel gpt \
mkpart boot 1M 2M \
set 1 bios_grub on \
mkpart root ext2 2M 100%
fi
2024-04-24 01:27:59 +03:00
# create loop device
LOOP_DEV=$(sudo losetup --show -fP "$BANAN_DISK_IMAGE_PATH" || exit 1 )
PARTITION1=${LOOP_DEV}p1
PARTITION2=${LOOP_DEV}p2
2024-04-24 01:27:59 +03:00
if [ ! -b $PARTITION1 ] || [ ! -b $PARTITION2 ]; then
echo "Failed to probe partitions for banan disk image." >&2
sudo losetup -d $LOOP_DEV
exit 1
fi
2023-03-19 05:51:25 +02:00
2024-04-24 01:27:59 +03:00
# create root filesystem
sudo mkfs.ext2 -q $PARTITION2
2024-04-24 01:27:59 +03:00
# delete loop device
sudo losetup -d $LOOP_DEV
2024-04-24 01:27:59 +03:00
# install bootloader
$BANAN_SCRIPT_DIR/install-bootloader.sh