2

I have a hard drive which is encrypted using LUKS. It was originally an external hard drive. Recently I removed the casing and connected it directly (via SATA). However, when I connect it directly, I'm unable to view the partition, and it doesn't prompt for the password. Out of 4 TB, it shows an unknown partition of 500GB and free space of 3.5TB.

I removed it from the system and connected it as an external hard drive again, and ubuntu detects the partitions, and prompts for the password.

Also, the partitioning is shown as MBR, when in reality it is GPT

1

It's probably a problem with the sector size. Some USB enclosures claim their drives have 4KiB sectors, when the drive represents itself as 512 byte sectors or vice versa. Partition tables (both msdos and gpt) unfortunately depend on the sector size. If the sector size changes, the partition table becomes invalid.

Now, this is a problem that could be solved in software - Linux could be made smart enough to interpret a GPT partition table correctly, regardless of the physical sector size the drive claims to have. But it doesn't do that, and it's probably not part of the standard, so ...

What you need to do is get the exact byte offsets of your partitions while in the USB closure

parted /dev/usbdrive unit b print free

and then see if those partition offsets work for the internal drive

losetup --find --show --read-only --offset 1048576 /dev/internaldrive
file -s /dev/loopX

and if that works out okay, re-create the partition table with the same (byte) offsets for the internal disk (make a backup of the first/last few megabytes of the disk first)

parted /dev/internaldisk unit b mklabel gpt mkpart 1048576 42424242 ...

I don't know if there is a partitioner that is smart enough to 'repair' such wrong-sector-size partition tables automagically. It would beat the manual approach but ...

  • This looks like it would work, however, I have another 4TB disk lying around, so I'm going the safe route for now. I'll try your method after I finish backing up. – kiranmathewkoshy Dec 11 '15 at 4:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.