[FIX] no swap on fresh LM19 install with home directory encryption

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
User avatar
xenopeek
Level 25
Level 25
Posts: 29503
Joined: Wed Jul 06, 2011 3:58 am

[FIX] no swap on fresh LM19 install with home directory encryption

Post by xenopeek »

There is an issue with home directory encryption that causes swap to be misconfigured during installation of Linux Mint 19, if you enabled home directory encryption during installation. This leaves you with swap that doesn't work.

To correct this run the following two commands after logging in to your new Linux Mint 19 installation:
sudo sed -i 's#/target##' /etc/crypttab
sudo sed -i '#^/swapfile#d' /etc/fstab

Finish with the following command:
sudo update-initramfs -u



Questions & Answers

Q: How do I know whether I have home directory encryption?
A: Run the following command and unless it replies the directory doesn't exist, you have home directory encryption:
ls /home/.ecryptfs

Q: How can I confirm that my swap doesn't work?
A: Run the following command and if it doesn't reply anything your swap doesn't work:
swapon --show

Q: What do those "sudo sed" commands do?
A: The first deletes "/target" from the line in /etc/crypttab file where it was erroneously added during installation. The second deletes the line starting with "/swapfile" in /etc/fstab that was erroneously not removed during installation. You may also manually edit these files with command xed admin:///etc/crypttab and xed admin:///etc/fstab if you prefer.

Q: What does the "sudo update-initramfs -u" do?
A: It updates the initramfs of your active kernel so that from next boot swap will be used correctly. If you've already installed new kernels you may wish to run the command as sudo update-initramfs -u -k 'all' instead to update the initramfs for all installed kernels. This is a one time action and future kernels you install won't need any action from you for this.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Image
Cortimi

Re: [FIX] no swap on fresh LM19 install with home directory encryption

Post by Cortimi »

Went through the steps, however:

$ sudo update-initramfs -u
update-initramfs: Generating /boot/initrd.img-4.15.0-29-generic
W: initramfs-tools configuration sets RESUME=UUID=2adde1e7-6685-48ad-8b0c-2b76c347adba
W: but no matching swap device is available.

swapon --show doesn't return anything.

$ ls /home/.ecryptfs shows the proper folder
User avatar
xenopeek
Level 25
Level 25
Posts: 29503
Joined: Wed Jul 06, 2011 3:58 am

Re: [FIX] no swap on fresh LM19 install with home directory encryption

Post by xenopeek »

Did you check the swapon --show after reboot? You need to reboot to activate changes.

If that didn't help, can you please run this command, reboot afterwards and check swapon --show again:
sudo update-initramfs -c -k 'all'
Image
Cortimi

Re: [FIX] no swap on fresh LM19 install with home directory encryption

Post by Cortimi »

Wow, don't I feel like a newb now.

$ sudo swapon --show
[sudo] password for cortimi:
NAME TYPE SIZE USED PRIO
/dev/dm-0 partition 2G 0B -2

Does that look good? I have 8GB of RAM and I crash a LOT from running out of memory (using Android emulators), so I hope this fixes things!
User avatar
xenopeek
Level 25
Level 25
Posts: 29503
Joined: Wed Jul 06, 2011 3:58 am

Re: [FIX] no swap on fresh LM19 install with home directory encryption

Post by xenopeek »

Yes that looks good; it shows you have encrypted swap as you need to have with home directory encryption.

General recommendation is to have about 20% of RAM as swap so you're good on that front. If for your particular use you need more swap you can increase the size of the swapfile with some commands. But try it out as-is first.
Image
gostal
Level 3
Level 3
Posts: 119
Joined: Fri Sep 07, 2018 9:56 am

Re: [FIX] no swap on fresh LM19 install with home directory encryption

Post by gostal »

I'm definitely a newbie to Mint, not so much to Linux which I have been running in various forms for about 20 years. I'm a bit puzzled.

As far as I can make out my /etc/crypttab and /etc/fstab are fine now:

Code: Select all

gostal@ki003401-linux:~$ cat /etc/crypttab 
cryptswap1 /swapfile /dev/urandom swap,offset=1024,cipher=aes-xts-plain64
...
gostal@ki003401-linux:~$ cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda5 during installation
UUID=33dfb83d-b24e-497f-af8e-260a1c100c53 /               ext4    errors=remount-ro 0       1
/dev/mapper/cryptswap1 none swap sw 0 0
and also swapon --show for which I get the same as Cortimi and ls /home/.ecryptfs seems reassuring.
However, when I do: sudo update-initramfs -u -k 'all' I get:

Code: Select all

