I have an ubuntu desktop system (VM guest), whose partitions were created by the install media. I wanted to expand the disk, so I shutdown the guest, and increased the disk size of the guest in the host. Now I need to expand the partitions in the guest - and here's the problem:

If I print the original table, this is what I get:

$ sudo fdisk -l /dev/sda

Disk /dev/sda: 37.6 GB, 37580963840 bytes
255 heads, 63 sectors/track, 4568 cylinders, total 73400320 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

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      499711      248832   83  Linux
/dev/sda2          501758    41940991    20719617    5  Extended
/dev/sda5          501760    41940991    20719616   8e  Linux LVM

In the past, whenever I've needed to expand a partition, I would delete and recreate the partition with the same type, and the same start, but different end. It's not working this time:

Command (m for help): d
Partition number (1-5): 5

Command (m for help): n
Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (503806-41940991, default 503806): 501760
Value out of range.

Whaaat? How is it possible that I can't create a partition with the parameters that it had just a second ago? In any event, I quit. I thought maybe it was just an old fdisk, so I dug myself deeper into the hole:

I used parted to delete the partition, not knowing that it would apply the change instantly. (I expected it to require "write" or "apply" command when I was finished ... So I screwed up.) Now my original partition is deleted and I can't recreate it.

How can I force creation of a partition with value out of range?


Got it. This worked for me:

By launching sudo parted I was able to do unit s to switch to sectors, and p to see the current table, and mkpart logical 501760 41940991 to recreate the partition. And quit from parted. Then I ran sudo fdisk /dev/sda and used t to set the partition type back to 8e

| improve this answer | |
  • Since I just went through this, a reminder that if the partition you are recreating should be marked active, while you have fdisk open to set the type is the perfect time to double check that :D – rakslice Apr 27 '19 at 2:04

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.