21

Below is my hard disk shown in gnu parted:

(parted) print free                                                       
Model: ATA HGST HTS541075A9 (scsi)
Disk /dev/sda: 750GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start   End     Size    File system     Name                     
       17.4kB  1049kB  1031kB  Free Space
1      1049kB  538MB   537MB   fat32           EFI System Partition  boot
2      538MB   468GB   467GB   ext4
       468GB   520GB   52.4GB  Free Space
6      520GB   527GB   6353MB  linux-swap(v1)
4      527GB   527GB   524MB   ext4
5      527GB   744GB   217GB                                         lvm
3      744GB   750GB   6352MB
    750GB   750GB   892kB   Free Space

(parted) 

You can see I have 52.4GB space (fourth entry). I want to create a partition in this. I know mkpart is the command for it.

Its syntax is

 mkpart PART-TYPE [FS-TYPE] START END

But my problem is I don't know what value is should give for START and END. What value should I use?

Braiam
  • 35,991
sps
  • 1,436
  • This is not a direct answer, but cfdisk allows to do that extremely easy: you just press on the Free space, and it asks you about the needed partition size (100% by default, so you don't have to calculate anything). – Yaroslav Nikitenko Apr 27 '23 at 09:31

2 Answers2

22
Number  Start   End     Size    File system
    ......................................
        468GB   520GB   52.4GB  Free Space

Well, as you can see Start is 468GB and End is 520GB. Now, parted defaults to MB so you'll have to specify the unit:

unit GB mkpart primary ntfs 468 520

or append unit suffix to the start/end numbers:

mkpart primary ext2 468GB 520GB

Alternatively, you can list the values in MB with

unit MB print free

and then use the start/end values without any unit/suffix e.g.

mkpart primary ext2 468012 520008
don_crissti
  • 82,805
-3

Another solution would be to use percentage unit (%) to specify sizes:

 sudo parted -s /dev/sdX mkpart primary 0% 100%

If a label is not present in the disk device, you will need to create it first. For example:

 sudo parted -s /dev/sdX mklabel msdos

Caution! 0% and 100% points correspondingly to the start and to the end of entire physical disk, and not just free space. So if you run sudo parted -s /dev/sdX mkpart primary 0% 100%, this will destroy all existing partitions.

andrew
  • 105