Skip to content

Commit

Permalink
Add swap to GuestOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Bownairo committed Nov 22, 2024
1 parent cbb47f9 commit 0e9de2c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions ic-os/components/early-boot/fstab/fstab-guestos
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ tmpfs /tmp tmpfs defaults 0 2
/dev/mapper/store-shared--backup /var/lib/ic/backup ext4 defaults,context=system_u:object_r:ic_data_t:s0 0 2
/dev/mapper/store-shared--crypto /var/lib/ic/crypto ext4 defaults 0 2
/dev/mapper/store-shared--data /var/lib/ic/data xfs defaults 0 2
/dev/mapper/store-shared--swap none swap defaults 0 2
2 changes: 2 additions & 0 deletions ic-os/components/guestos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ component_files = {
Label("upgrade/shared-resources/setup-shared-resources/setup-shared-crypto.service"): "/etc/systemd/system/setup-shared-crypto.service",
Label("upgrade/shared-resources/setup-shared-resources/setup-shared-data.sh"): "/opt/ic/bin/setup-shared-data.sh",
Label("upgrade/shared-resources/setup-shared-resources/setup-shared-data.service"): "/etc/systemd/system/setup-shared-data.service",
Label("upgrade/shared-resources/setup-shared-resources/setup-shared-swap.sh"): "/opt/ic/bin/setup-shared-swap.sh",
Label("upgrade/shared-resources/setup-shared-resources/setup-shared-swap.service"): "/etc/systemd/system/setup-shared-swap.service",
Label("upgrade/systemd-generators/guestos/mount-generator"): "/etc/systemd/system-generators/mount-generator",
Label("upgrade/systemd-generators/systemd-gpt-auto-generator"): "/etc/systemd/system-generators/systemd-gpt-auto-generator",
Label("upgrade/manageboot/manageboot.sh"): "/opt/ic/bin/manageboot.sh",
Expand Down
20 changes: 20 additions & 0 deletions ic-os/components/init/setup-lvs/guestos/setup-lvs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,23 @@ lvs /dev/store/shared-backup >/dev/null 2>&1 || (
fi
retry lvcreate --yes -L "$LV_SIZE"M -n shared-backup store
)

# Set up swap space if it does not exist yet.
lvs /dev/store/shared-swap >/dev/null 2>&1 || (
echo "Logical volume 'shared-swap' does not exist yet (first boot?), creating it."
# Create 64GB of swap
LV_SIZE=64000



TOTAL_SIZE=$(($(blockdev --getsz /dev/mapper/vda10-crypt) * 512))
# Limit to 64G or 14% of capacity, whichever is lower.
# Note: The odd percentage makes calculation easier, and allows for a
# smaller swap when testing.
LV_SIZE=$(("$TOTAL_SIZE" / 7 / 1024 / 1024))
LV_SIZE_LIMIT=64000
if [ "${LV_SIZE}" -gt "${LV_SIZE_LIMIT}" ]; then
LV_SIZE="${LV_SIZE_LIMIT}"
fi
retry lvcreate --yes -L "$LV_SIZE"M -n shared-swap store
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[Unit]
Description=Setup shared-swap space
DefaultDependencies=no
Requires=dev-mapper-store\x2dshared\x2d\x2dswap.device
After=dev-mapper-store\x2dshared\x2d\x2dswap.device
Before=dev-mapper-store\x2dshared\x2d\x2dswap.swap
# Add an explicit sequencing to LVM setup. The observed problem is that the
# LV apparently becomes notified as "ready" through udev before the actual
# lvcreate command has finished. This results in filesystem setup racing with
# lvcreate performing a "wipe" of the LV, resulting in a destroyed filesystem
# in turn.
After=setup-lvs.service
Requires=setup-lvs.service

[Install]
RequiredBy=systemd-fsck@dev-mapper-store\x2dshared\x2d\x2dswap.service
WantedBy=local-fs.target

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/opt/ic/bin/setup-shared-swap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -e

blkid /dev/mapper/store-shared--swap >/dev/null || (
mkswap /dev/mapper/store-shared--swap
)

0 comments on commit 0e9de2c

Please sign in to comment.