Skip to content

Instantly share code, notes, and snippets.

@MrAndrewMal
Forked from solaris9000/auto_fs_pi.txt
Created January 21, 2021 20:54
Show Gist options
  • Save MrAndrewMal/5094b068a7eb6e8633a0e9dc3bca37de to your computer and use it in GitHub Desktop.
Save MrAndrewMal/5094b068a7eb6e8633a0e9dc3bca37de to your computer and use it in GitHub Desktop.
How to set up auto filesystem expansion for custom PI images
How to set up auto filesystem expansion for custom PI images
============================================================
Preamble
========
When a custom pi image is created, it is a good idea to expand the FS so that all the space on the SD card is used. This is done manaully using the raspi-config tool or raspi-config --expand-rootfs.
The official pi images expand the FS automatically so it would be nice to replicate this process for custom images.
The procedure below shows how to do this.
Procedure
=========
1. Boot up the pi
2. log in
3. Append the following to the file /boot/cmdline.txt
quiet init=/usr/lib/raspi-config/init_resize.sh
Do not introduce line breaks to the line in cmdline.txt - this should remain as a single line.
4. Create the following script and save to /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"
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
------------------------------------------------
The lastest version of the script is found here:
https://github.com/RPi-Distro/pi-gen/blob/master/stage2/01-sys-tweaks/files/resize2fs_once
5. Change the permissions of the script
chmod +x /etc/init.d/resize2fs_once
6. Update the rc init links:
update-rc.d resize2fs_once defaults
7. The SD card is now ready to be cloned (after all customisations).
8. After cloning, the image is ready to be copied to the SD card using dd or dcfldd.
9. Boot up the new image. The FS should automatically expand to fill up all available space.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment