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
|
#!/bin/bash
|
||||||
|
|
||||||
version="v0.1.2"
|
version="v0.1.3"
|
||||||
|
|
||||||
CURRENT_DIR=$(pwd)
|
CURRENT_DIR=$(pwd)
|
||||||
SCRIPTNAME="${0##*/}"
|
SCRIPTNAME="${0##*/}"
|
||||||
|
@ -175,72 +175,36 @@ if [ "$should_skip_autoexpand" = false ]; then
|
||||||
#Make pi expand rootfs on next boot
|
#Make pi expand rootfs on next boot
|
||||||
mountdir=$(mktemp -d)
|
mountdir=$(mktemp -d)
|
||||||
mount "$loopback" "$mountdir"
|
mount "$loopback" "$mountdir"
|
||||||
|
#From https://raw.githubusercontent.com/RPi-Distro/pi-gen/master/stage2/01-sys-tweaks/files/resize2fs_once
|
||||||
if [ "$(md5sum "$mountdir/etc/rc.local" | cut -d ' ' -f 1)" != "0542054e9ff2d2e0507ea1ffe7d4fc87" ]; then
|
cat <<\EOF > "$mountdir/etc/init.d/resize2fs_once"
|
||||||
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 &&
|
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
echo "Expanding /dev/$ROOT_PART"
|
### BEGIN INIT INFO
|
||||||
resize2fs /dev/$ROOT_PART
|
# Provides: resize2fs_once
|
||||||
rm -f /etc/rc.local; cp -f /etc/rc.local.bak /etc/rc.local; /etc/rc.local
|
# 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
|
EOF
|
||||||
reboot
|
chmod +x "$mountdir/etc/init.d/resize2fs_once"
|
||||||
exit
|
ln -s "$mountdir/etc/init.d/resize2fs_once" "$mountdir/etc/rc3.d/resize2fs_once"
|
||||||
}
|
|
||||||
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
|
|
||||||
umount "$mountdir"
|
umount "$mountdir"
|
||||||
else
|
else
|
||||||
echo "Skipping autoexpanding process..."
|
echo "Skipping autoexpanding process..."
|
||||||
|
|
Loading…
Reference in New Issue