6

I have added some RAM to my netbook. I'd like to save an option to hibernate my computer, so I have to increase my SWAP from 2GiB to 4GiB.

My /etc/fstab looks like this:

UUID=57b6e4ca-86f6-440d-8d45-2295a86a946b /               ext4    errors=remount-ro 0       1
/dev/mapper/sda6_crypt /home           ext4    defaults        0       2
/dev/mapper/sda5_crypt none            swap    sw              0       0

My /etc/crypttab looks like this:

sda5_crypt UUID=17ec5831-e49e-4eb0-aa63-05101038a85c none luks,swap
sda6_crypt UUID=2a01b2a0-e954-4a97-9202-6cdbc0152e73 none luks

Appreciate any help.

Jorge Castro
  • 71,754
khaard
  • 178
  • 1
  • 7

4 Answers4

3

Should be simple. Assuming sda5_crypt is your swap:

sudo swapoff -a                   # turns all swaps off
sudo cryptsetup resize sda5_crypt # grows to maximum possible size
sudo mkswap /dev/sda5_crypt       # makes new swap using the new size
sudo swapon -a                    # turns all swaps on again

I just tested this on Ubuntu 16.04.

nh2
  • 1,621
2

Because the partitions are encrypted, it's not possible to resize them using the normal tools such as parted/gparted. This is because the actual partition on disk is not a valid file system, but just an encrypted block, which appears like a string of seemingly random data.

You can delete them and totally recreate them. If you only need to resize your swap, and to do this you don't need to resize any other (encrypted) partition, then trashing and re-installing it is going to be easy. But I assume that's not the case, as not many people will just leave unallocated space on the drive should they want to increase the swap partition (unless you're able to expand it into your un-encrypted root partition?). Otherwise you may be able to recreate your swap and home partitions, and copy across your files from an external drive. You will probably need to be familiar with cryptsetup and the way luks works. Otherwise a clean install is in order.

A common configuration with LUKS is to use LVM on top of it, which gives you a much easier way of resizing partitions inside your encrypted block - because LUKS means you have multiple partitions inside the same block, you don't need to resize the container to resize the partitions inside. If you are going to resort to a clean install, the alternate installer CD makes setting up a LUKS partition with LVM on top of it easy.

Most online tutorials you'll find about resizing a LUKS partition are actually about resizing LVM volumnes inside of one instead.

thomasrutter
  • 36,774
  • I have unencrypted ROOT partition which I have already shrinked. Then I have moved Unallocated space to extended partition. Now I have – khaard May 17 '12 at 09:05
  • I have shrinked / partition and moved unallocated space do extended partition. Now I have: unallocated space (2g), encrypted swap (2g), encrypted /home (290G). All within extended partition.

    Problem is I cannot find any tutorial about creating encrypted swap partition after installation and without using /dev/random to generate random keys. I've get used with entering passphrases twice. Encrypted swap With random keys would make hibernation impossible.

    BTW I have used Alternate CD to create LVM and LUKS. At this moment due to my huge data amount /home reinstall is not an option.

    – khaard May 17 '12 at 09:15
  • I answered a resizing question for LUKS ENCRYPTED SWAP IN LVM. – goulashsoup Jun 05 '22 at 16:00
0

Try booting on a Live CD or Live USB stick. Then choose "Try Ubuntu without installing it". When you get to the desktop, launch the app called Gparted.

In this application, you will be able to change the size of the partitions, including the swap one. But the latter one requires you first to right-click on the swap partition line and select "Swap off". Then you will be able to make your changes.

Agmenor
  • 16,214
-3

There is no way to enlarging encrypted swap partition. The solution is to reinstall the system with setting up new partition.

khaard
  • 178
  • 1
  • 7