Skip to content

Commit 302ec53

Browse files
committed
add do_expand_rootfs for ARM from raspi-config
1 parent 16fca22 commit 302ec53

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

scripts/_functions.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,79 @@ deb-src https://deb.torproject.org/torproject.org tor-nightly-master-$distro mai
373373
echo "# Installed $(tor --version)"
374374
fi
375375
}
376+
377+
# do_expand_rootfs
378+
function do_expand_rootfs() {
379+
# based on https://github.com/RPi-Distro/raspi-config/blob/d98686647ced7c0c0490dc123432834735d1c13d/raspi-config#L157
380+
ROOT_PART="$(findmnt / -o source -n)"
381+
ROOT_DEV="/dev/$(lsblk -no pkname "$ROOT_PART")"
382+
383+
PART_NUM="$(echo "$ROOT_PART" | grep -o "[[:digit:]]*$")"
384+
385+
# NOTE: the NOOBS partition layout confuses parted. For now, let's only
386+
# agree to work with a sufficiently simple partition layout
387+
if [ "$PART_NUM" -ne 2 ]; then
388+
whiptail --msgbox "Your partition layout is not currently supported by this tool. You are probably using NOOBS, in which case your root filesystem is already expanded anyway." 20 60 2
389+
return 0
390+
fi
391+
392+
LAST_PART_NUM=$(parted "$ROOT_DEV" -ms unit s p | tail -n 1 | cut -f 1 -d:)
393+
if [ $LAST_PART_NUM -ne $PART_NUM ]; then
394+
whiptail --msgbox "$ROOT_PART is not the last partition. Don't know how to expand" 20 60 2
395+
return 0
396+
fi
397+
398+
# Get the starting offset of the root partition
399+
PART_START=$(parted "$ROOT_DEV" -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d: | sed 's/[^0-9]//g')
400+
[ "$PART_START" ] || return 1
401+
# Return value will likely be error for fdisk as it fails to reload the
402+
# partition table because the root fs is mounted
403+
fdisk "$ROOT_DEV" <<EOF
404+
p
405+
d
406+
$PART_NUM
407+
n
408+
p
409+
$PART_NUM
410+
$PART_START
411+
412+
p
413+
w
414+
EOF
415+
ASK_TO_REBOOT=1
416+
417+
# now set up an init.d script
418+
cat <<EOF > /etc/init.d/resize2fs_once &&
419+
#!/bin/sh
420+
### BEGIN INIT INFO
421+
# Provides: resize2fs_once
422+
# Required-Start:
423+
# Required-Stop:
424+
# Default-Start: 3
425+
# Default-Stop:
426+
# Short-Description: Resize the root filesystem to fill partition
427+
# Description:
428+
### END INIT INFO
429+
430+
. /lib/lsb/init-functions
431+
432+
case "\$1" in
433+
start)
434+
log_daemon_msg "Starting resize2fs_once" &&
435+
resize2fs "$ROOT_PART" &&
436+
update-rc.d resize2fs_once remove &&
437+
rm /etc/init.d/resize2fs_once &&
438+
log_end_msg \$?
439+
;;
440+
*)
441+
echo "Usage: \$0 start" >&2
442+
exit 3
443+
;;
444+
esac
445+
EOF
446+
chmod +x /etc/init.d/resize2fs_once &&
447+
update-rc.d resize2fs_once defaults &&
448+
if [ "$INTERACTIVE" = True ]; then
449+
whiptail --msgbox "Root partition has been resized.\nThe filesystem will be enlarged upon the next reboot" 20 60 2
450+
fi
451+
}

scripts/start.joininbox.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ if [ "$setupStep" -lt 100 ];then
8383
if [ "$runningEnv" = "standalone" ];then
8484
# set ssh passwords on the first run
8585
sudo /home/joinmarket/set.password.sh || exit 1
86+
sed -i "s#setupStep=.*#setupStep=6#g" /home/joinmarket/joinin.conf
87+
# expand SDcard partition on ARM
88+
if [ ${cpu} != "x86_64" ]; then
89+
do_expand_rootfs
90+
sed -i "s#setupStep=.*#setupStep=7#g" /home/joinmarket/joinin.conf
91+
fi
8692
generateJMconfig
8793
sudo sed -i "s#setupStep=.*#setupStep=100#g" /home/joinmarket/joinin.conf
8894
/home/joinmarket/menu.config.sh

0 commit comments

Comments
 (0)