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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions roles/1-prep/tasks/hardware.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
- name: Install package 'cloud-guest-utils' so growpart is available for expanding rootfs partition during boot
- name: Install packages 'parted' and 'cloud-guest-utils' (so /usr/bin/growpart is available for expanding rootfs partition during boot)
package:
name: cloud-guest-utils # 2022-03-15: For RasPiOS especially. Ubuntu has still pre-installed, for use with cloud-init.
name:
- parted # 2022-03-15: RasPiOS and Ubuntu install this regardless -- so rarely nec but just in case.
- cloud-guest-utils # 2022-03-15: For growpart command, on RasPiOS especially. Ubuntu has this 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?

- name: "Install from templates: /usr/sbin/iiab-expand-rootfs, /etc/systemd/system/iiab-expand-rootfs.service"
Expand Down
11 changes: 5 additions & 6 deletions roles/1-prep/templates/iiab-expand-rootfs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
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.)

echo "$0: Expanding rootfs partition"

if [ -x /usr/bin/raspi-config ]; then
# 2022-02-17: Works in many more situations, e.g. with USB disks (not
# just microSD cards). IF ONLY THIS ALSO WORKED ON Ubuntu/Mint/etc !

# Uses do_expand_rootfs() from:
if [ -x /usr/bin/raspi-config ]; then # Raspberry Pi OS
# 2022-02-17: Uses do_expand_rootfs() from:
# https://github.com/RPi-Distro/raspi-config/blob/master/raspi-config
raspi-config --expand-rootfs
else
else # Other Linux OS's
# 2022-03-15: Borrows from above raspi-config URL's do_expand_rootfs()
ROOT_PART="$(findmnt / -o SOURCE -n)" # e.g. /dev/sda2 or /dev/mmcblk0p2
ROOT_DEV="/dev/$(lsblk -no pkname "$ROOT_PART")" # e.g. /dev/sda or /dev/mmcblk0
Expand All @@ -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)

# # ASSUMES SD CARD STYLE PARTITION NAME LIKE <device>p<partition number>
# # e.g. /dev/mmcblk0p2 mounts at / (typical RasPiOS microSD)
# # BUT /dev/sda2 mounts at /media/usb1 (RasPiOS USB boot disk...
Expand Down