How to transfer space from SWAP partition to Ubuntu Filesystem partition? [duplicate]
772
@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?
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
First option: change swap partition into a regular partition
Run gparted from the menu. Choose the swap partition. Right-click the oversize swap partition and choose 'swapoff'. When this is done and you right-click again, you get a choice 'format to....'. Choose ext4.
Next, right-click on the new partition and click 'Information'. Save the value of the displayed UUID somewhere.
You need to manually create a mount point and and entry in /etc/fstab, such as
UUID=... /mynewmountpoint ext4 defaults 0 2
For ..., use the value you saved above.
Also remove swap from /etc/fstab.
Second option: add the swap partition to the ubuntu system partition
But if you want to add the space to the actual partition, then you need to boot from your ubuntu installation stick and run gparted from there (click on the applications grid at the lower left and search for gparted).
Right-click and delete the swap partition and then you can extend (resize/move) the ubuntu system partition.
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):
Add this line at the end of the file:
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 swapsudo rm -i /swapfile # remove old /swapfileConfirm this line in /etc/fstab... and confirm other “swap” lines are commented out...
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.
gparted
First option: change swap partition into a regular partition
Run gparted from the menu. Choose the swap partition. Right-click the oversize swap partition and choose 'swapoff'. When this is done and you right-click again, you get a choice 'format to....'. Choose ext4.
Next, right-click on the new partition and click 'Information'. Save the value of the displayed UUID somewhere.
You need to manually create a mount point and and entry in /etc/fstab, such as
For ..., use the value you saved above.
Also remove swap from /etc/fstab.
Second option: add the swap partition to the ubuntu system partition
But if you want to add the space to the actual partition, then you need to boot from your ubuntu installation stick and run gparted from there (click on the applications grid at the lower left and search for gparted).
Right-click and delete the swap partition and then you can extend (resize/move) the ubuntu system partition.