[Merge] ~waveform/livecd-rootfs:fix-swapfile into livecd-rootfs:ubuntu/master
Ćukasz Zemczak
mp+415625 at code.launchpad.net
Mon Feb 21 21:29:58 UTC 2022
This seems okay. I usually don't like bundling fixes together as it breaks visibility of the issue we want to fix, but here it's fine. Left a small question inline below.
As for the service ordering you mentioned in the bug, I think it should be fine as it is. Looking for some details on this I found https://github.com/systemd/systemd/issues/15025 which seems to point that indeed expansion of the rootfs will happen always before local-fs.target.
Diff comments:
> diff --git a/live-build/ubuntu/hooks/099-ubuntu-image-customization.chroot b/live-build/ubuntu/hooks/099-ubuntu-image-customization.chroot
> index 526f013..6dd49d8 100644
> --- a/live-build/ubuntu/hooks/099-ubuntu-image-customization.chroot
> +++ b/live-build/ubuntu/hooks/099-ubuntu-image-customization.chroot
> @@ -17,14 +17,69 @@ if [ "$IMAGEFORMAT" == "none" ]; then
> /usr/sbin/oem-config-prepare --quiet
> touch "/var/lib/oem-config/run"
>
> - # Make the writable partition grow
> - echo "LABEL=writable / ext4 defaults,x-systemd.growfs 0 0" >>/etc/fstab
> + # Update the fstab to include the "discard" option, and
> + # "x-systemd.growfs" to ensure the root partition is expanded on first
> + # boot
> + awk \
> + -v root_fs_label="writable" \
> + -v root_fs_options="discard,x-systemd.growfs" \
> + '
> + BEGIN { OFS="\t"; count=0; }
>
> - # Create a 1GB swapfile
> - dd if=/dev/zero of=/swapfile bs=1G count=1
> - chmod 0600 /swapfile
> - mkswap /swapfile
> + # Omit the "UNCONFIGURED" warning if it is still present
> + /^# UNCONFIGURED FSTAB/ { next; }
>
> - echo "/swapfile none swap sw 0 0" >>/etc/fstab
> + # Only modify the first non-comment line where the second field is the
> + # root and omit multiple root definitions
> + /^[^#]/ && $2 == "/" {
> + if (!count) {
> + $1="LABEL=" root_fs_label;
> + $4=root_fs_options;
> + $6="1";
> + }
> + count++;
> + if (count > 1) next;
> + }
> +
> + { print; }
> +
> + # If we reach the end without seeing a root mount line, add one
> + END {
> + if (!count) {
> + print "LABEL=" root_fs_label, "/", "ext4", root_fs_options, "0", "1";
> + }
> + }
> + ' /etc/fstab > /etc/fstab.new
> + mv /etc/fstab.new /etc/fstab
> +
> + # Add units for a 1GiB swapfile, generated on first boot
> + cat << EOF > /lib/systemd/system/mkswap.service
> +[Unit]
> +Description=Create the default swapfile
> +DefaultDependencies=no
> +Requires=local-fs.target
> +After=local-fs.target
> +Before=swapfile.swap
> +ConditionPathExists=!/swapfile
> +
> +[Service]
> +Type=oneshot
> +ExecStartPre=fallocate -l 1GiB /swapfile
Oh, so fallocate is already good to use for swapfiles? I vaguely remember something about fallocate not being suitable for all filesystems for swap (as those might have been interpreted as files with holes), but that might have been an older state-of-things?
> +ExecStartPre=chmod 600 /swapfile
> +ExecStart=mkswap /swapfile
> +
> +[Install]
> +WantedBy=swap.target
> +EOF
> + cat << EOF > /lib/systemd/system/swapfile.swap
> +[Unit]
> +Description=The default swapfile
> +
> +[Swap]
huh, that's actually a systemd section that I did not know about!
> +What=/swapfile
> +EOF
> + mkdir -p /lib/systemd/system/swap.target.wants
> + ln -s ../mkswap.service /lib/systemd/system/swap.target.wants/
> + ln -s ../swapfile.swap /lib/systemd/system/swap.target.wants/
> fi
> fi
--
https://code.launchpad.net/~waveform/livecd-rootfs/+git/livecd-rootfs/+merge/415625
Your team Ubuntu Core Development Team is requested to review the proposed merge of ~waveform/livecd-rootfs:fix-swapfile into livecd-rootfs:ubuntu/master.
More information about the Ubuntu-reviews
mailing list