1

I have a 8 TB hard disk with two partitions on it: 3 TB and 1 TB, so remaining 4 TB is free. I'd like to create a 3rd partition which would span rest of the disk. In the early days with fdisk when creating a new partition the program would automatically offer a start position which would be right after the end of the previous partition. However GNU parted doesn't offer such an option.

The layout of the drive looks like this:

GNU Parted 3.2
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: ATA WDC WD80EFZX-68U (scsi)
Disk /dev/sdc: 8002GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  3001GB  3001GB               primary
 2      3001GB  4001GB  1000GB               primary

All the guides suggest to use (in this case) "4001GB" as a start and "-1" as an end for the partition. The "4001GB" boundary in this case seems a bit ambiguous to me. While 1 GB in the scope of terabytes is insignificant, OCD-me would like to have the entire disk used.

Hence my question:

Is there a sensible way to create a new partition with GNU Parted in such a way that the new partition is right after the previous one, with proper alignment taken into account? Or - if it is used with MB/GB/TB, does it just "do the right thing"?

  • 2
    Use the unit command to switch to something more fine grained (eg s for sector, or cyl for cylinder) – Stephen Harris Dec 27 '18 at 14:46
  • It does the right thing, it will not leave 1GB unused... – don_crissti Dec 27 '18 at 15:54
  • 2
    If you're more comfortable usingfdisk, you can also consider using gdisk to handle GPT disks. – Haxiel Dec 27 '18 at 16:25
  • @StephenHarris Yes, but what is the proper way? I would think that cylinders are irrelevant for SSDs so let's go with sectors. If the previous partition ends on a sector X, what number should I enter as a start for the new partition? X, or X+1, or X+something to keep it aligned? – Alex Darrell Dec 28 '18 at 16:14
  • @don_crissti Could you back this statement up with a link to relevant documentation? – Alex Darrell Dec 28 '18 at 16:14
2

With parted, use print free to see all free segments or gaps in your partitioning, as start/end/size that you can use in your subsequent mkpart commands.

(parted) unit mib # or s, b, whatever you prefer
(parted) print free                          
Model:  (file)
Disk /dev/shm/foobar.img: 7629395MiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start       End         Size        File system  Name  Flags
        0.02MiB     1.00MiB     0.98MiB     Free Space
 1      1.00MiB     953674MiB   953673MiB                root
        953674MiB   2861023MiB  1907349MiB  Free Space
 3      2861023MiB  7629394MiB  4768371MiB               data
        7629394MiB  7629395MiB  0.52MiB     Free Space

So in this example there is free space 953674MiB - 2861023MiB.

Create a partition and it should fill out perfectly.

(parted) mkpart home 953674MiB 2861023MiB
(parted) print free
Model:  (file)
Disk /dev/shm/foobar.img: 7629395MiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start       End         Size        File system  Name  Flags
        0.02MiB     1.00MiB     0.98MiB     Free Space
 1      1.00MiB     953674MiB   953673MiB                root
 2      953674MiB   2861023MiB  1907349MiB               home
 3      2861023MiB  7629394MiB  4768371MiB               data
        7629394MiB  7629395MiB  0.52MiB     Free Space

with proper alignment taken into account?

As already stated in the comments, the alignment depends on the correct end sector of the previous partition. It's best to check manually for correct MiB alignment.

If a partition did not have a correct size, it's usually (but not always) possible to grow the end sector of the previous partition accordingly, using the resizepart command. Leaving gaps in the partitioning is not harmful in any way, so don't worry too much about it.

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.