@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?
-
3Does this answer your question? [swap partition vs swap file](https://askubuntu.com/questions/904372/swap-partition-vs-swap-file) – Nmath Aug 28 '20 at 19:33
-
Do you still need help with this? If so, I'll put together a detailed answer for you. Why did you set swap at 127G? Do you have a Ubuntu Live DVD/USB? Edit your question and show me `free -h` and a screenshot of `gparted`. Start comments to me with @heynnema or I'll miss them. – heynnema Aug 29 '20 at 00:45
-
@heynnema I have edited the question! – Prince Kukreja Aug 29 '20 at 11:34
-
Status please... – heynnema Aug 29 '20 at 16:24
-
Status please... – heynnema Aug 30 '20 at 22:19
-
@heynnema I haven't tried the solution yet. Will update you soon once I test it. Btw, thanks for the answer ) – Prince Kukreja Sep 01 '20 at 19:06
-
@heynnema I have tried your solution(2nd one). Thanks for the solution. 1 more question. I have left 6GB of unallocated space for the SWAP partition. How to make the SWAP partition? – Prince Kukreja Sep 09 '20 at 20:25
-
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
-
Status please... – heynnema Sep 10 '20 at 13:57
-
@heynnema How can I fix this? How to make a swapfile instead of a disk partition! – Prince Kukreja Sep 12 '20 at 12:17
-
Did you read my previous comment? **You need to follow ALL of my instructions in my answer EXACTLY. You can't start 1/2 way in.** – heynnema Sep 12 '20 at 14:36
-
sudo swapoff -a swapoff: cannot find the device for UUID=52a6f33f-f94e-4b4d-8b8f-1d31b491c889 @heynnema – Prince Kukreja Sep 12 '20 at 14:48
-
That error occurs because you didn't follow my instructions the first time. Ignore the error and do the rest of my answer. – heynnema Sep 12 '20 at 14:50
-
Status please... – heynnema Sep 12 '20 at 17:16
-
@heynnema It's working great now! Thanks! – Prince Kukreja Sep 12 '20 at 17:18
2 Answers
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
- 68,647
- 15
- 124
- 180
-
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
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.
- 111
- 7
-
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
-

