diff --git a/roles/1-prep/README.adoc b/roles/1-prep/README.adoc index cdbd75142..fca0f26a6 100644 --- a/roles/1-prep/README.adoc +++ b/roles/1-prep/README.adoc @@ -14,16 +14,15 @@ username and group, to log into Admin Console * Ubermix (distro) needs /etc/tmpfiles.d/iiab.conf to create essential /var/log subdirs on each boot * *_Hardware actions:_* + ** Install package cloud-guest-utils for growpart + ** Install link:templates/iiab-expand-rootfs[iiab-expand-rootfs] that acts on flag `/.expand-rootfs` at boot ** link:tasks/raspberry_pi.yml[*_raspberry_pi.yml_*]: *** RTC (real-time clock): install udev rule, configure, enable - *** *_Install packages related to:_* - **** growpart - **** swapfile + *** *_Install packages:_* + **** dphys-swapfile (for swapfile) **** fake-hwclock (as RTC is often missing or dead!) - **** Wi-Fi - *** Increase swap file size - *** https://github.com/iiab/iiab/blob/master/roles/1-prep/templates/iiab-rpi-max-rootfs.sh[rootfs - auto-resizing] + **** iw, rfkill, wireless-tools (for internal Wi-Fi) + *** Increase swap file size (to `pi_swap_file_size`) ** NUC 6 Wi-Fi firmware Recap: Similar to 0-init, 2-common, 3-base-server, 4 server-options and diff --git a/roles/1-prep/tasks/hardware.yml b/roles/1-prep/tasks/hardware.yml index 7b3f6fa5a..c397223e2 100644 --- a/roles/1-prep/tasks/hardware.yml +++ b/roles/1-prep/tasks/hardware.yml @@ -1,3 +1,25 @@ +- name: Install packages 'parted' and 'cloud-guest-utils' (so /usr/bin/growpart is available for expanding rootfs partition during boot) + package: + 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 -- though RasPiOS currently doesn't need this, as raspi-config's do_expand_rootfs() instead uses fdisk. Ubuntu pre-installs cloud-guest-utils, 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 @@ -20,14 +42,15 @@ - 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 diff --git a/roles/1-prep/tasks/raspberry_pi.yml b/roles/1-prep/tasks/raspberry_pi.yml index 745ce60b9..90a312521 100644 --- a/roles/1-prep/tasks/raspberry_pi.yml +++ b/roles/1-prep/tasks/raspberry_pi.yml @@ -38,15 +38,18 @@ - name: '2021-07-27: SEE ALSO 4-5 networking packages LATER installed by https://github.com/iiab/iiab/blob/master/roles/2-common/tasks/network.yml' meta: noop -- name: 'Install packages: cloud-guest-utils, dphys-swapfile, fake-hwclock' +# 2022-03-15: This section is effectively now useless on RasPiOS (but apparently +# serves a purpose on Ubuntu on RPi, where it installs dphys-swapfile and +# fake-hwclock). Still: @jvonau's above explanation of other OS's / other HW +# suggest this code should possibly move in future, to helps others too? + +- name: 'Install packages: dphys-swapfile, fake-hwclock' package: name: - - cloud-guest-utils # Contains 'growpart' for resizing a partition during boot, which is normally done with the aid of cloud-init - - dphys-swapfile # 2021-07-27: RaspiOS installs this regardless -- autogenerate and use a swap file - - fake-hwclock # 2021-07-27: RaspiOS installs this regardless -- save/restore system clock on machines without working RTC hardware + - dphys-swapfile # 2021-03-15: For Ubuntu on RPi? RasPiOS installs this regardless -- autogenerate and use a swap file + - fake-hwclock # 2021-03-15: For Ubuntu on RPi? RasPiOS installs this regardless -- save/restore system clock on machines without working RTC hardware state: present - - name: Increase swap file size (to CONF_SWAPSIZE={{ pi_swap_file_size }} in /etc/dphys-swapfile) as kalite pip download fails lineinfile: path: /etc/dphys-swapfile @@ -58,20 +61,3 @@ systemd: # Had been...a rare/legacy service that was NOT systemd name: dphys-swapfile state: restarted - - -- name: Install RPi rootfs resizing (/usr/sbin/iiab-rpi-max-rootfs.sh) and its systemd service (/etc/systemd/system/iiab-rpi-root-resize.service), from templates (root:root by default) - template: - src: "{{ item.src }}" - dest: "{{ item.dest }}" - #owner: root - #group: root - mode: "{{ item.mode }}" - with_items: - - { src: 'iiab-rpi-max-rootfs.sh', dest: '/usr/sbin/', mode: '0755' } - - { src: 'iiab-rpi-root-resize.service', dest: '/etc/systemd/system/', mode: '0644' } - -- name: Enable RPi rootfs resizing (systemd service iiab-rpi-root-resize.service) - systemd: - name: iiab-rpi-root-resize - enabled: yes diff --git a/roles/1-prep/templates/iiab-expand-rootfs b/roles/1-prep/templates/iiab-expand-rootfs new file mode 100644 index 000000000..bc81bd302 --- /dev/null +++ b/roles/1-prep/templates/iiab-expand-rootfs @@ -0,0 +1,59 @@ +#!/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 all Linux OS's boot disks -- regardless whether Raspberry Pi +# microSD cards, external USB drives, internal spinning disks or SSD's, etc. + +# Verifies that rootfs is the last partition. + +if [ -f /.expand-rootfs ] || [ -f /.resize-rootfs ]; then + echo "$0: Expanding rootfs partition" + + 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 # 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 + + 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:) + + 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." + exit 1 + fi + + # Expand partition + growpart $ROOT_DEV $ROOT_PART_NUM # raspi-config instead uses fdisk + resize2fs $ROOT_PART + + # 2022-03-15: Legacy code below worked with Raspberry Pi microSD cards + # but *not* with USB boot drives, internal spinning disks/SSD's, etc. + + # # ASSUMES SD CARD STYLE PARTITION NAME LIKE p + # # 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 diff --git a/roles/1-prep/templates/iiab-rpi-root-resize.service b/roles/1-prep/templates/iiab-expand-rootfs.service similarity index 61% rename from roles/1-prep/templates/iiab-rpi-root-resize.service rename to roles/1-prep/templates/iiab-expand-rootfs.service index 2cd33ec11..4ac36fa42 100644 --- a/roles/1-prep/templates/iiab-rpi-root-resize.service +++ b/roles/1-prep/templates/iiab-expand-rootfs.service @@ -1,10 +1,10 @@ [Unit] -Description=Root Filesystem Auto-Resizer +Description=Root Filesystem Auto-Expander [Service] Environment=TERM=linux Type=oneshot -ExecStart=/usr/sbin/iiab-rpi-max-rootfs.sh +ExecStart=/usr/sbin/iiab-expand-rootfs StandardError=syslog RemainAfterExit=no diff --git a/roles/1-prep/templates/iiab-rpi-max-rootfs.sh b/roles/1-prep/templates/iiab-rpi-max-rootfs.sh deleted file mode 100644 index 8405727b4..000000000 --- a/roles/1-prep/templates/iiab-rpi-max-rootfs.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash -x - -# Resize rootfs and its partition on the RPi SD card (or external USB -# disk if possible, e.g. with Raspberry Pi OS) to maximum size. - -# To be used by /etc/systemd/system/iiab-rpi-root-resize.service on boot. -# Only resizes if /.resize-rootfs exists. -# Assumes root is last partition. - -if [ -f /.resize-rootfs ]; then - echo "$0: maximizing rootfs partion" - - 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 - # ASSUMES SD CARD STYLE PARTITION NAME LIKE p - # 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 /.resize-rootfs -fi