-
Notifications
You must be signed in to change notification settings - Fork 76
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
Changes from 4 commits
3542798
334c708
cc9a55f
ee765e4
baab781
85eb059
fc032ef
a9fe590
f32b9ce
212d1fa
9924767
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,38 @@ | ||
- name: Install package 'cloud-guest-utils' so 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. | ||
state: present | ||
|
||
- name: "Install from templates: /usr/sbin/iiab-expand-rootfs, /etc/systemd/system/iiab-expand-rootfs.service" | ||
template: | ||
src: "{{ item.src }}" | ||
dest: "{{ item.dest }}" | ||
mode: "{{ item.mode }}" | ||
with_items: | ||
- { src: 'iiab-expand-rootfs', dest: '/usr/sbin/', mode: '0755' } | ||
- { src: 'iiab-expand-rootfs.service', dest: '/etc/systemd/system/', mode: '0644' } | ||
|
||
- name: Enable /etc/systemd/system/iiab-expand-rootfs.service | ||
systemd: | ||
name: iiab-expand-rootfs | ||
enabled: yes | ||
|
||
|
||
## DISCOVER PLATFORMS ###### | ||
# Put conditional actions for hardware platforms here | ||
|
||
- include_tasks: raspberry_pi.yml | ||
when: first_run and rpi_model != "none" | ||
|
||
|
||
- name: Check if the identifier for Intel's NUC6 built-in WiFi is present | ||
shell: "lsusb | grep 8087:0a2b | wc | awk '{print $1}'" | ||
register: usb_NUC6 | ||
ignore_errors: True | ||
|
||
- name: Download {{ iiab_download_url }}/iwlwifi-8000C-13.ucode to /lib/firmware for built-in WiFi on NUC6 # iiab_download_url is http://download.iiab.io/packages | ||
- name: Download {{ iiab_download_url }}/iwlwifi-8000C-13.ucode to /lib/firmware for built-in WiFi on NUC6 | ||
get_url: | ||
url: "{{ iiab_download_url }}/iwlwifi-8000C-13.ucode" | ||
url: "{{ iiab_download_url }}/iwlwifi-8000C-13.ucode" # http://download.iiab.io/packages | ||
dest: /lib/firmware | ||
timeout: "{{ download_timeout }}" | ||
when: usb_NUC6.stdout|int > 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/bin/bash -x | ||
|
||
# Expand rootfs partition to its maximum size, if /.expand-rootfs exists. | ||
# Used by /etc/systemd/system/iiab-expand-rootfs.service on IIAB boot. | ||
|
||
# Should work with most Linux OS's, regardless whether Raspberry Pi SD cards | ||
# or external USB boot disks, etc. Verifies that rootfs is the last partition. | ||
|
||
if [ -f /.expand-rootfs ] || [ -f /.resize-rootfs ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've implemented consistent (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: | ||
# https://github.com/RPi-Distro/raspi-config/blob/master/raspi-config | ||
raspi-config --expand-rootfs | ||
else | ||
# 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 | ||
|
||
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:) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should really add 'parted' as a dependency, same as cloud-guest-utils There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done: 85eb059 |
||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would exit 1 be better here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. I borrowed |
||
fi | ||
|
||
# Expand partition | ||
growpart $ROOT_DEV $ROOT_PART_NUM | ||
resize2fs $ROOT_PART | ||
|
||
# # 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... | ||
# # ...WON'T WORK BELOW; recap @ PR #3121) | ||
|
||
# # Calculate root partition | ||
# root_part=`lsblk -aP -o NAME,MOUNTPOINT | grep 'MOUNTPOINT="/"' | awk -F\" '{ print $2 }'` # e.g. mmcblk0p2 | ||
# root_dev=${root_part:0:-2} # e.g. mmcblk0 | ||
# # bash substring expansion: "negative offset [below, but not above] | ||
# # must be separated from the colon by at least one space to avoid | ||
# # being confused with the ‘:-’ expansion" | ||
# # https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html | ||
# root_part_no=${root_part: -1} # e.g. 2 | ||
|
||
# # Resize partition | ||
# growpart /dev/$root_dev $root_part_no | ||
# resize2fs /dev/$root_part | ||
fi | ||
|
||
rm -f /.expand-rootfs /.resize-rootfs | ||
fi |
This file was deleted.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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: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?