[systemd-devel] Swap gets activated twice (through fstab and gpt generators)

Martin Pitt martin.pitt at ubuntu.com
Fri Jan 23 01:18:35 PST 2015


Hello all,

we just received a report (https://launchpad.net/bugs/1399595) that
swap gets activated twice:

| systemd[1]: Activating swap Swap Partition...
| systemd[1]: Activating swap /dev/disk/by-uuid/73d341f1-eedc-43fc-9e53-ba4194dae3fb...
| swapon[396]: swapon: /dev/disk/by-uuid/73d341f1-eedc-43fc-9e53-ba4194dae3fb: swapon failed: Device or resource busy
| systemd[1]: dev-disk-by\x2duuid-73d341f1\x2deedc\x2d43fc\x2d9e53\x2dba4194dae3fb.swap swap process exited, code=exited status=255
| systemd[1]: Failed to activate swap /dev/disk/by-uuid/73d341f1-eedc-43fc-9e53-ba4194dae3fb.
| systemd[1]: Unit dev-disk-by\x2duuid-73d341f1\x2deedc\x2d43fc\x2d9e53\x2dba4194dae3fb.swap entered failed state.
| systemd[1]: Activated swap Swap Partition.
| kernel: Adding 8298492k swap on /dev/sda3. Priority:-1 extents:1 across:8298492k SSFS

It turns out that the fstab and the gpt generator are overlapping here. gpt
creates a unit dev-sda3.swap:

| # Automatically generated by systemd-gpt-auto-generator
|
| [Unit]
| Description=Swap Partition
| Documentation=man:systemd-gpt-auto-generator(8)
|
| [Swap]
| What=/dev/sda3
| /tmp/r/tmp/gpt/dev-sda3.swap (END)

while /etc/fstab has

| # sda3
| UUID=73d341f1-eedc-43fc-9e53-ba4194dae3fb none swap sw 0 0

and thus the fstab generator creates one for the UUID name
dev-disk-by\x2duuid-73d341f1\x2deedc\x2d43fc\x2d9e53\x2dba4194dae3fb.swap:

| # Automatically generated by systemd-fstab-generator
|
| [Unit]
| SourcePath=/etc/fstab
| Documentation=man:fstab(5) man:systemd-fstab-generator(8)
|
| [Swap]
| What=/dev/disk/by-uuid/73d341f1-eedc-43fc-9e53-ba4194dae3fb
| Options=sw

Thus we get two units for the same swap device, and worse, the gpt one
won over the fstab one (just by sheer chance, this is a race).

So this is a bit tricky; obviously both units are justified: we want
the auto-discovery in gpt, and enable swap from fstab without GPT.

One idea would be to resolve symlinks after the generators (in
particular fstab) discovered the device names. Then fstab would also
create a dev-sda3.swap, and that unit would override the one generated
by gpt. As fstab should always win over gpt (as you might have
additional options there), gpt should write into ".late" and fstab
into "early" or "normal"?

There is a potential problem, though: at the time when the generator
runs, the device might not exist yet; it might take longer to be
detected, or it's on LVM or behind a still locked LUKS etc. In that
case the /dev/disks/... link doesn't even exist yet and we can't
resolve it.

So perhaps the more robust fix would be to make the gpt generator not
generate swap units if fstab already configures any swap device? I. e.
auto-discovery and swaps in fstab are mutually exclusive then.

Thanks,

Martin
-- 
Martin Pitt                        | http://www.piware.de
Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20150123/43df50b0/attachment-0001.sig>


More information about the systemd-devel mailing list