0

I have these partitions:

  • /dev/sda1: Linux distribution 1 (50GB)
  • /dev/sda2: Linux distribution 2 (13GB)
  • /dev/sda3: Linux swap (2GB)
  • /dev/sda4: Backup (2GB)
  • 398 GB of free space

My distribution 2 is full of archives that I don't have space anymore. I need to resize the partition in order to be able to use the system properly. But, this would seem not possible, for I cannot resize the partition. It has a maximum size, but this maximum size is the actual size. I cannot set 15 GB, for example. What can I do? The partitions are MBR and I would like to use fdisk, cfdisk or parted, but other programs are welcome but the GParted, for I'm facing an issue running it.

$ fdisk -l
Disk /dev/sda: 465.78 GiB, 500107862016 bytes, 
976773168 sectors
Disk model: WDC WD5000LPVT-0
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x6c9f0ca0

Device     Boot     Start       End   Sectors  Size Id Type
/dev/sda1  *         2048 104859647 104857600   50G 83 Linux
/dev/sda2       947914752 976773167  28858416 13.8G 83 Linux
/dev/sda3       943720448 947914751   4194304    2G 82 Linux swap / Solaris
/dev/sda4       104859648 109053951   4194304    2G 83 Linux

Partition table entries are not in disk order.
4
  • 1
    To beginners, I always recommend gparted as it is most easy to use. Also, it is relatively safe to use. Can you elaborate on why you cannot use gparted?
    – Hermann
    Commented Dec 18, 2020 at 21:34
  • Please add fdisk -l output to your question, it's hard to say where the free space is without it. If you want to resize a partition, the free space must be directly after it, if it is at the end of the drive, you'll need to move the other two partitions first (and that's way easier with GParted). Commented Dec 18, 2020 at 21:36
  • Hermann, Gparted says Gtk Warning: cannot open the display. Plus, before this warning, 5 times Unit \xe2\x97\x8f.service does not exist, proceeding anyway. Then, unable to init server: Could not connect: Connection refused.
    – Gabriel
    Commented Dec 18, 2020 at 21:58
  • Vojtech Trefny, question updated.
    – Gabriel
    Commented Dec 18, 2020 at 22:10

1 Answer 1

1
  1. You cannot do this from inside the operating system you're on, because you will need to perform operations on /dev/sda disk as a whole, and certain partitions will continue to be mounted, thus preventing you from applying some operations.

  2. What you need is a USB with a liveLinux on it. There are many choices, but Gparted is practically tailored for this particular operation. The Gparted liveUSB can be found here : GParted Live

  3. When you boot from your USB, your hard disk will be separated from the currently running operating system, likely on /dev/sdb1 with /dev/sdb corresponding to the storage of the whole USB. This will allow you to unmount all /dev/sdaX partitions.

In a perfect world, you would normally backup all of your partitions before these steps. This being said you should at the very least backup any important files you have on /dev/sda4 BACKUP partition. You will have to move all of the data that's there to other sectors on the drive. If something happens during the process (power outage) you may lose a couple of files (you wont lose the whole partition unless your computer catches on fire or something).

  1. Next, using the Gparted GUI for example, you will rearrange and resize the partitions.

    • MOVE the /dev/sda4 BACKUP partition towards the end of the hard drive space ( I would also increase its size while you are at it, as using only 2GB for backup space is plain silly). This will now create a gap of unallocated space between /dev/sda4 and /dev/sda3.

    • Afterwards, MOVE /dev/sda3 SWAP closer to the new location of /dev/sda4.

    • APPLY the previous operation before moving on and touching /dev/sda1 and /dev/sda2.


After this operation completes successfully you should have something like the following:

/dev/sda
  /dev/sda1 [50GB]
  /dev/sda2 [13GB]
--- Unallocated Space [390GB] ---
  /dev/sda3 [2GB] 
  /dev/sda4 [10GB]

  1. Now, finally you can extend your /dev/sda2 partition into the neighboring unallocated space. You can make it as large as ~400 GB if you wish, or you can leave some extra space at the end, and also extend-backwards your SWAP partition at /dev/sda3 if you so choose.

  2. Once you choose the new size of /dev/sda2 , hit APPLY and wait for the final step of the process to finish. It should not take too long because any moving of partitions had already been completed in step 4, and here you will only be extending the region belonging to /dev/sda2


Actually here is a perfect guide of how to do this with images: Gparted Partitions

3
  • Thanks for answering. I was trying to resize sda2 on sda1. But, unfortunately, it'll be hard for me to get a Live Linux. Is there a way to boot a system from something like a virtual hard drive? Or, can I create a new partition and transfer the data from sda2 to it? Will the system be the same?
    – Gabriel
    Commented Dec 19, 2020 at 0:23
  • Actually, if your linux distributions are separate OSs then you should try to boot into Linux 1 at /dev/sda1 first. Then attempt to unmount all of the other drives, starting with sudo umount -a /dev/sda4. If this succeeds then you will be able to MOVE it with Gparted. If it does not unmount, find whats holding on to it with lsof, and try to kill this process to free the partition. Once you successfuly move /dev/sda4 you can then do the same to SWAP, again leaving the unallocated block of free space, which /dev/sda2 will now be able to expand into.
    – NetIceCat
    Commented Dec 19, 2020 at 3:49
  • Thanks to everybody for helping me, but I have created a new partition with 100 GB and installed the operating system. Now, everything's fine here, better than yesterday. I would like to ask for some moderator to close this topic, for I don't know how to do it.
    – Gabriel
    Commented Dec 19, 2020 at 15:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .