62 lines
1.4 KiB
Plaintext
62 lines
1.4 KiB
Plaintext
|
#!/usr/bin/env bash
|
||
|
export DISK_IMAGE="$OPUS_OUTPUT/${OPUS_NAME}-${OPUS_DIST}-${OPUS_ARCH}_$(date "+%Y.%m.%d-%H.%M.%S").img"
|
||
|
export ROOT_MOUNT="$OPUS_OUTPUT/mount"
|
||
|
|
||
|
# Get the approximate size required for the image
|
||
|
export DISK_SIZE=$(du -sb "$1" | cut -f1)
|
||
|
# Add 256MB for SWAP, and 700MB for overhead
|
||
|
export DISK_SIZE=$(( $DISK_SIZE + ( 256 * 1000000 ) + ( 700 * 1000000 ) ))
|
||
|
# Add size of additional files
|
||
|
export DISK_SIZE=$(( $DISK_SIZE + $(du -sb "$OPUS_HOME/input/root-image" | cut -f1) ))
|
||
|
|
||
|
# Create and mount disk
|
||
|
fallocate -l $DISK_SIZE "$DISK_IMAGE"
|
||
|
export DISK_LOOP="$(losetup --show -f -P "$DISK_IMAGE")"
|
||
|
|
||
|
# Partition disk
|
||
|
(
|
||
|
echo n
|
||
|
echo e
|
||
|
echo
|
||
|
echo
|
||
|
echo +256M
|
||
|
echo t
|
||
|
echo swap
|
||
|
echo n
|
||
|
echo p
|
||
|
echo
|
||
|
echo
|
||
|
echo
|
||
|
echo t
|
||
|
echo
|
||
|
echo linux
|
||
|
echo w
|
||
|
echo
|
||
|
echo
|
||
|
) | fdisk "$DISK_LOOP"
|
||
|
|
||
|
# Format partions
|
||
|
mkswap "${DISK_LOOP}p1"
|
||
|
mkfs.ext4 "${DISK_LOOP}p2"
|
||
|
|
||
|
# Mount root
|
||
|
mkdir "$ROOT_MOUNT"
|
||
|
mount "${DISK_LOOP}p2" "$ROOT_MOUNT"
|
||
|
|
||
|
# Add files
|
||
|
dupe "$1/." "$ROOT_MOUNT"
|
||
|
|
||
|
# Make fstab
|
||
|
echo "UUID=$(blkid -o value -s UUID "${DISK_LOOP}p1") none swap sw 0 0" >"$ROOT_MOUNT/etc/fstab"
|
||
|
echo "UUID=$(blkid -o value -s UUID "${DISK_LOOP}p2") / ext4 errors=remount-ro 0 1" >>"$ROOT_MOUNT/etc/fstab"
|
||
|
|
||
|
# Set up GRUB and misc
|
||
|
fchroot "$ROOT_MOUNT" "/setupdisk"
|
||
|
|
||
|
# Clear logs
|
||
|
find "$ROOT_MOUNT/var/log" -type f -delete
|
||
|
|
||
|
# Unmount root
|
||
|
umount -l "$ROOT_MOUNT"
|
||
|
rmdir "$ROOT_MOUNT"
|
||
|
losetup -d "$DISK_LOOP"
|