I'm trying to extend partition /dev/sda5 which is logical partition under extended partition /dev/sda2.
I want to use fdisk.
Procedure should be to delete both partitions and then to recreate them with exact same starting sectors (1001470 & 1001472). It goes well until creating logical partition where minimum starting sector is bigger (1003518) than it needs to be.
$ sudo fdisk /dev/sda Command (m for help): p Disk /dev/sda: 9.8 GiB, 10485760000 bytes, 20480000 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 Disklabel type: dos Disk identifier: 0x0cd7105f Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 999423 997376 487M 83 Linux /dev/sda2 1001470 16775167 15773698 7.5G 5 Extended /dev/sda5 1001472 16775167 15773696 7.5G 83 Linux Partition 5 has been deleted. Partition 2 has been deleted. Command (m for help): n Partition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions) Select (default p): e Partition number (2-4, default 2): First sector (999424-20479999, default 999424): 1001470 Last sector, +sectors or +size{K,M,G,T,P} (1001470-20479999, default 20479999): Created a new partition 2 of type 'Extended' and of size 9.3 GiB. Command (m for help): n All space for primary partitions is in use. Adding logical partition 5 First sector (1003518-20479999, default 1003520): 1001472 Value out of range.
I have done it with parted, but it should be possible with fdisk somehow.
$ fdisk -V
fdisk from util-linux 2.27.1
3 Answers 3
Steps taken according to Gilles' answer:
$ sudo fdisk /dev/sda Welcome to fdisk (util-linux 2.27.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p Disk /dev/sda: 9.8 GiB, 10485760000 bytes, 20480000 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 Disklabel type: dos Disk identifier: 0x0cd7105f Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 999423 997376 487M 83 Linux /dev/sda2 1001470 16775167 15773698 7.5G 5 Extended /dev/sda5 1001472 16775167 15773696 7.5G 83 Linux Command (m for help): d Partition number (1,2,5, default 5): 2 Partition 2 has been deleted. Command (m for help): n Partition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions) Select (default p): e Partition number (2-4, default 2): First sector (999424-20479999, default 999424): 1001470 Last sector, +sectors or +size{K,M,G,T,P} (1001470-20479999, default 20479999): Created a new partition 2 of type 'Extended' and of size 9.3 GiB. Command (m for help): n All space for primary partitions is in use. Adding logical partition 5 First sector (1003518-20479999, default 1003520): Last sector, +sectors or +size{K,M,G,T,P} (1003520-20479999, default 20479999): Created a new partition 5 of type 'Linux' and of size 9.3 GiB. Command (m for help): x Expert command (m for help): b Partition number (1,2,5, default 5): New beginning of data (1001471-20479999, default 1003520): 1001472 Expert command (m for help): p Disk /dev/sda: 9.8 GiB, 10485760000 bytes, 20480000 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 Disklabel type: dos Disk identifier: 0x0cd7105f Device Boot Start End Sectors Id Type Start-C/H/S End-C/H/S Attrs /dev/sda1 * 2048 999423 997376 83 Linux 0/33/32 62/55/53 80 /dev/sda2 1001470 20479999 19478530 5 Extende 62/23/86 250/23/209 /dev/sda5 1001472 20479999 19478528 83 Linux 62/57/118 250/23/209
Then r(return to main menu) and w (write table to disk).
In the normal interface, Linux's fdisk applies alignment constraints to partitions. Which constraints depends on the version of fdisk. Older versions defaulted to cylinder alignment, for compatibility with older operating systems that were incompatible with LBA. When LBA was a little over two decades old, fdisk stopped catering for such ancient systems by default, and instead switched to 1MB alignment, which gives better performance on modern storage media.
In current versions of fdisk, to create partitions with any sector (512B) alignment, you need to first create the partition with the desired end point, then go to the expert menu (x
) and use the command b
to adjust the beginning of the partition (this changes the partition size, not where it ends). It does seem rather clumsy.
-
-
2@A.D. Because in that case the partition was aligned on 1MB.Gilles 'SO- stop being evil'– Gilles 'SO- stop being evil'2016年11月02日 12:16:56 +00:00Commented Nov 2, 2016 at 12:16
-
True, I tried to extend aligned partitions and it worked even without expert mode.A.D.– A.D.2016年11月02日 23:45:59 +00:00Commented Nov 2, 2016 at 23:45
Fdisk is old program, it understands only MBR partitions. I think your problem is in changed disk geometry (heads, sectors per track and tracks). After duplication data from old disk to new disk via dd command (sector to sector copy) you got partitions not aligned to start sectors of track. That is why fdisk doesn't allow you create start partition sector before first aligned to start of track sector where it was be on old disk.
You can try to change geometry of new disk in fdisk program via command in extended menu, but it's wrong way. Use parted and gparted programs instead old fdisk.
Now reading and writing speeds aren't dependent of aligning to start track sector of each partitions.
-
1Modern versions of fdisk understand GPT as well, but that's irrelevant here. The problem isn't necessarily changed disk geometry, just limitations of fdisk's non-expert interface.Gilles 'SO- stop being evil'– Gilles 'SO- stop being evil'2016年11月01日 23:00:48 +00:00Commented Nov 1, 2016 at 23:00
-
This is MBR:
Disklabel type: dos
. I remember parted complained it's not aligned so I can try to align it and then extend. I'm sure I saw same procedure done in fdisk and it was working.A.D.– A.D.2016年11月02日 00:31:40 +00:00Commented Nov 2, 2016 at 0:31