0

Some months ago I have installed Ubuntu 18.04.5 LTS on my new laptop, but while allocating space to the drivers, I unknowingly put 20 GB for the root filesystem partition 3 Ext4 (which now I think it's a disk where everything is going to be installed). So my question is, is there any way to increase its size without formatting it again using 70-80 GB of home ext4 space.

You can see the picture of GParted and free-h which I have attached within this question for a better understanding of my problem.

enter image description here

enter image description here

DMC-416
  • 25
  • 3
    Does this answer your question? How to resize partitions? – user68186 Nov 18 '20 at 17:09
  • You probably don't need 30GB swap. See How to decide on Swap size? for more information. – user68186 Nov 18 '20 at 17:12
  • Edit your question and show me a screenshot of gparted (not Disks) and I can make a better recommendation. What's on p7? Also show me free -h. – heynnema Nov 18 '20 at 19:32
  • @heynnema I have edited my question and per your request, i have also uploaded the gparted command screeshot. – DMC-416 Nov 19 '20 at 10:55
  • My current thinking is to (outline only): temporarily disable swap, comment out the swap line in /etc/fstab, remove your excessive p6 swap partition, resize p3, create a /swapfile, edit /etc/fstab to enable /swapfile. Have you used gparted and terminal before? I'll post a detailed answer if you accept my thinking. – heynnema Nov 19 '20 at 14:40
  • @heynnema I tried your solution and now I have reduced swap size into 5 GB but now I have another problem. P3 disk has some problem related to unallocated. Can you help me to solve it? I have attached a new picture within this question please check it. – DMC-416 Nov 19 '20 at 23:33
  • Looks like the filesystem did not grow with the partition (some partitions tools run resize2fs and some don't). You can run sudo resize2fs /dev/nvme0n1p3 yourself. – ubfan1 Nov 19 '20 at 23:45
  • @DMC-416 You can use gparteds Partition/Check to fix it, or use resize2fs as shown in ubfan1's comment. You must do this from a Ubuntu Live DVD/USB. – heynnema Nov 19 '20 at 23:49
  • @heynnema Thank you for your quick comment. I run it in the terminal and it worked like a cream. But now ubuntu has become slow compared to previous, I mean to say, it takes 3-4 minutes to restart ( I think this is bcoz of the swap. It get off automatically) and I have to select Swapon (on GParted) every time otherwise, it goes off automatically whenever I restart the pc. I ran this code (sudo chmod -R a+rwx /etc) to edit the comment of etc/fstab Any suggestion to solve this. – DMC-416 Nov 20 '20 at 00:05
  • 1
    Edit your question and show me free -h and sudo blkid and grep -i swap /etc/fstab. You shouldn't have chmod'ed /etc... sigh. I'm sure that it'll break the OS. – heynnema Nov 20 '20 at 00:18
  • @heynnema According to the man resize2fs output, an ext4 filesystem may be expanded when mounted (with any recent kernel). – ubfan1 Nov 20 '20 at 00:33
  • @ubfan1 OP already got into trouble using gparted on live partitions. That's why the FS was off in the first place. Safest way is to do it when booted to a Ubuntu Live DVD/USB. – heynnema Nov 20 '20 at 00:40
  • @heynnema This problem start to occur after I remove swap and again re-created it with a small size (while re-creating I suppose swap UUID changed to the new one and the new UUID was not automatically replaced in /etc/fstab section). After I ran sudo blkid and grep -i swap /etc/fstab as per ur suggestion, I figured out this problem. Now, I have changed the /etc/fstab swap UUID with the new one and it worked.

    Thank you for your helpful comment. It really helped me a lot.

    – DMC-416 Nov 20 '20 at 01:36

1 Answers1

0

From the comments... here's an outline of one way to resize your root file system, by deleting your swap partition, resizing /, and using a /swapfile, instead of a swap partition...

  • temporarily disable swap

    • sudo swapoff -a
  • comment out the swap line in /etc/fstab

    • #UUID=xxxx-xxxx-xxxx-xxxx-xxxx none swap sw 0 0
  • boot to a Ubuntu Live DVD/USB

    • delete your excessive p6 swap partition using gparted

    • resize p3 using gparted

  • boot back into Ubuntu

  • create a 4G /swapfile

Note: Incorrect use of the dd command 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 xG RAM and 4G swap

Confirm this /swapfile line at the end of /etc/fstab... and confirm no other “swap” lines...

To edit, use sudo -H gedit /etc/fstab or sudo pico /etc/fstab

/swapfile  none  swap  sw  0  0

reboot                    # reboot and verify operation
heynnema
  • 70,711