maybe final one, idk

This commit is contained in:
Pratham Patel 2023-07-28 13:55:52 +05:30
parent e2796f245a
commit 4d2da9b8fd
No known key found for this signature in database
4 changed files with 56 additions and 50 deletions

View File

@ -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"

View File

@ -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

View File

@ -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

42
scripts/expand-rootfs.sh Normal file
View File

@ -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}"