Replaced rc.local modification with resize2fs_once init script
This commit is contained in:
parent
4f61a3244a
commit
4250d9a258
94
pishrink.sh
94
pishrink.sh
|
@ -1,6 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
version="v0.1.2"
|
||||
version="v0.1.3"
|
||||
|
||||
CURRENT_DIR=$(pwd)
|
||||
SCRIPTNAME="${0##*/}"
|
||||
|
@ -175,72 +175,36 @@ if [ "$should_skip_autoexpand" = false ]; then
|
|||
#Make pi expand rootfs on next boot
|
||||
mountdir=$(mktemp -d)
|
||||
mount "$loopback" "$mountdir"
|
||||
|
||||
if [ "$(md5sum "$mountdir/etc/rc.local" | cut -d ' ' -f 1)" != "0542054e9ff2d2e0507ea1ffe7d4fc87" ]; then
|
||||
echo "Creating new /etc/rc.local"
|
||||
mv "$mountdir/etc/rc.local" "$mountdir/etc/rc.local.bak"
|
||||
#####Do not touch the following lines#####
|
||||
cat <<\EOF1 > "$mountdir/etc/rc.local"
|
||||
#!/bin/bash
|
||||
do_expand_rootfs() {
|
||||
ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p')
|
||||
|
||||
PART_NUM=${ROOT_PART#mmcblk0p}
|
||||
if [ "$PART_NUM" = "$ROOT_PART" ]; then
|
||||
echo "$ROOT_PART is not an SD card. Don't know how to expand"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Get the starting offset of the root partition
|
||||
PART_START=$(parted /dev/mmcblk0 -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d: | sed 's/[^0-9]//g')
|
||||
[ "$PART_START" ] || return 1
|
||||
# Return value will likely be error for fdisk as it fails to reload the
|
||||
# partition table because the root fs is mounted
|
||||
fdisk /dev/mmcblk0 <<EOF
|
||||
p
|
||||
d
|
||||
$PART_NUM
|
||||
n
|
||||
p
|
||||
$PART_NUM
|
||||
$PART_START
|
||||
|
||||
p
|
||||
w
|
||||
EOF
|
||||
|
||||
cat <<EOF > /etc/rc.local &&
|
||||
#From https://raw.githubusercontent.com/RPi-Distro/pi-gen/master/stage2/01-sys-tweaks/files/resize2fs_once
|
||||
cat <<\EOF > "$mountdir/etc/init.d/resize2fs_once"
|
||||
#!/bin/sh
|
||||
echo "Expanding /dev/$ROOT_PART"
|
||||
resize2fs /dev/$ROOT_PART
|
||||
rm -f /etc/rc.local; cp -f /etc/rc.local.bak /etc/rc.local; /etc/rc.local
|
||||
|
||||
### BEGIN INIT INFO
|
||||
# Provides: resize2fs_once
|
||||
# Required-Start:
|
||||
# Required-Stop:
|
||||
# Default-Start: 3
|
||||
# Default-Stop:
|
||||
# Short-Description: Resize the root filesystem to fill partition
|
||||
# Description:
|
||||
### END INIT INFO
|
||||
. /lib/lsb/init-functions
|
||||
case "$1" in
|
||||
start)
|
||||
log_daemon_msg "Starting resize2fs_once"
|
||||
ROOT_DEV=$(findmnt / -o source -n) &&
|
||||
resize2fs $ROOT_DEV &&
|
||||
update-rc.d resize2fs_once remove &&
|
||||
rm /etc/init.d/resize2fs_once &&
|
||||
log_end_msg $?
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 start" >&2
|
||||
exit 3
|
||||
;;
|
||||
esac
|
||||
EOF
|
||||
reboot
|
||||
exit
|
||||
}
|
||||
raspi_config_expand() {
|
||||
/usr/bin/env raspi-config --expand-rootfs
|
||||
if [[ $? != 0 ]]; then
|
||||
return -1
|
||||
else
|
||||
rm -f /etc/rc.local; cp -f /etc/rc.local.bak /etc/rc.local; /etc/rc.local
|
||||
reboot
|
||||
exit
|
||||
fi
|
||||
}
|
||||
raspi_config_expand
|
||||
echo "WARNING: Using backup expand..."
|
||||
sleep 5
|
||||
do_expand_rootfs
|
||||
echo "ERROR: Expanding failed..."
|
||||
sleep 5
|
||||
rm -f /etc/rc.local; cp -f /etc/rc.local.bak /etc/rc.local; /etc/rc.local
|
||||
exit 0
|
||||
EOF1
|
||||
#####End no touch zone#####
|
||||
chmod +x "$mountdir/etc/rc.local"
|
||||
fi
|
||||
chmod +x "$mountdir/etc/init.d/resize2fs_once"
|
||||
ln -s "$mountdir/etc/init.d/resize2fs_once" "$mountdir/etc/rc3.d/resize2fs_once"
|
||||
umount "$mountdir"
|
||||
else
|
||||
echo "Skipping autoexpanding process..."
|
||||
|
|
Loading…
Reference in New Issue