How to transfer space from SWAP partition to Ubuntu Filesystem partition? [duplicate]

enter image description here

enter image description here

@heynnema I have created a 127GB Swap partition instead of Filesystem partition while installing Ubuntu. How can I transfer the Swap partition space to the filesystem?


Turn off current swap

sudo swapoff -a

Edit /etc/fstab

sudo -H gedit /etc/fstab

Comment out a line that looks similar to this (put a # at the beginning of the line):

UUID=52a6f33f-f94e-4b4d-8b8f-1d31b491c889  none  swap       sw       0       0

Add this line at the end of the file:

/swapfile    none    swap    sw      0   0

Save the file.

Create a new /swapfile

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

sudo swapoff -a # turn off swap

sudo rm -i /swapfile # remove old /swapfile

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 16G RAM and 4G swap

Confirm this line in /etc/fstab... and confirm other “swap” lines are commented out...

/swapfile    none    swap    sw      0   0

reboot                    # reboot and verify operation

Edit partitions

Make sure that you have a good backup of your important Ubuntu files, as this procedure can corrupt or lose data.

Keep these things in mind:

  • always start the entire procedure with issuing a swapoff on any mounted swap partitions, and end the entire procedure with issuing a swapon on that same swap partition

  • a move is done by pointing the mouse pointer at the center of a partition and dragging it left/right with the hand cursor

  • a resize is done by dragging the left/right side of a partition to the left/right with the directional arrow cursor

  • if any partition can't be moved/resized graphically, you may have to manually enter the specific required numeric data (don't do this unless I instruct you to)

  • you begin any move/resize by right-clicking on the partition in the lower pane of the main window, and selecting the desired action from the popup menu, then finishing that action in the new move/resize window

Do the following...

Note: if the procedure doesn't work exactly as I outline, STOP immediately and DO NOT continue.

  • boot to a Ubuntu Live DVD/USB, in “Try Ubuntu” mode
  • start gparted
  • swapoff on partition /dev/nvme0n1p9
  • delete partition /dev/nvme0n1p9
  • resize the right side of partition /dev/nvme0n1p8 all the way right
  • click the Apply icon