update-initramfs: Generating /boot/initrd.img-4.15.0-33-generic
W: initramfs-tools configuration sets RESUME=UUID=ed9a18e4-11ca-4a2b-afba-4bcb6c36ae22
W: but no matching swap device is available.
update-initramfs: Generating /boot/initrd.img-4.15.0-20-generic
W: initramfs-tools configuration sets RESUME=UUID=ed9a18e4-11ca-4a2b-afba-4bcb6c36ae22
W: but no matching swap device is available.
also after reboot. This is apparently a warning and not an actual error. Is this to be expected when
using encrypted swap?

Not expected was also that:
sudo sed -i '#^/swapfile#d' /etc/fstab
did not delete the line beginning with /swapfile. I had to edit the file to remove the line which was the second (not counting comments). I was a bit careless this time usually I copy the original to begin with but not this time so I cannot show /etc/fstab prior to my edit.
Lap: Latitude E6520, i3-2330M @ 2.20GHz, 4GB, Intel HD Graphics 3000, OS Mint 19.1 version Mate, Windows 7 Enterprise
Desk: Dell Precision T5810, Xeon E5-1650 v4 @ 3.60GHz,72 GB, Radeon Pro WX 7100, OS CentOS 7.7
Stockholm, Sweden
snowshoeb

Re: [FIX] no swap on fresh LM19 install with home directory encryption

Post by snowshoeb »

I got a different error using a swap partition instead of a swap file with encrypted home directory installing LM19. The swap partition UUID in /etc/initramfs-tools/conf.d/resume was that of the unencrypted swap partition commented out in /etc/fstab/ resulting in 20 second delays booting the LM 19 default kernel of 4.15.0-20 and boot hangs with 4.15.0-34. Deleting /etc/initramfs-tools/conf.d/resume and running sudo update-initramfs -u fixed both boot issues.
User avatar
sigmalion
Level 1
Level 1
Posts: 4
Joined: Thu Oct 11, 2018 9:40 am

Re: [FIX] no swap on fresh LM19 install with home directory encryption

Post by sigmalion »

snowshoeb wrote: Sat Sep 29, 2018 10:36 am Deleting /etc/initramfs-tools/conf.d/resume and running sudo update-initramfs -u fixed both boot issues.
It worked for me, thanks a lot.
derflou78

Re: [FIX] no swap on fresh LM19 install with home directory encryption

Post by derflou78 »

LVM is a logical set of partitions inside the physical partition, in your case sda3.
The default will be / & swap but you cannot see that from outside the LVM.
FifesAndClarions

Re: [FIX] no swap on fresh LM19 install with home directory encryption

Post by FifesAndClarions »

xenopeek/ or someone who can possibly help:

On xenopeek's third post it says:
General recommendation is to have about 20% of RAM as swap so you're good on that front. If for your particular use you need more swap you can increase the size of the swapfile with some commands. But try it out as-is first.
I direly need help accomplishing such an increase. I'm not a newb with comfort level using the command line and follow steps, but I am rather a newb in terms of overall general knowledge; I hardly keep any chain of commands in my head or intimately know how they work in tandem.

That said, I installed LM19 a little over a week ago with an encrypted home folder. I quickly noticed the initial lack of swapfile and noticed it was one of the first things listed in 'Known Issues'. I followed the simple set of commands provided and was furnished automatically with a swapfile size of 1.4GB (never gave an option of setting a custom size; and my total RAM is 2.9GB on this system). 1.4 isn't terribly small but I had my doubts as to whether it'd be enough for how I typically use my system.

Today I concluded I needed more, but after scouring through forums (LM, ubuntu, and others), I haven't found anything that comes close to helping me with "cryptswap" -- whether steps to successfully delete and create a new one, or simply resize.
I've steered clear of even experimenting with steps that I'm 99% certain would not apply in my case -- I can't afford to bork anything right now -- and ended up trying one set and instantly regretting it -- as it didn't resize anything, and left me with
swapon: /swapfile: read swap header failed
, whatever that means.
For the record, the two commands I tried I believe were:

Code: Select all

sudo cryptsetup resize cryptswap1
sudo mkswap /dev/mapper/cryptswap1

I hope I haven't rambled on too much, and wish I could provide more detail but there's little detail for me to provide at this point beyond the pathetic efforts I've made so far, plus the 50 random forum pages noisily rattling in my head to no avail.

Someone knowledgeable -- please help me delete or if possible fix/cleanup my current mess, and to set it so that I can have 2gb swap file!!
I can follow directions pretty well.
mpke98

Re: [FIX] no swap on fresh LM19 install with home directory encryption

Post by mpke98 »

sigmalion wrote: Thu Oct 11, 2018 9:43 am
snowshoeb wrote: Sat Sep 29, 2018 10:36 am Deleting /etc/initramfs-tools/conf.d/resume and running sudo update-initramfs -u fixed both boot issues.
It worked for me, thanks a lot.
I get this when I try implementing this fix:
update-initramfs: Generating /boot/initrd.img-4.15.0-38-generic
cryptsetup: WARNING: Invalid source device /swapfile
cryptsetup: WARNING: target cryptswap1 has a random key, skipped
Waterwalker
Level 1
Level 1
Posts: 6
Joined: Fri Jun 30, 2017 7:53 pm

Re: [FIX] no swap on fresh LM19 install with home directory encryption

Post by Waterwalker »

When I used the first command got the floowing reply "sed: can't read /etc/crypttab: No such file or directory"
User avatar
xenopeek
Level 25
Level 25
Posts: 29503
Joined: Wed Jul 06, 2011 3:58 am

Re: [FIX] no swap on fresh LM19 install with home directory encryption

Post by xenopeek »

Waterwalker wrote: Wed Nov 07, 2018 11:31 pm When I used the first command got the floowing reply "sed: can't read /etc/crypttab: No such file or directory"
If you don't have a /etc/crypttab file, you're not using Linux Mint 19 with home directory encryption or you don't have swap.
Image
jcoles
Level 2
Level 2
Posts: 63
Joined: Wed Feb 08, 2012 11:22 pm

Re: [FIX] no swap on fresh LM19 install with home directory encryption

Post by jcoles »

It all looks like smoke and mirrors to me.

Code: Select all

swapon --show
NAME      TYPE      SIZE USED PRIO
/dev/dm-0 partition   2G   0B   -2
What's a dm-0?

/etc/crypttab defines /swapfile as

Code: Select all

cryptswap1 /swapfile /dev/urandom swap,offset=1024,cipher=aes-xts-plain64
/dev/urandom is a random number generator. How can data be written to it?

/etc/fstab defines

Code: Select all

/swapfile                                 none            swap    sw              0       0
/dev/mapper/cryptswap1 none swap sw 0 0
Is there really a swap space? If so, where is it?
RR245

Re: [FIX] no swap on fresh LM19 install with home directory encryption

Post by RR245 »

jcoles wrote: Sun Nov 11, 2018 1:56 pm What's a dm-0?
  • dm-X — Device Mapper. Use -N to see what these are, or ls -l /dev/mapper. Device Mapper underlies LVM2 and dm-crypt. If you're using either LVM or encrypted volumes, you'll see dm-X devices.

https://unix.stackexchange.com/question ... -dm-1-mean
/etc/crypttab defines /swapfile as

Code: Select all

cryptswap1 /swapfile /dev/urandom swap,offset=1024,cipher=aes-xts-plain64
/dev/urandom is a random number generator. How can data be written to it?
Your system remember the ramdom key for your crypted swap while it is running. After shutdown the key and swapped data are lost. That's the reason why suspend-to-disk does not work with home directory encryption.
/etc/fstab defines

Code: Select all

/swapfile                                 none            swap    sw              0       0
/dev/mapper/cryptswap1 none swap sw 0 0
Really? Or did you make a mistake while copying? It should be

Code: Select all

#/swapfile                                 none            swap    sw              0       0
/dev/mapper/cryptswap1 none swap sw 0 0
Please check it.
Is there really a swap space? If so, where is it?
Well, good question. /dev/mapper/cryptswap1 is a link to /dev/dm-0 and the crypttab says, that /swapfile should be used for /dev/mapper/cryptswap1. In my understanding, swap should be a file on your drive. If I am wrong and /dev/dm-0 is a virtual device in the memory :roll: it would not help if swap is needed. :?:
Falling_Stars

Re: [FIX] no swap on fresh LM19 install with home directory encryption

Post by Falling_Stars »

I am having this very issue. I did the fix, and here's the readout of how it went:

:~$ sudo sed -i 's#/target##' /etc/crypttab
[sudo] password for username
~$ sudo sed -i '#^/swapfile#d' /etc/fstab
~$ udo update-initramfs -u

Command 'udo' not found, but can be installed with:

sudo apt install udo

~$ sudo apt install udo
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
udo
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 205 kB of archives.
After this operation, 598 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu bionic/universe amd64 udo amd64 6.4.1-4 [205 kB]
Fetched 205 kB in 4s (53.4 kB/s)
Selecting previously unselected package udo.
(Reading database ... 280215 files and directories currently installed.)
Preparing to unpack .../archives/udo_6.4.1-4_amd64.deb ...
Unpacking udo (6.4.1-4) ...
Setting up udo (6.4.1-4) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
~$ sudo sed -i 's#/target##' /etc/crypttab
~$ sudo sed -i '#^/swapfile#d' /etc/fstab
~$ sudo update-initramfs -u
update-initramfs: Generating /boot/initrd.img-4.15.0-42-generic
W: initramfs-tools configuration sets RESUME=UUID=3a525a17-2651-4816-bc1e-07d733969e91
W: but no matching swap device is available.
~$ swapon
:~$ swapon --show
~$
arso96

