fdisk: shrinking partion - alignment problem
Hi,
I have a 500GB USB hard drive, which currently contains a single full-disk partition. I want to shrink this to 100GB. I've already shrunk the filesystem using resize2fs, and am now trying to shrink the partition. However, /dev/sdb1 is currently aligned to sector 63, but fdisk wants to align the start of the new partition to sector 2048 (see below). This disk doesn't need an MBR. Is there a way to get fdisk to stop trying to be clever and do what I'm telling it? If not, what's the best way around this? Should I go into the "extra functionality" menu, and use the b command to move the beginning of the data to 2048 (not something I've tried before)? Code:
root@rob-laptop:~# fdisk /dev/sdb |
Hopefully you have a good backup just in case.
gparted is a better tool for resizing partitions. It allows you to shrink the partition vs deleting and recreating. Newer versions of fdisk use 2048 to align with the new 4K disks and 1M boundaries. The MBR is the first 446 bytes and starts at 0. The partition table is the next 66 bytes. The disk may not have a bootloader installed but the space is still reserved unless you are not using a partition table. |
Certainly gparted is the best solution I have found - it (now) has the smarts to handle this. When this problem first started to arise some time ago, I put aside a liveCD with the older fdisk on it so I could decide how to manage things.
|
If you run fdisk in "DOS compatibility" mode ("c" command), the default starting location for the first partition will be at LBA 63 (the beginning of the second track).
Your suggestion to tell fdisk to move the starting location to sector 2048 would not work. fdisk never moves the contents of a partition. Your filesystem would still start where it does now at LBA 63, which is not where the new partition would start. |
Thanks, rknichols, the c option was what I was looking for. And thanks for confirming my suspicions about the option to move the beginning of the data.
No, I haven't backed this data up, michaelk. I like to live dangerously ;). Seriously, though, the data on here is old backups. Wouldn't have been a disaster to lose it (the important stuff is already stored elsewhere, and it would give me an opportunity to try out some file recovery tools), and would have required even more disk shenannigans to make space to back it up. You're probably right about gparted, but I find I have less trust in tools that make it easy to do something, but harder to tell exactly what is being done. |
Glad you got it sorted out. Marking this thread "SOLVED" (in the Thread Tools, near the top of the page) would be appropriate.
|
Quote:
|
Quote:
gparted is a high-level tool, and works only in high-level ways. Partition placement and size must be specified in mebibytes (power-of-2 megabytes) and decimal fractions thereof. Ever tried to figure out what decimal fraction of a mebibyte you need to enter to get a partition to start on a specific sector? (Should be easy. Let's see, with the common geometry of 255 heads and 63 sectors per track there are 7.844238 mebibytes in a cylinder, ... .) And how many digits of that fraction are needed to get it to round to the right integer? Ever tried to get gparted to move a partition whose content is opaque binary data (such as an encrypted partition)? (Hint: It won't do that.) gparted is totally the wrong tool for any forensic or recovery situation. |
All times are GMT -5. The time now is 08:11 PM. |