Ubuntu – “Misaligned partition” – Should I do repartition (how?)

dual-bootpartitioningwindows 7

Tried to install Ubuntu 12.04 from USB-stick alongside the existing Win7 OS 64bit, and now I'm not sure if install was completely successful: Disk Utility tool claims that the Extended partition (which contains Ubuntu partition and Swap) is "misaligned" and recommends repartition. What should I do, and if should I do this repartition, how to do it (especially if I would like not to lose the data on Win7 partition)?

Background info: A considerably new Thinkpad laptop (UEFI BIOS, if that matters). Before install there were already a "SYSTEM_DRV" partition, the main Windows partition and a Lenovo recovery partition (all NTFS). Now the table looks like this: SYSTEM_DRV (sda1), Windows (sda2), Extended (sda4) (which contains Linux (sda5; ext4) and Swap (sda6)) and Recovery (sda3). Disk Utility Tool gives a message as follows when I select Ext: "The partition is misaligned by 1024 bytes. This may result in very poor performance. Repartitioning is suggested."

There were couple of problems during the install, which I describe below, in the case they happen to be relevant.

Installer claimed that it recognized existing OS'es fine, so I checked the corresponding option during the install. Next, when it asked me how to allocate the disk space, the first weird thing happened: the installer give me a graphical "slide" allocate disk space for pre-existing Win7 OS and new Ubuntu… but it did not inform me which partition would be for Ubuntu and which for Windows. ..well, I decided to go with the setting installer proposed. (not sure if this is relevant, but I guess I'd better mention it anyway – the previous partition tools have been more self-explanatory…)

After the install (which reported no errors), GRUB/Ubuntu refused to boot. Luckily this problem was quite straightforwardly resolved with live-Ubuntu-USB and Boot-Repair ("Recommended repair" worked just fine). After all this hassle I decided to check the partition table "just to be sure"- and the disk utility gives the warning message I described.

I checked my disk specs on Hitachi/HGST website, and yes, it's Advanced Format ("Advanced Format, 512-byte emulation").

Also, fdisk gives me the following:

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048     3074047     1536000    7  HPFS/NTFS/exFAT
/dev/sda2         3074048   523241959   260083956    7  HPFS/NTFS/exFAT
/dev/sda3       939907072   976771071    18432000    7  HPFS/NTFS/exFAT
/dev/sda4       523243518   939907071   208331777    5  Extended
Partition 4 does not start on physical sector boundary.
/dev/sda5       523243520   932153343   204454912   83  Linux
/dev/sda6       932155392   939907071     3875840   82  Linux swap / Solaris

Apparently sda4 (extended) partition is off by 2 bytes (sda4 starts on 523243518, sda5 523243520), but if I understood correctly, this should not be a problem, as the logical partition sda5 seems to be OK(?). In other words, there should be no need for repartitioning?

Best Answer

There's two issues usually involved here. I think the main problem is that the physical sector size on the disk might be (say for example) 4096 bytes whereas the logical sector size is usually 512 bytes. Where the start of the partition is not at the beginning of the physical sector a discrepancy occurs with how the disk is read. This can mainly cause a performance problem on some machines with some drives. I don't believe it will actually cause any loss of data or similar problems, however I'm not a disk drive engineer.

The second issue is that Linux disk utilities and the ext file system in general seem to assume that partitions should line up with the cylinders on the hard drive. I've seen it written that if a cylinder extends past a cylinder boundary and the next partition starts in the same cylinder, data corruption could result. Sorry I've got no firm reference on this and google seems to be finding anything but information on cylinder alignment, but it had something to do with ext2/3/4 assuming that it could write to the end of a cylinder under certain circumstance.

Usually, I set up partitions with Gparted before I start the installation (gparted is on the LiveDVD) and then select how I want to use the partitions manually by selecting "do something else" when I get to that part of the installation. It's usually later that I realise that Gparted has left a few MB of unused space either at the end of the drive, or if I've set up the whole drive with Gparted, right at the end. Here's the exact example of the drive that I'm on at the moment. Note that I have two boot partitions of about 20Gb, with a the rest of the drive being an extended partition containing the swap partition and /home. Note the 2Mb of unallocated space right at the end of the extended partition. This was Gparted's doing, not mine. I've seen other disks that (for example) might have some unallocated space beteen the primary partitions or before the extended partition because the partitions were created at different times and with different programs.

Gparted screen

Since it is only a few MB, and after reading the information about the potential problems, I usually let it be. If Gparted wants to take a belt and suspenders approach I'm quite happy to let it do so.

I suggest you boot off the LiveDVD/USB again and just resize the ext4 partition Ubuntu is on with Gparted. I think you'll find that Gparted will try to align the partition with the cylinders, and this should solve the problems for you. Don't bother re-installing unless the resize breaks the Linux boot in some way.

During my google searches I did find information about Gparted aligning to full MB figures, but this is not my experience. The amount of space left is more like a cylinder's worth, rather that something that denotes MB boundaries.

Related Question