Extending Root Partition by Deleting Swap Partition [Duplicate]

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 gparted looks like, the first few partitions are for my windows dual boot.

How would I accomplish this?

2

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
2
Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest