Lately my root partition is running out of space which is causing me problems, and I constantly have to free some space in order to avoid it. After 2-3 days my root partition gets full again. The only solution that i find is to increase the size of my root partition, but as a newbie on Linux systems I am afraid of data loss. My laptop has dual boot of Windows 10 / Ubuntu 18.04. Is there any way that I can use the unallocated space that I created here in order to extend the root partition?
-
No, as i will have to move the unallocated space next to the root partition and i am not sure how to do that and where to move it – Christos Theofilou Aug 24 '21 at 17:49
-
1You don't "move" unallocated space. You 1) delete your probably too small swap), move your root left to start at the start of the unallocated space, then extend it right (leaving enough room for (a bigger?) swap. – ubfan1 Aug 24 '21 at 18:18
-
1You did not make your root partition big enough. 25 GB has been the recommended minimum for Ubuntu Desktop since 2017. Because you let your file system completely run out of space several times, you will probably have to reinstall the system. You might be better off not creating a separate home partition as you've just discovered why overpartitioning creates rigid and arbitrary limitations on how your system can make use of your space. Due to the cumbersome way you've arranged these partitions, moving/resizing is going to be extremely difficult. – Nmath Aug 24 '21 at 18:24
-
1FYI, you don't need a swap partition either. If you don't make a swap partition, your system will use a dynamically sized swap file. The partition size you chose for swap is also not really big enough to be useful. This partition scheme is unviable and is overly partitioned. I would recommend a single partition for the entirely of Ubuntu. Delete (erase) partitions 5, 6, and 7 and reinstall Ubuntu to the much larger unallocated space at the end of the drive after your NTFS partition. You will avoid all of the problems you created this time by overpartitioning / incorrect partitioning – Nmath Aug 24 '21 at 18:28
-
@Nmath "If you don't make a swap partition, your system will use a dynamically sized swap file"... who told you that? Not true. – heynnema Aug 24 '21 at 19:14
-
@hennema See: https://askubuntu.com/questions/904372/swap-partition-vs-swap-file - The size of a swapfile can be easily changed. The size of a swap partition cannot – Nmath Aug 24 '21 at 19:26
-
@Nmath I'm totally aware of the difference between a swap partition and a /swapfile. My issue was with your statement that 1) made it sound like this was an automatic switchover, and 2) that the /swapfile is dynamic... it's not... it's a fixed size... to whatever size it was created with. – heynnema Aug 24 '21 at 19:35
-
@heynnema if you are hung up on the word "dynamic" consider that I am specifically talking about swapfile creation during system installation which is in fact dynamically sized at that time based on system resources. I am not talking about it automatically changing sizes after it is already set up. A swapfile is overwhelmingly more flexible than a swap partition, which is my entire point – Nmath Aug 24 '21 at 19:53
-
@Nmath re: "swapfile creation during system installation which is in fact dynamically sized at that time based on system resources"... I'm not sure that this is correct either. My observation is that this is not dynamic either... it ALWAYS creates a 2G /swapfile (which is ALWAYS too small), no matter how much RAM there is. I know what you were trying to say... my only disagreement what was implied... or what the thinking behind your understanding was. Peace :-) – heynnema Aug 24 '21 at 22:18
1 Answers
We'll repartition your disk, as requested, but also convert you from a (too small) swap partition, to a /swapfile.
Note: Pay close attention to these instructions.
Make sure that you have a good backup of your important Ubuntu files, as this procedure can corrupt or lose data.
DISABLE CURRENT SWAP PARTITION
sudo swapoff -a
sudo -H gedit /etc/fstab
Comment out the swap line that looks similar to this...
UUID=xxxx-xxxx-xxxx-xxxx none swap sw 0 0
Save the file and quit gedit
.
REPARTITION
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
- set swapoff on /dev/nvme0n1p5
- delete the /dev/nvme0n1p5 old swap partition
- move /dev/nvme0n1p6 partition all the way left
- resize /dev/nvme0n1p6 right side all the way right
- click the Apply icon
- quit
gparted
and reboot the computer
CREATE /swapfile
Now we'll create a fresh new /swapfile...
Note: Incorrect use of the rm
and dd
commands can cause data loss. Suggest copy/paste.
In the terminal
...
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 xxG RAM and 4G swap
Edit /etc/fstab, using sudo -H gedit /etc/fstab
or sudo pico /etc/fstab
.
Add the following /swapfile line in /etc/fstab... and confirm no other “swap” lines... use SPACES in this line... confirm NO TABS...
/swapfile none swap sw 0 0
Then reboot and verify operation.
RECOMMENDATION
Reducing the size of the /dev/nvme0n1p7 partition, and creating a new NTFS partition, that can be used for sharing files between Windows and Ubuntu.

- 70,711
-
Thank you very much. This was exactly the answer I was looking for, as a new user on Linux. Worked perfectly. – Christos Theofilou Aug 25 '21 at 08:06