Linux disk partitioning

Is anybody here clever with Linux? I’m not so clever and I’m having trouble with disk partitioning. Any help would be appreciated.

Anyone who can help will probably need more information. Exactly what partitioning are you trying to do? Partitioning a space on your Windows drive to also install Linux? Asking about the best partitioning scheme for Linux? Learning how to partition a USB flash drive so you can put the installer on it? Learning how to use gparted, the main paritioning tool in Linux?

There are lots of things your post can mean, so you’ll need to be more specific about what you are trying to do.

Also, what trouble are you having? A specific error, or general unease with the process?

Unless you have very specific requirements. I would advise to let the installer do its thing and don’t worry about it.

If you tell us how many partitions you want, how big you want them, and what they’re supposed to be for, then we can help you. Also if your drive has existing partitions or data that needs to be preserved, or if it’s factory-new.

One acceptable answer is “idk why, the installer is just asking me to do this unfamiliar-sounding thing.” I had the same question the first time I did it. But helpful specifics are needed for a helpful answer.

I’m not so sure. One possibility is that they are talking about installing Linux on a drive that already has Windows on it. I would not recommend allowing the installer to try and resize the NTFS partition. It’s better to do that from within Windows beforehand.

Yes, there are lots of people here that can help, but we need much more detail.

Since the OP never came back, maybe you all can help me out. I’ve got an old Dell laptop running Ubuntu that I want to repartition. The laptop has a 250GB hard drive, the primary partition is 100GB with Ubuntu 16.10 which for one reason or another won’t boot properly anymore. The secondary partition, running Ubuntu 20.04, uses up the other 150GB. Basically I’d like to get rid of the 16.10 OS on the primary and repartition so that my 20.04 OS is on the primary and has access to the entire 250GB.

I’ve taken the first couple steps, backed up the laptop and created a bootable thumb drive. I just have no clue what to do once I boot up and open GParted.

Please check first what is the current partitioning scheme? Just two partitions, or are there any EFI partitions, swap partitions, logical volumes, etc? And what filesystems are in use?

This is the info from the “Disks” utility.

Partition 1 - Filesystem - 101 GB Ext4
Device: /dev/sda1
Partition type: Linux (bootable)

Partition 2 - Extended Partition - 149 GB
Device: /dev/sda2
Partition Type: Extended Partition

And then it looks like Partition 2 is split into two parts:
Partition 5 - Swap - 8.6 GB
Device: /dev/sda5
Partition Type: Linux swap

Partition 6 - Filesystem - 140 GB Ext4
Device: /dev/sda6
Partition Type: Linux

This is the one hard drive tango version of doing it. I would do it this way, but I’m an old greybeard with decades of experience doing this kind of thing. You very well could lose data if you make a mistake. For that reason, there are no copy/paste commands in this post.

You don’t want what is on sda1, but it is much easier to expand a partition from the end than from the beginning. This will only work if sda6 has less than 100GB of data on it.

  • Reformat sda1
  • Copy everything on sda6 to sda1
  • Edit the files on sda1 so they know root is sda1, update the bootloader and associated config files.
  • Make sure that is working and you can boot to 20.04 off sda1.
  • Delete partitions sda6 sda5 and sda2.
  • Resize sda1 to -8.6GB of the end of the drive.
  • Add sda2 at the end.
  • Grow the filesystem on sda1 to use new available space.
  • Setup swap on the new sda2.

Not insane way of doing it:

  • Backup the files on sda6 to an external device.
  • Reformat the drive the way you want it.
  • Restore the files to the new partition.
  • Edit the files on the new partition so root is sda1 (or whatever) and reinstall the bootloader and update its config

Noob way of doing it:

  • Copy home directory and other important files off sda6 to an external device.
  • Install from scratch 20.04 (or 20.10?) on the drive, using the whole thing and partitioning it to the defaults.
  • Copy your home directory and other files back.

Always make backups.

Thanks for the detailed instructions. Apparently I was thinking about this in my sleep because I woke up in the middle of the night thinking, I already took a full backup, why not just reformat the entire drive, install from the thumb drive, then restore my backup? Which I think is more or less your “noob” directions.

The upside is that if I totally botch this, it’s no huge loss. I mostly use this laptop for ripping vinyl to mp3 with Audacity, playing Dwarf Fortress, and doing some personal software development projects. And it’s not like I’m running out of room and desperately need that extra drive space, it’s mostly a nice-to-have.

And while your at it, add these steps:

  • remove your HDD
  • install a SSD

Good thing you have up-to-date backups, which you should have anyway; that way it will not matter if you screw something up!

What I might add to @echoreply 's explanation is, GParted automates many of these operations. Meaning, from the GUI you can select deletion of Partition 1 and Partition 2, may as well delete the Swap partition too (you can just use a swap file instead, or recreate the partition later if you feel like it, see eg here), then “Resize/Move” your current /dev/sda6 to start at the beginning of the disk and take up maximum size.

After that you may have to edit the root and swap settings and update the bootloader.

Ubuntu 20.04 is supposed to be a “LTS” release, so there is no rush to update it (unless you want); support continues until 2025.

The only thing I know about *nix is how to spell it. So I ask the assembled experts here:

What advantage is there to having a swap partition versus a swap file in an ordinary partition also holding programs and data files? If it’s all one physical disk it’s not like you’re creating a contention-free path to the hardware.

It prevents fragmentation. If it’s just a file, then the different parts may get stored in different places on the disk. But if it’s a partition, all the parts are guaranteed to be contiguous. This can make the swap work a bit faster. The tradeoff is that it can’t be easily resized if you run out.

In practice, it often doesn’t matter much. The swap file will be made when there is plenty of room on the disk to keep the file contiguous. And then, as long as the file doesn’t get resized, it won’t ever become fragmented. And, if it does get resized, the OS will try to keep it from being fragmented enough to cause slowdown. And this will only fail if the disk is getting really full.

Plus, of course, most people are moving to having at least the OS on an SSD for the speedup. And fragmentation doesn’t matter much on an SSD. There are no physical parts having to jump around to all the different parts, and the controller naturally tries to keep things contiguous enough as part of wear leveling (keeping the drive from wearing out from too many writes).

It is possible to hibernate to a swap partition, but not to a swap file. Or rather, the filesystem containing the swap file must be mounted before the swap file can be read, but a system can’t be restored from hibernation if one of the filesystems is already mounted. (There are exceptions and ways around it, but really, just use a swap partition, it will be easier for everybody.)

In the long ago times, a swap partition was also much faster than a swap file on Linux, but I don’t think that has been the case for a long time.

And if you’re actively paging in and out of swap, buy more memory or close a few tabs.

Yeah, my understanding is that it hasn’t been true since the 2.4 kernels.

Yeah. We used to have customers who would complain that we would max out swap partitions at 8GB or so. Our response was “You’re not going to wait for it to churn through half of that swap. You’re going to call in and have the noc tech reboot the box long before that happens.” Most customers understood our line of thinking.

And hey! I learned something from this thread. I never thought about resuming from swap file being impossible. Servers don’t normally go into hibernate mode, and all my laptops have just gotten a partition out of habit.