2

I keep reading that to merge two partitions, they must be adjacent. But I haven't found any definition of the word "adjacent" in this context. How do I tell whether two partitions are adjacent?

JEG
  • 201
  • 2
  • 12

3 Answers3

9

First of all, you cannot merge partitions. You can delete one, and resize the other to use the now-free space additionally.

enter image description here

In this picture, the partitions hda1 and hda3 are adjacent, they could be "merged" by, e.g. backing up the data on hda3, deleting this partition, which would result in 7GiB of unallocated space between hda1 and the extended partition hda4 and the loss of all files in hda3. Now, one could resize hda1 to use this free space, too, and then put the files back on there.

hda1 and hda4 are not adjacent, as there is a partition in between.

s3lph
  • 14,314
  • 11
  • 59
  • 82
  • Also, note that doing as the_Seppi suggests will result in the loss of all data on /dev/hda3 -- after all, it's been deleted before /dev/hda1 is expanded. If you truly want to merge two partitions (which to my mind implies preserving the data on both), you must copy the data from one to the other before deleting the one and expanding the other. As a side note, many people talk about "unallocated partitions," but that's an oxymoron -- a partition is, by definition, allocated space. Unallocated space is, also by definition, not partitioned. – Rod Smith May 17 '15 at 15:50
  • @RodSmith is it possible to allocate free space by removing hda1 and resizing hda3 ? (not to remove data that is in dha3) – grep Jun 18 '19 at 05:10
  • 1
    @grep, yes; however, that's a more involved operation. Filesystems are typically defined relative to their start points, and deleting hda1 and expanding hda3 (in this specific example) necessarily involves changing the start point of hda3. Essentially, after hda1 is deleted, hda3 will be moved and then expanded. Tools like GParted will take care of the details, but the operation will take more time and be more risky than one that involves moving only the endpoint of a partition/filesystem. – Rod Smith Jun 19 '19 at 13:01
5

"Adjacent" means "right next to", so, if your partitions (called A, B, C, and D for this explanation) are physically laid out on the disk like this:

AAAAAAABBBBBBBCCCCCCCDDDDDDD  

the, A and B are adjacent, B and C are adjacent, C and D are adjacent. No other pairs are adjacent. "Only adjacent partitions can be merged" makes sense when one considers how merging A and B happens, giving

AAAAAAAAAAAAAACCCCCCCDDDDDDD   

You can tell by looking at gparted's display - if the partitions are next to each other, then they ARE adjacent.

waltinator
  • 36,399
2

This image may make it a little clearer:

enter image description here

Partitions are physically next to each other on a hard drive, like this:

enter image description here

So you can't just make green and purple into one partition. You first have to make them next to each other, then swap them. These are the steps the computer does:

  1. Remove Red (free space)
  2. Remove Green (free space)
  3. Add Red (if wanted, at center)
  4. Stretch purple (make the free space the same format, e.g. ext4)

The grey (unallocated) at the end of my image can't be part of /dev/sda1 because there is /dev/sda5 in the way.

Tim
  • 32,861
  • 27
  • 118
  • 178
  • 1
    If you want to keep the red partition, I think you'd have to remove green, copy red into the space previously occupied by green, remove the old red, and then move and expand purple. – David Z May 17 '15 at 05:32
  • @DavidZ yes, assuming red fits into green. – Tim May 17 '15 at 07:50