diff --git a/Makefile b/Makefile index 272d261..8926e95 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ mambadir := ${datadir}/openmamba polkitdir := ${datadir}/polkit-1/actions dbussystemdir := ${sysconfdir}/dbus-1/system.d localesdir := ${datadir}/locale +libexecdir := /usr/libexec DESTDIR := INSTALL := /usr/bin/install @@ -52,12 +53,14 @@ install-dirs: @$(INSTALL_DIR) $(DESTDIR)$(mambadir)/usbinstall/img @$(INSTALL_DIR) $(DESTDIR)$(polkitdir) @$(INSTALL_DIR) $(DESTDIR)$(dbussystemdir) + @$(INSTALL_DIR) $(DESTDIR)$(libexecdir) install: install-dirs install-locales $(INSTALL_PROGRAM) src/usbinstall.py $(DESTDIR)$(mambadir)/usbinstall/usbinstall.py $(INSTALL_SCRIPT) src/usbinstall.sh $(DESTDIR)$(sbindir)/usbinstall $(INSTALL_SCRIPT) src/rootfsinstall.sh $(DESTDIR)$(sbindir)/rootfsinstall $(INSTALL_SCRIPT) src/mmcinstall.sh $(DESTDIR)$(sbindir)/mmcinstall + $(INSTALL_SCRIPT) src/init_resize.sh $(DESTDIR)$(libexecdir)/init_resize $(INSTALL_DATA) src/img/*.png $(DESTDIR)$(mambadir)/usbinstall/img/ $(INSTALL_DATA) src/org.openmamba.usbinstall.policy $(DESTDIR)$(polkitdir)/org.openmamba.usbinstall.policy $(INSTALL_DATA) src/org.openmamba.usbinstall.conf $(DESTDIR)$(dbussystemdir)/org.openmamba.usbinstall.conf diff --git a/src/init_resize.sh b/src/init_resize.sh new file mode 100755 index 0000000..dd6a57b --- /dev/null +++ b/src/init_resize.sh @@ -0,0 +1,164 @@ +#!/bin/sh +# +# openmamba - automatically grow root partition at first boot +# Based on raspi-config init_resize.sh script +# +reboot_pi () { + umount /boot + mount / -o remount,ro + sync + echo b > /proc/sysrq-trigger + sleep 5 + exit 0 +} + +check_commands () { + for COMMAND in grep cut sed parted fdisk findmnt resize2fs; do + if ! command -v $COMMAND > /dev/null; then + FAIL_REASON="$COMMAND not found" + return 1 + fi + done + return 0 +} + +get_variables () { + ROOT_PART_DEV=$(findmnt / -o source -n) + ROOT_PART_NAME=$(echo "$ROOT_PART_DEV" | cut -d "/" -f 3) + ROOT_DEV_NAME=$(echo /sys/block/*/"${ROOT_PART_NAME}" | cut -d "/" -f 4) + ROOT_DEV="/dev/${ROOT_DEV_NAME}" + ROOT_PART_NUM=$(cat "/sys/block/${ROOT_DEV_NAME}/${ROOT_PART_NAME}/partition") + + BOOT_PART_DEV=$(findmnt /boot -o source -n) + BOOT_PART_NAME=$(echo "$BOOT_PART_DEV" | cut -d "/" -f 3) + BOOT_DEV_NAME=$(echo /sys/block/*/"${BOOT_PART_NAME}" | cut -d "/" -f 4) + BOOT_PART_NUM=$(cat "/sys/block/${BOOT_DEV_NAME}/${BOOT_PART_NAME}/partition") + + OLD_DISKID=$(fdisk -l "$ROOT_DEV" | sed -n 's/Disk identifier: 0x\([^ ]*\)/\1/p') + + ROOT_DEV_SIZE=$(cat "/sys/block/${ROOT_DEV_NAME}/size") + TARGET_END=$((ROOT_DEV_SIZE - 1)) + + PARTITION_TABLE=$(parted -m "$ROOT_DEV" unit s print | tr -d 's') + + LAST_PART_NUM=$(echo "$PARTITION_TABLE" | tail -n 1 | cut -d ":" -f 1) + + ROOT_PART_LINE=$(echo "$PARTITION_TABLE" | grep -e "^${ROOT_PART_NUM}:") + ROOT_PART_START=$(echo "$ROOT_PART_LINE" | cut -d ":" -f 2) + ROOT_PART_END=$(echo "$ROOT_PART_LINE" | cut -d ":" -f 3) +} + +fix_partuuid() { + mount -o remount,rw "$ROOT_PART_DEV" + mount -o remount,rw "$BOOT_PART_DEV" + DISKID="$(tr -dc 'a-f0-9' < /dev/hwrng | dd bs=1 count=8 2>/dev/null)" + fdisk "$ROOT_DEV" > /dev/null < /proc/sys/kernel/sysrq + +if ! check_commands; then + reboot_pi +fi + +if main; then + echo "Resized root filesystem. Rebooting in 5 seconds..." +else + echo "Could not expand filesystem.\n${FAIL_REASON}" +fi +sleep 5 + +reboot_pi diff --git a/src/rootfsinstall.sh b/src/rootfsinstall.sh index 69ab58a..49b9b61 100755 --- a/src/rootfsinstall.sh +++ b/src/rootfsinstall.sh @@ -195,6 +195,7 @@ case $TARGETDEVICE in chipone_ts grub-efi rtl8723bs_bt rtl8723bs axpd acpi_tables_patch $INSTALLPACKAGES" REMOVEPACKAGES="" FSTAB_ROOT_DEVICE="/dev/sda2" + FSTAB_BOOT_DEVICE="/dev/mmcblk0p1" ;; bpi) ARCH=arm BOOTFSTYPE=fat32 @@ -205,32 +206,22 @@ case $TARGETDEVICE in INSTALLPACKAGES="kernel-sunxi kernel-sunxi-modules u-boot-sunxi-Bananapi $INSTALLPACKAGES" REMOVEPACKAGES="kernel-mamba-arm" FSTAB_ROOT_DEVICE="/dev/mmcblk0p2" + FSTAB_BOOT_DEVICE="/dev/mmcblk0p1" ;; rpi) ARCH=arm BOOTFSTYPE=fat32 BOOTFSSIZE=100M BOOTFSSTART=0 - [ "$USEKERNEL" ] || USEKERNEL="zImage-*-rpi" - [ "$USEKERNEL2" ] || USEKERNEL2="zImage-*-rpi-v7" - [ "$USEKERNEL3" ] || USEKERNEL3="zImage-*-rpi-v7l" KERNELDEST="@BOOT@/kernel.img" KERNELDEST2="@BOOT@/kernel7.img" KERNELDEST3="@BOOT@/kernel7l.img" INSTALLPACKAGES="kernel-rpi kernel-rpi-modules raspberrypi-firmware \ kernel-rpi-v7 kernel-rpi-v7-modules \ kernel-rpi-v7l kernel-rpi-v7l-modules \ -raspberrypi-utils raspi-config $INSTALLPACKAGES" +raspberrypi-utils xf86-video-fbturbo $INSTALLPACKAGES" REMOVEPACKAGES="kernel-mamba-arm" - RPI_FIRMWARE_FILES="bootcode.bin \ -fixup_x.dat start_x.elf \ -fixup4x.dat start4x.elf \ -bcm2708-rpi-b-plus.dtb bcm2708-rpi-b.dtb bcm2708-rpi-cm.dtb \ -bcm2708-rpi-zero-w.dtb bcm2708-rpi-zero.dtb \ -bcm2709-rpi-2-b.dtb bcm2710-rpi-2-b.dtb \ -bcm2710-rpi-3-b-plus.dtb bcm2710-rpi-3-b.dtb \ -bcm2710-rpi-cm3.dtb bcm2711-rpi-4-b.dtb \ -cmdline.txt config.txt" FSTAB_ROOT_DEVICE="/dev/mmcblk0p2" + FSTAB_BOOT_DEVICE="/dev/mmcblk0p1" ;; cubox) ARCH=arm BOOTFSTYPE=ext3 @@ -354,7 +345,6 @@ if [ "${GROWIMAGE}" ]; then resize2fs ${PARTITION2} fi -[ "$BOOTFSTYPE" ] && BOOTMP=`mktemp -d -t rootfsinstall.XXXXXXXX` ROOTMP=`mktemp -d -t rootfsinstall.XXXXXXXX` [ -d $ROOTMP ] || { @@ -369,6 +359,8 @@ mount $PARTITION2 $ROOTMP || { trap "[ "$ROOTMP" -a -e $ROOTMP ] && umount $ROOTMP/dev/pts $ROOTMP/dev $ROOTMP/proc $ROOTMP/sys $ROOTMP/run $ROOTMP && rmdir $ROOTMP;[ "$BOOTMP" -a -e $BOOTMP ] && umount $BOOTMP && rmdir $BOOTMP" 0 HUP INT QUIT ABRT KILL TERM if [ "$BOOTFSTYPE" ]; then + BOOTMP=$ROOTMP/boot + mkdir $BOOTMP mount $PARTITION1 $BOOTMP || { echo "ERROR: unable to mount partition $PARTITION1; aborting." exit 1 @@ -554,22 +546,12 @@ _EOF dd if=$ROOTMP/boot/Bananapi/u-boot-sunxi-with-spl.bin of=${DRIVE} bs=1024 seek=8 : elif [ "$TARGETDEVICE" = "rpi" ]; then - # fetch and install firmware files if missing - for f in $RPI_FIRMWARE_FILES; do - if [ -e $ROOTMP/boot/$f ]; then - cp $ROOTMP/boot/$f $BOOTMP/$f - elif [ "$f" != "cmdline.txt" -a "$f" != "config.txt" ]; then - echo "ERROR: firmware file $f for rpi is missing in /boot directory; aborting." - exit 1 - fi - done - if [ -e $ROOTMP/boot/overlays ]; then - cp -a $ROOTMP/boot/overlays $BOOTMP/ - fi -# IMAGE=`ls $ROOTMP/boot/$USEKERNEL | head -n 1` - cp $ROOTMP/boot/$USEKERNEL $KERNELDEST - cp $ROOTMP/boot/$USEKERNEL2 $KERNELDEST2 - cp $ROOTMP/boot/$USEKERNEL3 $KERNELDEST3 + [ "$USEKERNEL" -a -e $KERNELDEST ] || cp $ROOTMP/boot/$USEKERNEL $KERNELDEST + [ "$USEKERNEL2" -a -e $KERNELDEST2 ] || cp $ROOTMP/boot/$USEKERNEL2 $KERNELDEST2 + [ "$USEKERNEL3" -a -e $KERNELDEST3 ] || cp $ROOTMP/boot/$USEKERNEL3 $KERNELDEST3 + + [ -e /usr/libexec/init_resize ] && cp /usr/libexec/init_resize ${ROOTMP}/usr/libexec/ + [ -e ${ROOTMP}/usr/libexec/init_resize ] && CMDLINE_ADD=" init=/usr/libexec/init_resize" # cmdline.txt : parameters passed to the kernel on boot [ ! -e $ROOTMP/boot/cmdline.txt ] && \ @@ -579,7 +561,8 @@ root=/dev/mmcblk0p2 \ rootfstype=$SYSTEMFSTYPE \ quiet \ rootwait \ -splash" > $BOOTMP/cmdline.txt +splash\ +$CMDLINE_ADD" > $BOOTMP/cmdline.txt # Create the kernel configuration file [ ! -e $ROOTMP/boot/config.txt ] && \ @@ -640,6 +623,12 @@ $FSTAB_ROOT_DEVICE / auto defaults 0 0 _EOF fi +if [ "$FSTAB_BOOT_DEVICE" ]; then + cat >> $ROOTMP/etc/fstab << _EOF +$FSTAB_BOOT_DEVICE / auto defaults 0 2 +_EOF +fi + if [ "$USEKERNEL" ]; then if [ -r $ROOTMP/boot/$USEKERNEL ]; then cp $ROOTMP/boot/$USEKERNEL $KERNELDEST || {