Saturday, July 2, 2016

linux - Why does fdisk have a discrepancy in translating units between cylinder and sectors?



We were re-partitioning a virtual disk to increase the size of an LVM's physical volume.



This is how we initially performed this:



$ fdisk /dev/sdb
# delete partition
fdisk> d

? 1
# create new partition
fdisk> n
? p
? 1
first cylinder? [ENTER]
last cylinder? [ENTER]
# set LVM type
fdisk> t
? 8e

fdisk> w


This led to the LVM not being recognized by Linux. I was puzzled and looked at a backup. The partition tables both started at 1 so that didn't seem like the problem. However, if I changed units (fdisk command u) from cylinders to sectors, I noticed that the backup begun at sector 13 but the new partition started at sector 128.



When we corrected the beginning of the partition, everything went fine.



Can't get my head around the discrepancy in the conversion of units. Can someone help me understand?


Answer



fdisk is an old tool, and uses the oldstyle cylinder schema be default. This will be calculated based on the fake cilinder/track/head data provided by the firmware of the hard disk. Most tool (since the existence of the LBA partitioning) doesn't have anything with it to do.




You can switch to sector-based mode with it with the command u .



Your partition table was probably generated by another tool (probably by a repartitioning feature of an installer), which used this sector-based partitioning by default.



Gpart, parted and yet a lot of tools does this better, although none of them have the pure clean precision of the old fdisk.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...