LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-26-2014, 03:52 PM   #1
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 97
Angry 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

Command (m for help): p

Disk /dev/sdb: 500.1 GB, 500079525888 bytes
255 heads, 63 sectors/track, 60797 cylinders, total 976717824 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x33439e40

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1              63   976703804   488351871   83  Linux

Command (m for help): d
Selected partition 1

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-976717823, default 2048): 63
Value out of range.
First sector (2048-976717823, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-976717823, default 976717823): +102G

Command (m for help): p

Disk /dev/sdb: 500.1 GB, 500079525888 bytes
255 heads, 63 sectors/track, 60797 cylinders, total 976717824 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x33439e40

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   213911551   106954752   83  Linux

Command (m for help): x
Expert command (m for help): b
Partition number (1-4): 1
New beginning of data (1-976703804, default 63):
<rant>This sort of thing does really gall me. I thought this was Linux, not Windows. I thought we were supposed to be able to have control over our systems. I mean, Linux is supposed to be the OS which says "fine, I'll delete your entire home folder without asking 'are you sure?'." </rant>
 
Old 01-26-2014, 06:47 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
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.
 
Old 01-26-2014, 07:42 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
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.
 
Old 01-26-2014, 08:35 PM   #4
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
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.
 
1 members found this post helpful.
Old 01-28-2014, 01:20 PM   #5
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Original Poster
Rep: Reputation: 97
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.
 
Old 01-28-2014, 03:39 PM   #6
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Glad you got it sorted out. Marking this thread "SOLVED" (in the Thread Tools, near the top of the page) would be appropriate.
 
Old 01-28-2014, 07:27 PM   #7
enorbet
Senior Member
 
Registered: Jun 2003
Location: Virginia
Distribution: Slackware = Main OpSys
Posts: 4,784

Rep: Reputation: 4434Reputation: 4434Reputation: 4434Reputation: 4434Reputation: 4434Reputation: 4434Reputation: 4434Reputation: 4434Reputation: 4434Reputation: 4434Reputation: 4434
Quote:
Originally Posted by Robhogg View Post
<snip>
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.
One doesn't have to preclude the other. Even old Dos-based PQMagic had the ability to drop down to "ptedit". GParted, on any decent distro, live or otherwise, should likewise have that capacity. It's not binary. One can use both. It would be a sweet feature on "Expert Mode" if it was possible from selecting a menuitem to drop right to direct edit, and simply remove the step of launching a console.
 
Old 01-28-2014, 09:28 PM   #8
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by enorbet View Post
GParted, on any decent distro, live or otherwise, should likewise have that capacity.
By that definition, there are apparently no "decent" distributions, live or otherwise.

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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem mounting a linux partion from another ext3 partion fkeith Linux - Hardware 1 10-14-2007 07:33 PM
weird fdisk problem (Fdisk unable to see winxp partitions) khidot Slackware - Installation 5 04-07-2007 09:26 PM
Shrinking RAID 1 partion on 2nd disk simonb1975uk Slackware 3 12-04-2006 06:58 AM
Shrinking and moving an lvm partition. (and random fdisk help) pardasaniman Linux - Software 2 08-02-2006 08:11 AM
is windows extended partion free space visible to linux fdisk purplesky Linux - General 1 11-12-2002 07:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration