How do I go about resizing a disk partition for Linux?

I have Ubuntu installed on an external hard drive that I can boot to. It was Ubuntu 20.04 LTS, and I was just trying to upgrade to 22.04 LTS. The ext4 partition was already mostly taken up, and the upgrade added files, so I feel like I need to extend that partition. I got errors on the upgrade, and it looks like it failed and is trying to recover. I suspect it’s the partition size(s). When I initially did the 20.04 LTS install, I decided to try doing manual partitions (to get the experience), so that’s what caused my problem. I did follow a template for recommended partition sizes, and the other ones are probably okay, but I didn’t leave myself much room for expansion on the ext4 partition. It’s a 1GB hard drive, and that Linux install is all I have on there, so I have lots of unallocated space.

It looks like I can’t do this with GParted (partition app) while running Linux. It looks like I’d have to launch GParted from CD/USB (flash drive) and “unmount” the partition before expanding it.

Does this sound right? I wanted to ask for advice on how to go about this before trying that method. Thanks!

(It looks like I might need to expand the Root partition too, as I got messages about that during the upgrade attempt)

Since you have not had an answer yet, I am going to go out on a non-expert opinion here.

First ext4 is a filesystem type, not a partition. I am assuming that you have allocated all the space to a filesystem (ext4 in this case) that is in the partition. Next assuming that you have drive space to expand the partition, you can then expand the filesystem. Much easier to do with LVM. To do that, you will need to not be booted on said partition/filesystem, so yes, a CD/USB boot. What is the mount point of this filesystem?

My advice… back up anything you want to keep, and fix it with a fresh install and reconfiguration of the partitions and filesystems. If you want to learn, back it up before doing anything at all.

2 Likes

Thanks! I welcome any ideas. Unfortunately, the OS crashed and did not recover, though I may try to boot to it again and see. But it looked pretty hopeless. I got lots of errors at the end of the install, and it seemed to be a ‘space’ issue, as I had been concerned about.

I think that’s right. I created multiple partitions and assigned a filesystem type to each one, per the instructions I was following. I noticed the ext4 (main Linux OS partition?) and the Root partition had very little space left. I shouldn’t have tried the install in that case, should have waited until I could change the partition sizes.

Thanks, I will look into LVM!

Not sure about the question. I had Ubuntu 20.04 loaded on an external hard drive that I booted to from my Windows PC. Ubuntu was the only OS on that external drive, and as I said I had numerous partitions (boot, root, home, swap, temp, etc). From my understanding, you need a small EFI partition for a Linux install, and then a much larger ext4 main partition. That’s what Linux will install on its own, from my observation (done several installs so far).

What I’ll probably do is just do a new install on that external hard drive, directly to Ubuntu 22.04 and bypass the upgrade process. I’ll also probably just let the Linux installer figure everything out (wipe the drive and create its own partitions). That one drive is the only one I tried custom partitions on. Other installs work fine and haven’t had this issue.

I think what I learned is that for the main ext4 partition, as well as the Root partition, ~20GB is too small (again, that’s what the instructions suggested). They both were running out of space, and the upgrade to 22.04 put a nail in the coffin.

Please correct any of my ideas or lingo here. While fairly tech savvy, I’m still learning Linux and its file system attributes. I previously used Windows for years, as well as MacOS for quite awhile.

You can boot from the USB/CD, and then mount the filesystem(s) very likely, even if it won’t boot.
Typically your hard filesystems (not tmpfs which are in memory), would be /boot, / (root), and /home if you did that separate. There could also be /recovery. Linux cannot run if / filesystem is full. You might be able to clear out files in /var/log and get some space enough to boot. Could be a good learning exercise.

Best learning experiences!

2 Likes

Thanks for the advice!

Do you mean boot to a ‘live’ version of Linux (on USB) to do that? Or LVM (on USB)? It seems to me that I could do what you’re describing with a ‘live’ version of Linux running. I don’t quite understand “mount the filesystem(s)” though. I understand mounting and unmounting drives (like USB, hard drive).

By ‘live’, I mean boot from a CD/USB, that also has the disk that linux is on that you with to repair (meaning connected to the same computer, but on a different port). The steps may be different, but yes, same as mounting/unmounting drives. The difference is that your ‘drive’ has multiple partitions, and filesystems are on those partitions. For instance, your USB drive (broken) could have say /dev/sda1 as /boot, and /dev/sda2 as / (eg root), and even a /dev/sda4 as /home. Just examples, yours are very likely different.

Perhaps these links will give you some ideas:
https://www.quora.com/How-do-I-mount-a-hard-drive-in-Ubuntu-live-CD
https://docs.intuitivetechnology.com/article/92-how-to-mount-linux-filesystem-from-a-live-cd-and-copy-a-backup

Once you have that mounted, you can do anything you want, including backup of files if you have a place to put them. You have access just as if it was running on that partition.

1 Like

Thanks, I just learned something! :slightly_smiling_face: I got familiar with things like /dev/sda1 etc by playing around with the Gparted app. I think I understand that partitioning nomenclature fairly well. Your explanation is very helpful! And those articles look like they’ll be very helpful also.

So it sounds like the partition is mounted just like an external disk would be. I can probably figure that out when I get in there. I didn’t have any files on there I need to save, as they were already backed up. I’d just want to restore the system to being bootable again.

1 Like

Yes, it would be mounted just like if you plugged in a USB stick. Actually, you can partition a USB stick… :smiley: Something for another day…

It is one of those you can use it to learn something. Once you are ready, just wipe it and rebuild. You could even rebuild at 20.04, and then upgrade, if you wanted that experience. I keep a bunch around just for playing, in virtual machines and on Raspberry Pi cards, just for the fun of it.

1 Like

I already did that upgrade on my main Linux computer (Mini-PC), and it was fairly painless, so I was pretty happy to experience that. This install was almost like a dual-boot with Windows on another computer, except it’s an external hard drive. I’ve been hesitant to do dual-boot on my Windows system drive, as I still depend on Windows for some things. I could possibly install Linux on the secondary (data) internal hard drive on that Windows computer, so that remains an option.

The external hard drive Linux boot worked nicely though, till I crashed it. :roll_eyes: The only thing was I couldn’t Suspend it (properly), being external to the system hardware.

I hope to get into Virtual Machines soon, and create a Windows setup on one, so I can move away from the existing Windows computer. I still like Windows 7, but it’s obviously aged and increasingly unsupported.

UPDATE: I took a look at the partitions on that external hard drive with the failed Ubuntu upgrade, using GParted on a ‘live’ version of Ubuntu 22.04 running. The main ext4 partition (the one that grows with installed software) was totally maxxed out. The boot partitition was too IIRC. The main ext4 partition size was like 18-20GB. The upgrade filled it up and crashed it

So instead of messing with the partitions, which I assumed were beyond repair, I just wiped and installed Ubuntu 22.04 from the ‘live’ session. That had been the target of my upgrade, so I just went straight to it. It did take several hours to copy all my configurations over for browser, email, installs, etc. I’m happy with 22.04, it seems to be working great.

1 Like