I have read Enabling swap on Ubuntu Core. Unfortunately the approach given used a swap file instead of a swap partition.
I was successful in generating a swap partition on an usb-mounted ssd usind parted
and mkswap
additionally i am able to mount the swap partition using swapon -U UUID
.
Sadly the mount only lasts till the next reboot.
I have read a lot and thought the swap-partition would automagically be mounted by systemd on start-up using the GPT-automount but that does not happen
Is it possible to use swap with a swap-partition in ubuntu core?
How is it done?
Yes, you can. For example, I downloaded ubuntu-core-16-amd64.img
, and added an sda4
partition using gparted
, telling it to make it a swap partition. Then I created /etc/systemd/system/dev-sda4.swap
,
[Unit]
Description=Be swappy
[Swap]
What=/dev/sda4
[Install]
WantedBy=multi-user.target
The name of the file is important! from systemd.swap(5)
,
Swap units must be named after the devices or files they control. Example: the swap device /dev/sda5 must be configured in a unit file dev-sda5.swap. For details about the escaping logic used to convert a file system path to a unit name, see systemd.unit(5). Note that swap units cannot be templated, nor is possible to add multiple names to a swap unit by creating additional symlinks to it.
(you can use systemd-escape --suffix=swap --path /dev/whatever
to get the right name).
Thank you!
systemd-escape
did the trick.
In combination with /dev/disk/by-uuid/_uuid_ i was able to mount the swap partition as you described
I used the uuid because i have multiple usb-disks attached. These are unfortunately mounted on a not deterministic pattern. This results in the swap-partition sometime beeing sda1 and some other time beeing sdb1.
For others who come by…
The filename has to be escaped with systemd-escape
whilst the end of the path after What=
must be the same as listed under ls -l /dev/disk/by-uuid/
starting with /dev/disk/by-uuid
Mine (dev-disk-by\x2duuid-6a8085d3\x2d88b4\x2d431d\x2d86e4\x2d93d6f07a8634.swap) looks like:
[Unit]
Description=Be swappy
[Swap]
What=/dev/disk/by-uuid/6a8085d3-88b4-431d-86e4-93d6f07a8634
[Install]
WantedBy=multi-user.target
1 Like