Re: [FIX] no swap on fresh LM19 install with home directory encryption

Post by arso96 »

There should be swap, but I think it is crypswap inside the LVM partition. The root partition is also inside the LVM partition.

There is a good instruction for testing the Lubuntu alternate iso file with encryption. I think you can use it (with modifications) also for other iso files, for example the Ubuntu desktop iso files. See this link ]

http://iso.qa.ubuntu.com/qatracker/m...s/1439/results


There is also this direct instruction set for Ubuntu, which I have not used,

http://iso.qa.ubuntu.com/qatracker/m...s/1451/results


I think it works well too.
Last edited by SMG on Tue Nov 01, 2022 8:51 pm, edited 1 time in total.
Reason: Removed links from post.
pregister

Re: [FIX] no swap on fresh LM19 install with home directory encryption

Post by pregister »

Same problem no swap on encrypted install.Solved.
Thank you xenopeek.Your answer worked for me instantly.You rock sir.
gm10

Re: [FIX] no swap on fresh LM19 install with home directory encryption

Post by gm10 »

pregister wrote: Wed Feb 06, 2019 11:45 am Same problem no swap on encrypted install.Solved.
Thank you xenopeek.Your answer worked for me instantly.You rock sir.
Surprised this is still a thing. Did you install 19 and not 19.1? Because we fixed this in 19.1.
iHad169

Re: [FIX] no swap on fresh LM19 install with home directory encryption

Post by iHad169 »

I have same problem with you.
I go to find my swap UUID.
I edit /etc/initramfs-tools/conf.d/resume UUID to my swap UUID.
I not have W: but no matching swap device is available. Error
I do it this:

On terminal. Use blkid Find your swap UUID. We need TYPE="swap" line UUID="555b2d67-e979-4c9b-b582-630d40911c09".

Code: Select all

localhost@localhost-desktop:~$ blkid
/dev/sda1: UUID="ed379f71-07ba-4a63-9256-133740f2fb8c" UUID_SUB="d14f0761-79d9-45a1-8dbc-8143241a92b1" TYPE="btrfs" PARTUUID="53769008-5316-4565-b63f-d651d128bd06"
/dev/sda2: UUID="94e1fea9-0b36-4fba-be55-c042545773f0" TYPE="bcache" PARTUUID="f31256a3-0de0-4705-af5c-dc9e4a69b03d"
/dev/sda3: UUID="555b2d67-e979-4c9b-b582-630d40911c09" TYPE="swap" PARTUUID="01ce7382-f49a-46a2-9653-d4419caf19a5"
/dev/sda4: UUID="56FE8CD0FE8CAA37" TYPE="ntfs" PARTUUID="8297e9c5-7a96-4ca4-841e-305e14628781"
/dev/sdb1: UUID="7829-FD25" TYPE="vfat" PARTUUID="be6fdd05-9b09-4b1d-9e23-416312a61826"
/dev/sdb2: UUID="272083cf-9961-4759-8164-6260c304c0cd" TYPE="bcache" PARTUUID="9a919546-91c8-4748-a5ce-c75c87947d3a"
/dev/bcache0: UUID="173aeef8-3958-4a66-b574-048035620008" UUID_SUB="0714a16b-08eb-41b2-9c74-c6f46c4b3e2b" TYPE="btrfs"
/dev/mapper/cryptswap1: UUID="84055346-89b1-4a61-98b2-2d12e3f39de8" TYPE="swap"
Edit /etc/initramfs-tools/conf.d/resume

Code: Select all

sudo gedit /etc/initramfs-tools/conf.d/resume
On /etc/initramfs-tools/conf.d/resume like this:

Code: Select all

RESUME=UUID=27372d81-43e2-48c4-b789-d45f06aecdca
You need change RESUME=UUID=<before Your swap UUID> to RESUME=UUID=<Your swap UUID on top finded>
On My Case
E.g. RESUME=UUID=27372d81-43e2-48c4-b789-d45f06aecdca to RESUME=UUID="555b2d67-e979-4c9b-b582-630d40911c09"
Save it. You run sudo update-initramfs -c -k 'all' on Terminal for Update.
You will can see not have W: but no matching swap device is available. Error.
Locked

Return to “Beginner Questions”