Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iiab-expand-rootfs for more HW/OS's w/ safety checks, per raspi-config's do_expand_rootfs() #3137

Merged
merged 11 commits into from
Mar 15, 2022

Conversation

holta
Copy link
Member

@holta holta commented Mar 15, 2022

Building off @jvonau's excellent suggestion at:

Several safety checks are also added, e.g. multi-digit partition numbers, and verification that the rootfs partition is indeed the last partition, etc. In the end, most improvements were borrowed (almost verbatim) from raspi-config's well-tested do_expand_rootds() here: https://github.com/RPi-Distro/raspi-config/blob/master/raspi-config

In summary, this modernizes:

  • 1-prep/templates/iiab-expand-rootfs originally iiab-rpi-max-rootfs.sh
  • 1-prep/templates/iiab-expand-rootfs.service originally iiab-rpi-root-resize.service

Allowing for use on other OS's (e.g. Ubuntu/Mint/Debian) with other HW (e.g. external boot disks, not just Raspberry Pi microSD cards).

Requirements are re-organized a bit, given this is no longer just for Raspberry Pi, and docs are clarified e.g. to explain flag /.expand-rootfs which matches the new name, in keeping with Raspberry Pi norms.

Related:

@holta holta added this to the 8.0 milestone Mar 15, 2022

if [ $ROOT_PART_NUM -ne $LAST_PART_NUM ]; then
echo "ERROR: $ROOT_PART partition ($ROOT_PART_NUM) is not the last partition ($LAST_PART_NUM). Don't know how to expand."
return 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would exit 1 be better here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

I borrowed return 0 from https://github.com/RPi-Distro/raspi-config/blob/684fbe183a53f60cccee21c341d5754357cf1288/raspi-config#L170 but exit 1 is a useful fix and improvement I'll add now.


ROOT_PART_NUM="$(echo "$ROOT_PART" | grep -o "[[:digit:]]*$")" # e.g. 2
# SLOW (~10 seconds) but it works!
LAST_PART_NUM=$(parted "$ROOT_DEV" -ms unit s p | tail -n 1 | cut -f 1 -d:)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should really add 'parted' as a dependency, same as cloud-guest-utils

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: 85eb059

package:
name: cloud-guest-utils # 2022-03-15: For RasPiOS especially. Ubuntu has still pre-installed, for use with cloud-init.
state: present

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are using raspi-config on RaspOS why install universally unless the use of raspi-config is going to go away?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Installing cloud-guest-utils is indeed currently overkill on RasPiOS.

/usr/bin/growpart is only 22 kB however, and the total package size is also tiny:

root@box:~# apt show cloud-guest-utils | grep Size

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Installed-Size: 62.5 kB
Download-Size: 23.7 kB
root@box:~# dpkg-query -L cloud-guest-utils
/.
/usr
/usr/bin
/usr/bin/ec2metadata
/usr/bin/growpart
/usr/bin/vcs-run
/usr/share
/usr/share/doc
/usr/share/doc/cloud-guest-utils
/usr/share/doc/cloud-guest-utils/NEWS.Debian.gz
/usr/share/doc/cloud-guest-utils/changelog.Debian.gz
/usr/share/doc/cloud-guest-utils/changelog.gz
/usr/share/doc/cloud-guest-utils/copyright
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/growpart.1.gz

Currently I'm inclined to continue installing it for all OS's, in case such infra utilities later help others.

But if others feel otherwise (e.g. if growpart proves to be unmaintained and/or causing problems?) then we could later try to remove it completely?

@@ -34,6 +31,8 @@ if [ -f /.expand-rootfs ] || [ -f /.resize-rootfs ]; then
growpart $ROOT_DEV $ROOT_PART_NUM
resize2fs $ROOT_PART

# 2022-03-15: Legacy code below for microSD cards but NOT USB boot disks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of /dev/sda is not just a 'usb' boot disk but any boot device that uses sdX naming, this should work nicely with 'normal' spinning disks also. (think older sata drives)


# Verifies that rootfs is the last partition.

if [ -f /.expand-rootfs ] || [ -f /.resize-rootfs ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why there would be a need to introduce another flag to act upon, all the tools in iiab-factory know nothing about the new 'expand-rootfs' flag.

Copy link
Member Author

@holta holta Mar 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've implemented consistent /.expand-rootfs naming across the board in both repos, per raspi-config norms:

(Legacy flag name /.resize-rootfs will still work during the interim.)

@holta
Copy link
Member Author

holta commented Mar 15, 2022

Tested with Ubuntu Server 21.10 on Raspberry Pi 4.

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

Successfully merging this pull request may close these issues.

2 participants