Skip to content

Instantly share code, notes, and snippets.

@cuu
Last active Jul 20, 2019
Embed
What would you like to do?
expand_rootfs for gameshell
#!/bin/sh
### BEGIN INIT INFO
# Provides: expand_rootfs
# Required-Start:
# Required-Stop:
# Default-Start: 3
# Default-Stop:
# Short-Description: Expand the root filesystem to fill partition
# Description:
### END INIT INFO
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
# 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
log_daemon_msg "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."
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
log_daemon_msg "$ROOT_PART is not the last partition. 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
# 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: 2 3 4 5 S
# 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 &&
systemctl enable resize2fs_once
rm -rf /etc/init.d/expand_rootfs
}
. /lib/lsb/init-functions
case "$1" in
start)
log_daemon_msg "Starting expand rootfs" &&
do_expand_rootfs &&
/sbin/reboot
;;
*)
echo "Usage: $0 start" >&2
exit 3
;;
esac
@cuu
Copy link
Author

cuu commented Feb 11, 2019

ubuntu

cd /etc/init.d
sudo wget 
https://gist.githubusercontent.com/cuu/b11109f2197cd482fe8d2c61b8d409c6/raw/672971991633283eaf8cdc0263a99472371b508d/expand_rootfs

sudo chmod +x expand_rootfs
sudo systemctl enable expand_rootfs
sudo reboot

debian

sudo apt-get -y install parted

cd /etc/init.d
sudo wget 
https://gist.githubusercontent.com/cuu/b11109f2197cd482fe8d2c61b8d409c6/raw/672971991633283eaf8cdc0263a99472371b508d/expand_rootfs

sudo chmod +x expand_rootfs
sudo systemctl enable expand_rootfs
sudo reboot

@cuu
Copy link
Author

cuu commented Jul 20, 2019

Patch to clockworkpios img

fdisk -l $IMAGE
# calculate the offset in bytes
mount -o loop,offset=$OFFSET $IMAGE $MOUNTPOINT
sudo mount  -o loop,offset=48234496  clockworkos_v0.4.img /media/sdb2/

cd /media/sdb2/etc/init.d
/media/sdb2/etc/init.d$ sudo wget 
https://gist.githubusercontent.com/cuu/b11109f2197cd482fe8d2c61b8d409c6/raw/672971991633283eaf8cdc0263a99472371b508d/expand_rootfs
/media/sdb2/etc/init.d$ sudo chmod +x expand_rootfs 
/media/sdb2/etc/init.d$ cd ..
/media/sdb2/etc$ cd rc3.d/
/media/sdb2/etc/rc3.d$ sudo ln -s ../init.d/expand_rootfs S01expand_rootfs
/media/sdb2/etc/rc3.d$ cd && sudo umount /media/sdb2

now dd it into sdcard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment