1

Much to my surprise I recently found myself to lack a swap partition.

Since (as is evident from the output of df, which I hereby repost) that I am running off a single encrypted volume, I was wondering how I can safely go about resizing everything and creating an 8 GB partition for use as a swap (and enabling it's use). I seem to remember that the scheme I opted for during installation is LUKS.

user@host:~$ df
Filesystem                  1K-blocks     Used Available Use% Mounted on
/dev/mapper/ubuntu--vg-root 237978256 14144120 211722472   7% /
none                                4        0         4   0% /sys/fs/cgroup
udev                          3829132        4   3829128   1% /dev
tmpfs                         3844736     2060   3842676   1% /tmp
tmpfs                          768948     1324    767624   1% /run
none                             5120        0      5120   0% /run/lock
none                          3844736    32312   3812424   1% /run/shm
none                           102400       28    102372   1% /run/user
tmpfs                         3844736        0   3844736   0% /var/spool
tmpfs                         3844736       24   3844712   1% /var/tmp
tmpfs                         3844736      936   3843800   1% /var/log
/dev/sda1                      240972    84550    143981  37% /boot
/home/user/.Private        237978256 14144120 211722472   7% /home/user
user@host:~$ 

I'm a little out of my depth and I intuit that there's ample opportunity for disaster so I'd much appreciate some assistance. (And, though I would be disappointed if I accidentally nuked the drive, this is just a personal laptop with nothing criticcal on it, so I could always start over).

qubex
  • 425
  • 9
  • 22

2 Answers2

2

There is a really nice tool called system-config-lvm, which helps guide the resizing, adding, removing and other functions of pv's and lv's of your LVM. Unfortunately, you'll run into issues trying to resize or edit an active partition.

You will need to run a Live Distribution in order to modify your SSD's partitions. You can do this with Ubuntu itself, or try out the [no-longer free] partedmagic. Parted Magic does have better features and functionality dealing with SSD/HDDs.

Once you're in a Live Distro, you'll be able to find lots of information on how to resize your partitions.

earthmeLon
  • 11,247
  • Do you suggest I create the partition for the swapfile inside the LUKS volume or aside from it? – qubex May 17 '14 at 18:26
  • 1
    Most importantly, set up the swap volume as a swap volume (random key each boot). Whether or not you create a completely new LVM/LUKS volume depends on what you want to accomplish. – earthmeLon May 19 '14 at 17:05
  • I’ve kind of succeeded in re-enabling virtual memory by providing a swap partition, but I haven’t yet succeeded in providing a swap partition that can be used for the sake of hibernation and resume (I think the memory image is being written to the swap upon hibernation but not being read at the successive power-on). – qubex May 19 '14 at 18:56
2

You can add some swap without resizing partitions.

If your root partition is not BTRFS you can easily make a swap file of any size, even inside an encrypted partition. It is possible to have multiple swap partitions and/or swap files.

# Make an empty 8GB file 
sudo dd if=/dev/zero of=/swap.file bs=1G count=8

# Set permissions
sudo chmod 600 /swap.file

# Format it
sudo mkswap /swap.file

# Activate it
sudo swapon /swap.file

# Check it
free -h

# Deactivate it
sudo swapoff /swap.file

To activate it automatically on boot you can add it to your /etc/fstab just like a swap partition:

/swap.file    swap    defaults    0    0
Clint
  • 61