Browse Source

Provide systemd service for Raspberry Pi boards to resize data partition

As the partition table has been modified 'resize2fs_once' service
no longer fulfils its purpose.
That service has been replaced with 'resizefs' systemd service
which extends data partition's size and resizes filesystem too
to fill the whole free unallocated space.

Issues: MEN-2254

Changelog: Title

Signed-off-by: Adam Podogrocki <a.podogrocki@gmail.com>
1.1.x
Adam Podogrocki 6 years ago
parent
commit
197bf516d3
  1. 2
      files/init_resize.sh
  2. 13
      files/resizefs.service
  3. 42
      files/resizefs.sh
  4. 26
      rpi-convert-stage-5.sh

2
files/init_resize.sh

@ -75,7 +75,7 @@ main () {
reboot_pi
fi
if ! parted -m $ROOT_DEV u s resizepart $ROOT_PART_NUM $TARGET_END; then
if ! parted -m $ROOT_DEV u s resizepart $ROOT_PART_NUM $TARGET_END; then
FAIL_REASON="Data partition resize failed"
return 1
fi

13
files/resizefs.service

@ -0,0 +1,13 @@
[Unit]
Description=Expand data partition file system
After=mender.service
[Service]
Type=simple
User=root
Group=root
ExecStart=/bin/sh -c 'sleep 1 ; /usr/sbin/resizefs.sh start'
RemainAfterExit=true
[Install]
WantedBy=multi-user.target

42
files/resizefs.sh

@ -0,0 +1,42 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: resizefs
# Required-Start:
# Required-Stop:
# Default-Start: 3
# Default-Stop:
# Short-Description: Resize the data filesystem to fill partition
# Description:
### END INIT INFO
. /lib/lsb/init-functions
case "$1" in
start)
log_daemon_msg "Starting resizefs service (once)"
DISK=$(lsblk -f | sed -n '2{p;q}')
DISK_DEV="/dev/$DISK"
DISK_SIZE=$(blockdev --getsize $DISK_DEV)
DATA_PART_DEV=$(findmnt /data -o source -n)
DATA_PART=$(basename $DATA_PART_DEV)
DATA_PART_START=$(parted -m $DISK_DEV unit s print | tr -d 's' | tail -n 1 | cut -d ":" -f 2)
DATA_PART_SIZE=$(blockdev --getsize $DATA_PART_DEV)
FREE_SPACE=`expr $DISK_SIZE - $DATA_PART_START - $DATA_PART_SIZE`
if [ $FREE_SPACE -eq 0 ]; then
log_daemon_msg "Data partition already resized, aborting"
else
resize2fs $DATA_PART_DEV
FSSIZEMEG=`expr $FREE_SPACE + $DATA_PART_SIZE`
FSSIZEMEG=`expr $FSSIZEMEG / 2 / 1024`"M"
log_daemon_msg "Resizing $DATA_PART finished, new size is $FSSIZEMEG"
fi
systemctl --no-reload disable resizefs.service
log_end_msg $?
;;
*)
echo "Usage: $0 start" >&2
exit 3
;;
esac

26
rpi-convert-stage-5.sh

@ -107,11 +107,11 @@ install_files() {
sed -i 's/\b[ ]root=[^ ]*/ root=\${mender_kernel_root}/' ${output_dir}/cmdline.txt
# If the the image that we are trying to convert has been booted once on a
# device, it will have removed the init_resize.sh init argument from cmdline.
# Original Raspberry Pi image run once will have init_resize.sh script removed
# from the init argument from the cmdline.
#
# But we want it to run on our image as well to resize our data part so in
# case it is missing, add it back to cmdline.txt
# On the other hand in Mender image we want to retain a mechanism of last
# partition resizing. Check the cmdline.txt file and add it back if necessary.
if ! grep -q "init=/usr/lib/raspi-config/init_resize.sh" ${output_dir}/cmdline.txt; then
cmdline=$(cat ${output_dir}/cmdline.txt)
sh -c -e "echo '${cmdline} init=/usr/lib/raspi-config/init_resize.sh' > ${output_dir}/cmdline.txt";
@ -124,7 +124,7 @@ install_files() {
# might write an update while it is mounted which often result in
# corruptions.
#
# TODO: Find a way to only blacklist mmcblk0pX devices instea of masking
# TODO: Find a way to only blacklist mmcblk0pX devices instead of masking
# the service.
sudo ln -sf /dev/null ${rootfs_dir}/etc/systemd/system/udisks2.service
@ -154,10 +154,24 @@ install_files() {
sudo install -m 755 ${bin_dir_pi}/fw_printenv ${rootfs_dir}/sbin/fw_printenv
sudo ln -fs /sbin/fw_printenv ${rootfs_dir}/sbin/fw_setenv
# Override init script to expand the data part instead of rootfs, which it
# Override init script to expand the data partition instead of rootfs, which it
# normally expands in standard Raspberry Pi distributions.
sudo install -m 755 ${files_dir}/init_resize.sh \
${rootfs_dir}/usr/lib/raspi-config/init_resize.sh
# As the whole process must be conducted in two steps, i.e. resize partition
# during first boot and resize the partition's file system on system's first
# start-up add systemd service file and script.
sudo install -m 644 ${files_dir}/resizefs.service \
${rootfs_dir}/lib/systemd/system/resizefs.service
sudo ln -sf /lib/systemd/system/resizefs.service \
${rootfs_dir}/etc/systemd/system/multi-user.target.wants/resizefs.service
sudo install -m 755 ${files_dir}/resizefs.sh \
${rootfs_dir}/usr/sbin/resizefs.sh
# Remove original 'resize2fs_once' script and its symbolic link.
sudo unlink ${rootfs_dir}/etc/rc3.d/S01resize2fs_once
sudo rm ${rootfs_dir}/etc/init.d/resize2fs_once
}
do_install_bootloader() {

Loading…
Cancel
Save