[SOLVED] Automatic swap detection interferes with encr. swap

Kernels & Hardware, configuring network, installing services

[SOLVED] Automatic swap detection interferes with encr. swap

Postby Palmstroem » 2017-08-14 12:25

Recently I upgraded from Jessie to Stretch (9.1) and got some problems with swap. I use encrypted swap with the following fstab entry:
Code: Select all
/dev/mapper/cswap none swap pri=1,defaults 0 0
and a corresponding crypttab entry:
Code: Select all
cswap /dev/disk/by-id/ata-SAMSUNG_SSD_PM851_mSATA_256GB_S1EVNYAF552489-part8 /dev/urandom swap,cipher=aes-cbc-essiv:sha256,size=256
The encrypted swap works, as seen in the following test:
Code: Select all
# cryptsetup status cswap
/dev/mapper/cswap is active and is in use.
  type:    PLAIN
  cipher:  aes-cbc-essiv:sha256
  keysize: 256 bits
  device:  /dev/sda8
  offset:  0 sectors
  size:    23437312 sectors
  mode:    read/write
However, on every boot I get the error: Failed to activate swap Swap Partition. Apparently systemd tries to launch an automatically generated service dev-sda8.swap and fails:
Code: Select all
# systemctl status dev-sda8.swap
● dev-sda8.swap - Swap Partition
   Loaded: loaded (/run/systemd/generator.late/dev-sda8.swap; generated; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2017-08-14 13:47:47 CEST; 1h 8min ago
     What: /dev/sda8
     Docs: man:systemd-gpt-auto-generator(8)
As far as I know systemd-gpt-auto-generator should do nothing if there is an entry in fstab. De-activating the service does not help.
How can I prevent this?

EDIT:
Problem solved! The situation was similar to the one reported as a bug here https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=772182. I will give a short description of what happens (in my opinion):

    1. When Debian boots, the system daemon systemd activates quite a number of services and devices. One of these is the systemd-cryptsetup@cswap.service which takes care about the encrypted swap.
    However, there is also the generator systemd-gpt-auto-generator which creates dev-sda8.swap. Later, dev-sda8.swap tries to switch on /dev/sda8 as swap and fails because swap space is already controlled by dev-mapper-cswap.swap.

    2. It is therefore totally useless to stop, kill, or mask dev-sda8.swap since it gets dynamically created at every boot.

    3. Now how on earth does systemd-gpt-auto-generator know that there should be a swap space on my partition /dev/sda8? The answer is that it reads the partition GUID code from the GPT (GUID Partition Table). This whole GUID talk can be quite confusing! You must distinguish the partition GUID code from the patition unique GUID! The latter is created when you partition the disk and is supposed to be unique all over the universe :D . On the other hand, the partition GUID code is just indicating the type of the partition: whether it is intended for Windows, Linux root, Linux home or whatever. I had set sda8 to type Linux swap which means a magic number of 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F. When I corrected this number to 0FC63DAF-8483-4772-8E79-3D69D8477DE4 (Linux filesystem data) and rebooted, the error was gone.
Happy Linuxing!
Palmstroem
 
Posts: 14
Joined: 2017-08-12 12:36

Return to System configuration

Who is online

Users browsing this forum: No registered users and 3 guests

fashionable