After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 686668 - Growing logical partition overlaps end of extended partition
Growing logical partition overlaps end of extended partition
Status: RESOLVED FIXED
Product: gparted
Classification: Other
Component: application
0.14.0
Other Linux
: Normal normal
: ---
Assigned To: gparted maintainers alias
gparted maintainers alias
Depends on:
Blocks:
 
 
Reported: 2012-10-22 21:34 UTC by bugreport
Modified: 2012-12-12 18:12 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gparted_details.htm log file that demonstrates the problem (4.69 KB, text/html)
2012-11-25 18:32 UTC, Curtis Gedak
  Details
Patch to fix grow logical partition overlaps end of extended partition problem (3.61 KB, patch)
2012-11-25 21:07 UTC, Curtis Gedak
none Details | Review

Description bugreport 2012-10-22 21:34:50 UTC
Gparted 0.14.1 failed to move and resize my ntfs partition.
See the following thread for details:

http://gparted-forum.surf4.info/viewtopic.php?id=16667
Comment 1 Curtis Gedak 2012-11-25 18:32:14 UTC
Created attachment 229831 [details]
gparted_details.htm log file that demonstrates the problem

Today I was able to confirm this bug.

PROBLEM DESCRIPTION
===================

In the forum link from comment #1 the disk device uses an MSDOS
partition table and contains partitions with varying alignments (e.g.,
cylinder, MiB, and other alignments).  When the sda6 logical partition
is grown to the end of the sda3 extended partition using MiB
alignment, the GParted operation fails with the error message:

   Can't have overlapping partitions.


Since I do not have a 2 TiB disk device for testing, I used the
following steps to recreate the bug:

1)  Create a sparse file 2 TiB in size:

    $ dd if=/dev/zero of=$IMGFILE bs=1k seek=2048M count=1

2)  Set up a loop device using the sparse file:

    $ sudo losetup /dev/loop0 $IMGFILE

3)  Create a text file (bigdev.sf) with a simplified MSDOS partition
    table to demonstrate the problem.

    Contents of bigdev.sf
----- cut here -----
# partition table of /dev/loop0
unit: sectors

/dev/loop0p1 : start=        0, size=        0, Id= 0
/dev/loop0p2 : start=        0, size=        0, Id= 0
/dev/loop0p3 : start=1331202048, size=2575034832, Id= 5
/dev/loop0p4 : start=        0, size=        0, Id= 0
/dev/loop0p5 : start=1331202111, size=209720559, Id=83
/dev/loop0p6 : start=2671544320, size=838866042, Id= b
----- cut here -----

4)  Write the partition table to the loop device:

    $ sudo sfdisk /dev/loop0 < bigdev.sf

5)  Ensure that the device entries for the partitions are created:

    $ sudo partprobe /dev/loop0

6)  Format the "sda6" partition with FAT32.
    (this bug is not file system specific)

    $ sudo mkdosfs -F32 -v -n "FAT32TEST" /dev/loop0p6

7)  Run GParted on the loop device

    $ sudo gparted /dev/loop0

8)  Using the GParted GUI:

    a)  Select partition /dev/loop0p6

    b)  Choose the "Partition --> Resize/Move" menu option

    c)  Click on the right hand side of the partition and drag it
        all the way to the right.  This is to grow the partition
        to the end of the extended partition

    d)  Click on Resize/Move

    e)  Choose "Edit --> Apply all operations" menu option

    f)  *** Witness the error occur ***

Attached is the gparted_details.htm log file that shows the error.


Please note that the loop device can be removed with the following
command:

    $ sudo losetup -d /dev/loop0
Comment 2 Curtis Gedak 2012-11-25 20:57:20 UTC
In the above list of steps I missed setting the IMGFILE variable to a file name.

Hence add the following step for this to work.

0)  Set the IMGFILE variable

    $ IMGFILE=bigdev.img


Or alternatively you can simply substitute a file name for $IMGFILE in steps 1 and 2 above.
Comment 3 Curtis Gedak 2012-11-25 21:07:08 UTC
Created attachment 229841 [details] [review]
Patch to fix grow logical partition overlaps end of extended partition problem

The attached patch set addresses two problems

1)  Fixes problem that file system grow operation proceeds when the prior
    partition grow operation fails.

2)  Fixes MiB alignment problem that in some grow situations would try to
    set the end of a logical partition beyond the end of the extended
    partition.
Comment 4 Mike Fleetwood 2012-12-02 11:10:16 UTC
Hi Curtis,

