0

Currently, I am running low on space on my root partition (I need more space to execute the 20.04 update).

I have a 14.9 GB swap partition, and a half-filled home partition. I'm thinking I would delete the swap partition, extend my root partition into some, or all of the remaining space, then make a new swap partition by resizing my home partition.

This is currently what my partitions in GParted look like, with the first few partitions are for my Windows dual boot:

partitions in GParted

How would I accomplish this?

1 Answers1

0

We'll convert your partition-based swap, to a /swapfile. We'll delete the swap partition, and use that unallocated space to increase the / partition. You'll need to have a bootable Ubuntu Live DVD/USB to proceed.

Edit /etc/fstab...

To edit, use sudo -H gedit /etc/fstab or sudo pico /etc/fstab

and comment out this line:

UUID=xxxx-xxxx-xxxx-xxxx none  swap       sw       0       0

Save the edit and quit the editor

Boot to a Ubuntu Live DVD/USB

Start gparted.

Do a swapoff on the /dev/nvme0n1p6 partition

Delete the /dev/nvme0n1p6 partition, as it won't be used any more

Drag the right side of the /dev/nvme0n1p5 partition all the way right

Click the Apply button

Quit gparted

Reboot

Create a /swapfile...

Note: Incorrect use of the dd command can cause data loss. Suggest copy/paste.

In the terminal...

sudo dd if=/dev/zero of=/swapfile bs=1M count=4096

sudo chmod 600 /swapfile # set proper file protections sudo mkswap /swapfile # init /swapfile sudo swapon /swapfile # turn on swap free -h # confirm xxG RAM and 4G swap

Confirm this /swapfile line at the end of /etc/fstab... and confirm no other uncommented “swap” lines...

To edit, use sudo -H gedit /etc/fstab or sudo pico /etc/fstab

Note: Use SPACES, not TABS

/swapfile  none  swap  sw  0  0

reboot                    # reboot and verify operation
heynnema
  • 70,711
  • would it be advisable to, instead of creating a swapfile, create a new swap partition, by reducing the size of my home partition, and creating a swap partition at the end, with the unallocated space? I also had a question about the swapfile, does it reside in root? – Matthew Ha Oct 07 '20 at 14:22
  • @MatthewHa /swapfile (which does reside in root) vs swap partition is moot, as either will work. All current versions of Ubuntu use a /swapfile (when clean installed). Yes, you could still use a swap partition, but it would require a somewhat risky RESIZE and MOVE of your /home partition. My procedure, is faster, safer, and doesn't require you to reduce your /home. – heynnema Oct 07 '20 at 15:50