Score:0

How to extend my root partition?

ng flag

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?

Screenshot of partitions

Christos Theofilou avatar
ng flag
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
cc flag
You 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.
Nmath avatar
ng flag
You 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 avatar
ng flag
FYI, 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
heynnema avatar
ru flag
@Nmath *"If you don't make a swap partition, your system will use a dynamically sized swap file"*... who told you that? Not true.
Nmath avatar
ng flag
@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
heynnema avatar
ru flag
@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.
Nmath avatar
ng flag
@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
heynnema avatar
ru flag
@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 :-)
Score:1
ru flag

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.

Christos Theofilou avatar
ng flag
Thank you very much. This was exactly the answer I was looking for, as a new user on Linux. Worked perfectly.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.