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

feat: [NODE-1529] Add swap to GuestOS #2780

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 15 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,18 @@ 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."
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
)
andrewbattat marked this conversation as resolved.
Show resolved Hide resolved
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
)