[HowTo] Fix Partition Outside the Disk

How-to Fix Partition Outside the Disk

The following instructions describe how to manually correct the problem of a partition extending beyond the end of the disk.

Other methods also exist, such as using testdisk to scan the disk device to rebuild the partition table. The testdisk application is included on GParted Live.

If the problem occurs with the extended partition, then you might consider using the fixparts application. The fixparts application is also included on GParted Live.

NOTE:   Be sure to choose the correct disk device path.
In the following example, the disk device containing a partition outside the disk is /dev/sdb

  1. Ensure you have a good backup of your data.
  2. Confirm the problem by running parted on your disk device (e.g., /dev/sdb).

    For example:
        $ sudo parted /dev/sdb unit s print
        Error: Can’t have a partition outside the disk!
        
    You should see the error message Error: Can’t have a partition outside the disk!
  3. Gather partition details for analysis using the fdisk command.

    For example:
        $ sudo fdisk -l -u /dev/sdb
    
        Disk /dev/sdb: 250.1 GB, 250059350016 bytes
        255 heads, 63 sectors/track, 30401 cylinders, total 488397168 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: 0x00068df3
    
          Device  Boot      Start         End      Blocks   Id  System
        /dev/sdb1   *          63    12578894     6289416    7  HPFS/NTFS/exFAT
        /dev/sdb2        12578895   180345689    83883397+   7  HPFS/NTFS/exFAT
        /dev/sdb3       180345690   390058199   104856255    7  HPFS/NTFS/exFAT
        /dev/sdb4       390058200   488408189    49174995    5  Extended
        /dev/sdb5       390058263   459089504    34515621   83  Linux
        /dev/sdb6       459089568   488392064    14651248+  82  Linux swap / Solaris
        
  4. Check the fdisk output for the cause of the problem.

    Does any partition have an end value larger than the disk size?

    To be precise, since the first sector begins at sector zero (0), check to see if the end of any partition is greater than the disk size minus one sector.

    In this example the end of extended partition sdb4 is beyond the size of the disk.

        488,408,189 --- end of sdb4
        488,397,168 --- size of sdb device
        Disk /dev/sdb: 250.1 GB, 250059350016 bytes
        255 heads, 63 sectors/track, 30401 cylinders, total 488397168 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: 0x00068df3
    
          Device  Boot      Start         End      Blocks   Id  System
        /dev/sdb1   *          63    12578894     6289416    7  HPFS/NTFS/exFAT
        /dev/sdb2        12578895   180345689    83883397+   7  HPFS/NTFS/exFAT
        /dev/sdb3       180345690   390058199   104856255    7  HPFS/NTFS/exFAT
        /dev/sdb4       390058200   488408189    49174995    5  Extended
        /dev/sdb5       390058263   459089504    34515621   83  Linux
        /dev/sdb6       459089568   488392064    14651248+  82  Linux swap / Solaris
        
  5. Determine a new end value (and partition size) to prevent the partition outside the disk problem.

    The new end sector of the partition outside the disk should be the size of the disk minus one sector.

    In our example:
        new sdb4 end = (sdb disk size) - 1
                     = 488397168 - 1
                     = 488397167
        
    New size of sda1 will be the new end of sda1 minus the start of sda1 plus one sector.
        new sdb4 size = (new sdb4 end) - (sdb4 start) + 1
                      = 488397167 - 390058200 + 1
                      = 98338968
        
  6. Make a copy of the partition table in an editable file using the sfdisk command.

    For example:
        $ sudo sfdisk -d /dev/sdb > sdb-backup.txt
        
  7. Use your favourite editor to edit the file to change the old partition size to the new partition size.
    If you are using GParted Live, you can edit the file using the Leafpad editor.

    For example:
        $ sudo leafpad sdb-backup.txt
    
        # partition table of /dev/sdb
        unit: sectors
    
        /dev/sdb1 : start=       63, size= 12578832, Id= 7, bootable
        /dev/sdb2 : start= 12578895, size=167766795, Id= 7
        /dev/sdb3 : start=180345690, size=209712510, Id= 7
        /dev/sdb4 : start=390058200, size= 98349990, Id= 5
        /dev/sdb5 : start=390058263, size= 69031242, Id=83
        /dev/sdb6 : start=459089568, size= 29302497, Id=82
        
    Change the old size of the partition sdb4 (98349990) to the calculated new size (98338968).
        # partition table of /dev/sdb
        unit: sectors
    
        /dev/sdb1 : start=       63, size= 12578832, Id= 7, bootable
        /dev/sdb2 : start= 12578895, size=167766795, Id= 7
        /dev/sdb3 : start=180345690, size=209712510, Id= 7
        /dev/sdb4 : start=390058200, size= 98338968, Id= 5
        /dev/sdb5 : start=390058263, size= 69031242, Id=83
        /dev/sdb6 : start=459089568, size= 29302497, Id=82
        
    Save the file and exit the editor.
  8. Write the corrected partition details to the partition table using the sfdisk command.

    For example:
        $ sudo sfdisk /dev/sdb < sdb-backup.txt
        Checking that no-one is using this disk right now ...
        OK
    
        Disk /dev/sdb: 30401 cylinders, 255 heads, 63 sectors/track
        Old situation:
        Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0
    
           Device Boot Start     End   #cyls    #blocks   Id  System
        /dev/sdb1   *      0+    782     783-   6289416    7  HPFS/NTFS/exFAT
        /dev/sdb2        783   11225   10443   83883397+   7  HPFS/NTFS/exFAT
        /dev/sdb3      11226   24279   13054  104856255    7  HPFS/NTFS/exFAT
        /dev/sdb4      24280   30402-   6123-  49174995    5  Extended
        /dev/sdb5      24280+  28576    4297-  34515621   83  Linux
        /dev/sdb6      28577+  30400    1824-  14651248+  82  Linux swap / Solaris
        New situation:
        Units = sectors of 512 bytes, counting from 0
    
           Device Boot    Start       End   #sectors  Id  System
        /dev/sdb1   *        63  12578894   12578832   7  HPFS/NTFS/exFAT
        /dev/sdb2      12578895 180345689  167766795   7  HPFS/NTFS/exFAT
        /dev/sdb3     180345690 390058199  209712510   7  HPFS/NTFS/exFAT
        /dev/sdb4     390058200 488397167   98338968   5  Extended
        /dev/sdb5     390058263 459089504   69031242  83  Linux
        /dev/sdb6     459089568 488392064   29302497  82  Linux swap / Solaris
        Warning: partition 4 does not end at a cylinder boundary
        Warning: partition [6] does not end at a cylinder boundary
        Successfully wrote the new partition table
    
        Re-reading the partition table ...
    
        If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
        to zero the first 512 bytes:  dd if=/dev/zero of=/dev/foo7 bs=512 count=1
        (See fdisk(8).)
        
  9. Confirm the problem is now resolved by running parted on your disk device.

    For example:
        $ sudo parted /dev/sdb unit s print
        Model: ATA ST3250022ACE (scsi)
        Disk /dev/sdb: 488397168s
        Sector size (logical/physical): 512B/512B
        Partition Table: msdos
    
        Number  Start       End         Size        Type      File system     Flags
         1      63s         12578894s   12578832s   primary   ntfs            boot
         2      12578895s   180345689s  167766795s  primary   ntfs
         3      180345690s  390058199s  209712510s  primary   ntfs
         4      390058200s  488397167s  98338968s   extended
         5      390058263s  459089504s  69031242s   logical   ext2
         6      459089568s  488392064s  29302497s   logical   linux-swap(v1)
        
    You should now be able to use GParted with this device. :-)

 

Source:

http://gparted.org/h2-fix-msdos-pt.php#partition-outside-disk

Attached Files
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Name
Email
Security Code Security Code
Related Articles RSS Feed
[Issue] SSH session slow to start
Viewed 1209 times since Tue, Sep 23, 2014
[How To] Remove a disk from a LVM volume group
Viewed 2432 times since Thu, May 4, 2017
MENU