From 4d2da9b8fd884077aa8b7d4edfbb4a333cf9783f Mon Sep 17 00:00:00 2001 From: Pratham Patel Date: Fri, 28 Jul 2023 13:55:52 +0530 Subject: [PATCH] maybe final one, idk --- create-image.sh | 2 +- includes/bootloader-stuff.ksi | 16 ++++++------ includes/post-install.ksi | 46 ++++------------------------------- scripts/expand-rootfs.sh | 42 ++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 50 deletions(-) create mode 100644 scripts/expand-rootfs.sh diff --git a/create-image.sh b/create-image.sh index 8020cec..2659b24 100755 --- a/create-image.sh +++ b/create-image.sh @@ -29,7 +29,7 @@ if [[ -f "${APPLIANCE_NAME}-sda.raw" ]]; then COMPRESSED_IMAGE_NAME="${IMAGE_NAME}.zst" touch "${APPLIANCE_NAME}-sda.raw" - mv "${APPLIANCE_NAME}-sda.raw" "${IMAGE_NAME}" + mv -v "${APPLIANCE_NAME}-sda.raw" "${IMAGE_NAME}" zstd -9 -z "${IMAGE_NAME}" sha256sum "${IMAGE_NAME}" > "${IMAGE_NAME}.sha256" diff --git a/includes/bootloader-stuff.ksi b/includes/bootloader-stuff.ksi index a76f000..c1f88e7 100644 --- a/includes/bootloader-stuff.ksi +++ b/includes/bootloader-stuff.ksi @@ -2,8 +2,8 @@ # U-Boot binaries for 32-bit and 64-bit Raspberry Pi models # (these are loaded by /boot/efi/config.txt) -cp -f /usr/share/uboot/rpi_3/u-boot.bin /boot/efi/rpi3-u-boot.bin -cp -f /usr/share/uboot/rpi_4/u-boot.bin /boot/efi/rpi4-u-boot.bin +cp -v -f /usr/share/uboot/rpi_3/u-boot.bin /boot/efi/rpi3-u-boot.bin +cp -v -f /usr/share/uboot/rpi_4/u-boot.bin /boot/efi/rpi4-u-boot.bin # Remove the 'dracut-config-generic' package if found installed dnf list installed | grep 'dracut-config-generic' > /dev/null && \ @@ -16,7 +16,7 @@ fi # remove '/boot/dtb' because the kernel should use '/boot/dtb' if [ -d /boot/dtb ]; then - rm -rf /boot/dtb + rm -r -v -f /boot/dtb fi # Kernel selection at boot @@ -32,15 +32,15 @@ UPDATEDEFAULT=yes # The 'DEFAULTKERNEL' options specifies what package type will be used as the default DEFAULTKERNEL=kernel-core EOF -chmod 644 /etc/sysconfig/kernel +chmod --verbose 644 /etc/sysconfig/kernel # GRUB setup if [ -d /boot/efi/EFI/rocky ] && [ -f /boot/efi/EFI/rocky/grubaa64.efi ]; then - mv -f /boot/grub2/grub.cfg /boot/efi/EFI/rocky/grub.cfg + mv -v -f /boot/grub2/grub.cfg /boot/efi/EFI/rocky/grub.cfg ln -s ../efi/EFI/rocky/grub.cfg /boot/grub2/grub.cfg - [ -d /boot/efi/EFI/BOOT ] || mkdir -p /boot/efi/EFI/BOOT - cp -f /boot/efi/EFI/rocky/grubaa64.efi /boot/efi/EFI/BOOT/BOOTAA64.EFI + [ -d /boot/efi/EFI/BOOT ] || mkdir --verbose --parent /boot/efi/EFI/BOOT + cp -v -f /boot/efi/EFI/rocky/grubaa64.efi /boot/efi/EFI/BOOT/BOOTAA64.EFI fi # Write GRUB defaults @@ -55,6 +55,6 @@ GRUB_DISABLE_RECOVERY="true" GRUB_DISABLE_OS_PROBER="true" GRUB_ENABLE_BLSCFG="false" EOF -chmod 644 /etc/default/grub +chmod --verbose 644 /etc/default/grub %end diff --git a/includes/post-install.ksi b/includes/post-install.ksi index a5c2978..a2a12a5 100644 --- a/includes/post-install.ksi +++ b/includes/post-install.ksi @@ -3,54 +3,18 @@ %post # The script that expands root partition -mkdir -v /usr/local/bin -cat << EOF > /usr/local/bin/expand-rootfs.sh -#!/usr/bin/env bash - -ROOT_DEVICE=$(mount | grep '/ ' | awk '{print $1}') # "/dev/sda3" -DISK_NAME="/dev/$(lsblk -ls "${ROOT_DEVICE}" | tail -n 1 | awk '{print $1}')" # "/dev/sda" -CUT_LENGTH=$(( ${#DISK_NAME} + 1 )) # how much to cut from "/dev/sda3" to get "3" -if [[ "${DISK_NAME}" =~ "nvme" || "${DISK_NAME}" =~ "mmcblk" ]]; then - # Add an extra character to cut since NVMe and MMC-block devices - # have a partition number _after_ a 'p' - CUT_LENGTH=$(( CUT_LENGTH + 1 )) -fi -PARTITION_NUMBER=$(echo "${ROOT_DEVICE}" | cut -c "${CUT_LENGTH}-") # get "3" from "/dev/sda3" - -if [[ -z "${ROOT_DEVICE}" || -z "${DISK_NAME}" || -z "${CUT_LENGTH}" || -z "${PARTITION_NUMBER}" ]]; then - >&2 echo "$0: error: unable to detect root device" - exit 1 -fi - -if ! command -v growpart > /dev/null; then - >&2 echo "$0: error: unable to find command 'growpart'" - exit 1 -fi - -if ! command -v resize2fs > /dev/null; then - >&2 echo "$0: error: unable to find command 'resize2fs'" - exit 1 -fi - -if [[ ${EUID} -ne 0 || ${UID} -ne 0 ]]; then - >&2 echo "$0: error: please run this script as root" - exit 1 -fi - -set -x -growpart "${DISK_NAME}" "${PARTITION_NUMBER}" -resize2fs "${ROOT_DEVICE}" -EOF -chmod +x /usr/local/bin/expand-rootfs.sh +[ -d /usr/local/bin ] || mkdir --verbose /usr/local/bin +curl 'https://git.resf.org/thefossguy/rocky-linux-generic-images/raw/branch/r9/scripts/expand-rootfs.sh' --output /usr/local/bin/expand-rootfs.sh +chmod --verbose +x /usr/local/bin/expand-rootfs.sh # Rebuild the RPM database rpm --rebuilddb # Remove 'ifcfg-link' on generated images -rm -f /etc/sysconfig/network-scripts/ifcfg-link +rm -v -f /etc/sysconfig/network-scripts/ifcfg-link # The 'machine-id' needs to be unique for each machine so remove ours to prevent duplication -rm -f /etc/machine-id +rm -v -f /etc/machine-id touch /etc/machine-id %end diff --git a/scripts/expand-rootfs.sh b/scripts/expand-rootfs.sh new file mode 100644 index 0000000..9975703 --- /dev/null +++ b/scripts/expand-rootfs.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +ROOT_DEVICE=$(mount | grep '/ ' | awk '{print $1}') # "/dev/sda3" +DISK_NAME="/dev/$(lsblk -ls "${ROOT_DEVICE}" | tail -n 1 | awk '{print $1}')" # "/dev/sda" +CUT_LENGTH=$(( ${#DISK_NAME} + 1 )) # how much to cut from "/dev/sda3" to get "3" +if [[ "${DISK_NAME}" =~ "nvme" || "${DISK_NAME}" =~ "mmcblk" ]]; then + # Add an extra character to cut since NVMe and MMC-block devices + # have a partition number _after_ a 'p' + CUT_LENGTH=$(( CUT_LENGTH + 1 )) +fi +PARTITION_NUMBER=$(echo "${ROOT_DEVICE}" | cut -c "${CUT_LENGTH}-") # get "3" from "/dev/sda3" + +if [[ -z "${ROOT_DEVICE}" || -z "${DISK_NAME}" || -z "${CUT_LENGTH}" || -z "${PARTITION_NUMBER}" ]]; then + >&2 echo "$0: error: unable to detect root device" + exit 1 +fi + +if ! command -v growpart > /dev/null; then + >&2 echo "$0: error: unable to find command 'growpart'" + exit 1 +fi + +if ! command -v resize2fs > /dev/null; then + >&2 echo "$0: error: unable to find command 'resize2fs'" + exit 1 +fi + +if ! command -v e2fsck > /dev/null; then + >&2 echo "$0: error: unable to find command 'e2fsck'" + exit 1 +fi + +if [[ ${EUID} -ne 0 || ${UID} -ne 0 ]]; then + >&2 echo "$0: error: please run this script as root" + exit 1 +fi + +set -x +growpart --verbose "${DISK_NAME}" "${PARTITION_NUMBER}" +e2fsck -D -f -F -p -v -y "${ROOT_DEVICE}" +resize2fs -f -F -p "${ROOT_DEVICE}" +e2fsck -D -f -F -p -v -y "${ROOT_DEVICE}"