1

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?

2 Answers2

1

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
heynnema
  • 70,711
  • I tried the 2nd-way using Ubuntu Live USB in "Try Mode" and it solved my issue – Prince Kukreja Sep 09 '20 at 20:33
  • No, you needed to follow ALL of my instructions EXACTLY. You can't start 1/2 way in. You don't need a 6G swap partition. If you followed my instructions, you'd now be using a /swapfile for swap, not a disk partition. – heynnema Sep 09 '20 at 23:10
0

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.

Siep
  • 121
  • Hm..., I didn't know "sudo gparted" still worked. Hasn't it been reworked years ago? Also, this doesn't seem to answer the question. – mikewhatever Aug 28 '20 at 20:08
  • 'sudo gparted' works fine on my admittedly non-standard 20.04 system. I added an explanation how to add the space to the ubuntu partition. – Siep Aug 28 '20 at 20:31
  • Not really supposed to use gui apps with sudo. Things get saved into roots /home, not user's /home. It used to be gksudo, pkexec or sudo -H. Not sure what is best, but you can just run gparted by selecting in gui menu. But cannot change mounted partitions and must also update fstab to remove swap entry. Use live installer to change partitions which has gparted as part of its default apps. – oldfred Aug 28 '20 at 21:13
  • @oldfred: Incorporated these into my answer. – Siep Aug 28 '20 at 21:34