I've been unable set-up the failure case.  Fedora 14 and Debian 6 both fail when creating the sparse file.

    # dd if=/dev/zero of=/opt/nobackup/block0.img bs=1k seek=2048M count=1
    dd: failed to truncate to 2199023255552 bytes in output file `/opt/nobackup/block0.img': File too large
    # dd --version | head -1
    dd (coreutils) 8.5

Fedora 17 I can get the required partitions into the loop device but can't correctly load those partitions into the kernel so can't create the the file system.

    # sfdisk -l -u S /dev/loop0
    sfdisk: Disk /dev/loop0: cannot get geometry

    Disk /dev/loop0: 267349 cylinders, 255 heads, 63 sectors/track
    sfdisk: Warning: extended partition does not start at a cylinder boundary.
    DOS and Linux will interpret the contents differently.

    Units = sectors of 512 bytes, counting from 0

       Device Boot    Start       End   #sectors  Id  System
    /dev/loop0p1             0         -          0   0  Empty
    /dev/loop0p2             0         -          0   0  Empty
    /dev/loop0p3     1331202048 3906236879 2575034832   5  Extended
    /dev/loop0p4             0         -          0   0  Empty
    /dev/loop0p5     1331202111 1540922669  209720559  83  Linux
    /dev/loop0p6     2671544320 3510410361  838866042  83  Linux

Partprobe doesn't load any partitions into the kernel.

    # strace -e ioctl partprobe  /dev/loop0
    ioctl(3, BLKGETSIZE64, 2199023256576)   = 0
    +++ exited with 0 +++
    # grep loop0 /proc/partitions
       7        0 2147483649 loop0
    # partprobe --version | head -1
    partprobe (GNU parted) 3.0

Partx loads the wrong partition sizes into the kernel.  The kernel is told partition sizes of 1K and 2.6M!

    # strace -e ioctl partx -a /dev/loop0
    ioctl(3, BLKGETSIZE64, 2199023256576)   = 0
    ioctl(3, CDROM_GET_CAPABILITY or SNDRV_SEQ_IOCTL_UNSUBSCRIBE_PORT, 0) = -1 EINVAL (Invalid argument)
    ioctl(3, BLKSSZGET, 512)                = 0
    ioctl(3, BLKPG, {BLKPG_ADD_PARTITION, flags=0, datalen=148, {start=2970615808, length=1024, pno=3, devname="", volname=""}}) = 0
    ioctl(3, BLKPG, {BLKPG_ADD_PARTITION, flags=0, datalen=148, {start=2970648064, length=2743808, pno=5, devname="", volname=""}}) = 0
    ioctl(3, BLKPG, {BLKPG_ADD_PARTITION, flags=0, datalen=148, {start=2031091712, length=2683904, pno=6, devname="", volname=""}}) = 0
    +++ exited with 0 +++
    # grep loop0 /proc/partitions
       7        0 2147483649 loop0
     259        0          1 loop0p3
     259        1       2679 loop0p5
     259        2       2621 loop0p6
    # type partx
    partx is hashed (/sbin/partx)
    # rpm -qf /sbin/partx
    util-linux-2.21.2-2.fc17.i686

I guess your using Ubuntu 12.10 where all this must just work.  Anyway I'll continue and just do a visual review.

Mike
Comment 5 Mike Fleetwood 2012-12-02 12:30:55 UTC
Hi Curtis,

Patches:

1) Tested and reviewed.  Good.

2) Reviewed.  (Couldn't test as described above).  OK.
   I assume that it wouldn't be possible for the logical partition to
   be more that 1 MiB beyond the end of the extended partition, probably
   because that's how the Resize/Move dialog works.  Also in multiple
   location in the function snap_to_mebibyte() it assumes that
   subtracting 1 MiB will bring the partition within the required limits
   so your patch is no different.

(Think that there is an opportunity for a future clean up.  Have the UI
query GParted_Core to get size limits with all required allowances
applied first so sizes don't have to be adjusted afterwards).

I'll commit in a day or two unless I hear otherwise.

Thanks,
Mike
Comment 6 Curtis Gedak 2012-12-02 16:48:06 UTC
Thank you Mike for looking at this patch set.

re: (2).  I agree that there is room for improvement here.  Currently this all works because the GUI uses MiB as the smallest and largest value for sizes.  For now this works and I believe is an improvement over the current code.

re: Testing.
When I created the sparse file, it was on Ubuntu 12.04 on a disk with 149 GiB free.  It is entirely possible that improvements have been made with loop devices, and sparse files in these more recent GNU/Linux distributions.

The versions I used are as follows:

$ dd --version
dd (coreutils) 8.13

$ partprobe --version
partprobe (GNU parted) 2.3
[*** NOTE: This is the patched Ubuntu version ***]

$ uname -a
Linux octo 3.2.0-34-generic #53-Ubuntu SMP Thu Nov 15 10:48:16 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

$ dpkg -l | grep util-linux
ii  util-linux                           2.20.1-1ubuntu3                         Miscellaneous system utilities
[*** NOTE: losetup is a part of util-linux ***]
Comment 7 Mike Fleetwood 2012-12-03 13:14:02 UTC
Hi Curtis,

Patchset "Patch to fix grow logical partition overlaps end of extended partition problem" from comment #3 has been committed to git repository for inclusion in the next release of GParted.

The relevant git commits can be viewed at the following links:

Prevent file system grow when partition grow fails (#686668)
http://git.gnome.org/browse/gparted/commit/?id=fd963289201532f2216029ffd1e0b49e22d79560

Fix logical partition grow overlaps extended partition end (#686668)
http://git.gnome.org/browse/gparted/commit/?id=83ccbce1995147bf171eca1c6bd283483ec1dd05

Thanks,
Mike
Comment 8 Curtis Gedak 2012-12-12 18:12:04 UTC
The enhancements to address this bug report have been included in GParted 0.14.1 released on December 12, 2012.