kopia lustrzana https://github.com/cyoung/stratux
rodzic
7e0205be17
commit
f2c6c23c8e
|
@ -15,103 +15,3 @@ if [ -e /root/update*stratux*v*.sh ] ; then
|
|||
fi
|
||||
fi
|
||||
|
||||
|
||||
get_init_sys() {
|
||||
if command -v systemctl > /dev/null && systemctl | grep -q '\-\.mount'; then
|
||||
SYSTEMD=1
|
||||
elif [ -f /etc/init.d/cron ] && [ ! -h /etc/init.d/cron ]; then
|
||||
SYSTEMD=0
|
||||
else
|
||||
echo "Unrecognised init system" >>/tmp/err
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
do_expand_rootfs() {
|
||||
get_init_sys
|
||||
if [ $SYSTEMD -eq 1 ]; then
|
||||
ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p')
|
||||
else
|
||||
if ! [ -h /dev/root ]; then
|
||||
echo "/dev/root does not exist or is not a symlink. Don't know how to expand" >>/tmp/err
|
||||
return 0
|
||||
fi
|
||||
ROOT_PART=$(readlink /dev/root)
|
||||
fi
|
||||
|
||||
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" >>/tmp/err
|
||||
return 0
|
||||
fi
|
||||
|
||||
# NOTE: the NOOBS partition layout confuses parted. For now, let's only
|
||||
# agree to work with a sufficiently simple partition layout
|
||||
if [ "$PART_NUM" -ne 2 ]; then
|
||||
echo "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." >>/tmp/err
|
||||
return 0
|
||||
fi
|
||||
|
||||
LAST_PART_NUM=$(parted /dev/mmcblk0 -ms unit s p | tail -n 1 | cut -f 1 -d:)
|
||||
if [ $LAST_PART_NUM -ne $PART_NUM ]; then
|
||||
echo "$ROOT_PART is not the last partition. Don't know how to expand" >>/tmp/err
|
||||
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
|
||||
|
||||
# now set up an init.d script
|
||||
cat <<EOF > /etc/init.d/resize2fs_once &&
|
||||
#!/bin/sh
|
||||
### 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" &&
|
||||
resize2fs /dev/$ROOT_PART &&
|
||||
update-rc.d resize2fs_once remove &&
|
||||
rm /etc/init.d/resize2fs_once &&
|
||||
log_end_msg \$?
|
||||
;;
|
||||
*)
|
||||
echo "Usage: \$0 start" >&2
|
||||
exit 3
|
||||
;;
|
||||
esac
|
||||
EOF
|
||||
chmod +x /etc/init.d/resize2fs_once &&
|
||||
update-rc.d resize2fs_once defaults
|
||||
}
|
||||
|
||||
if [ ! -f /etc/stratux.firstboot ]; then
|
||||
echo "expanding filesystem (first boot)" >>/tmp/err
|
||||
do_expand_rootfs
|
||||
touch /etc/stratux.firstboot
|
||||
fi
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue