5

If I run these commands:

parted -s /dev/sda \
    mklabel gpt \
    mkpart primary 1MiB 261MiB \
    set 1 esp on \
    mkpart primary 261MiB 50GiB \
    mkpart primary 50GiB 550GiB \
    mkpart primary 550GiB 100%

mkfs.fat -F32 /dev/sda1
yes | mkfs.ext4 /dev/sda2
yes | mkfs.ext4 /dev/sda3
yes | mkfs.ext4 /dev/sda4

I get primary as name for all those partitions like this:

Model: ATA ST2000LM003 HN-M (scsi)
Disk /dev/sda: 2000GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  274MB   273MB   fat32        primary  boot, esp
 2      274MB   53.7GB  53.4GB  ext4         primary
 3      53.7GB  591GB   537GB   ext4         primary
 4      591GB   2000GB  1410GB  ext4         primary

I don't want these names, how can I avoid such automatic naming?


EDIT

If I change the mkpart section like this:

parted -s /dev/sda \
    mklabel gpt \
    mkpart 1MiB 261MiB \
    set 1 esp on \
    mkpart 261MiB 50GiB \
    mkpart 50GiB 550GiB \
    mkpart 550GiB 100%

and run the script, I get these:

Error: Invalid number.
mkfs.fat 4.1 (2017-01-24)
mkfs.fat: unable to open /dev/sda1: No such file or directory
mke2fs 1.45.3 (14-Jul-2019)
The file /dev/sda2 does not exist and no size was specified.
mke2fs 1.45.3 (14-Jul-2019)
The file /dev/sda3 does not exist and no size was specified.
mke2fs 1.45.3 (14-Jul-2019)
The file /dev/sda4 does not exist and no size was specified.

EDIT

gparted can do that:

enter image description here

Here I've removed the label from last partion with gparted BUT it doesn't show the command how it did that!

  • 1
    You can always change them later using the name NUMBER name switch. – ajgringo619 Sep 17 '19 at 00:56
  • @ajgringo619, I don't want any name. These names become the partition label on KDE's Dolphin and as a result I can't see the actual size of the partition under Devices category! On another machine I used msdos instead of gpt and with msdos I didn't have this issue. –  Sep 17 '19 at 00:59
  • 2
    I don't know if you can avoid them getting a name, but I guess "primary" comes from your own command (lines 3, 5, 7 and 7). I believe GPT doesn't have primary and extended partitions, so these don't really mean anything else. – Henrik supports the community Sep 17 '19 at 06:17
  • @Henrik, ok, I didn't know that! Let me check with this mkpart 1MiB 261MiB \ style. –  Sep 17 '19 at 06:55
  • @Henrik, no, that doesn't work! With cfdisk I did gpt partitions several times without any name. I think, cfdisk actually doesn't have any option for name for gpt partitions. –  Sep 17 '19 at 07:08
  • You can find the solution here https://askubuntu.com/a/1069617/78090 – enjoy343322434 Jan 17 '22 at 10:23

3 Answers3

2

From the parted docs:

Command: mkpart [part-type fs-type name] start end
...
part-type is one of ‘primary’, ‘extended’ or ‘logical’, and may be specified only with ‘msdos’ or ‘dvh’ partition tables. A name must be specified for a ‘gpt’ partition table. Neither part-type nor name may be used with a ‘sun’ partition table.

You have to set a name for GPT partitions when using parted.

muru
  • 72,889
  • I'd gpt partitions on that disk, I made those with cfdisk and that didn't ask me for a name. –  Sep 17 '19 at 07:20
  • 1
    @EmonHaque then use cfdisk instead of parted. – muru Sep 17 '19 at 07:21
  • cfdisk requires user interaction, I'm not sure whether I can use cfdisk in installation script like this. –  Sep 17 '19 at 07:24
  • Well, unless you have some definite problem caused by the names, I don't see an issue. Put a random name, or keep using primary as the name, what difference does it make? – muru Sep 17 '19 at 07:27
  • I can't see the partition size on the Dolphin file manager's device listings! –  Sep 17 '19 at 07:30
  • If that's you actual problem, then you should edit or ask a new question about that. When you do that, also add: How did you come to the conclusion that partition naming was the problem? What does Dolphin actually show? Have you checked if other GUI tools show the same problem? – muru Sep 17 '19 at 07:33
  • I did install Arch with the name primary and Dolphin Instead of labeling them with the size of partitions labels all primary. –  Sep 17 '19 at 07:41
  • 1
    @EmonHaque, The label is not a list of the size, but some system tools will list a drive with the size, if there is no label. This is not a bug but a feature. There are other ways to see the size of a partition, and labels are useful for identification (of course a different label for each partition). Most file browsers have a way to show 'Properties' of a partition. I think you can find something like that also with Dolphin. – sudodus Sep 17 '19 at 07:46
  • @sudodus, I actually wanted to remove those label with gparted and it did remove those primary labels and Dolphin showed the actual size. Since gparted can do that so should parted right? Let me know the command gparted used to remove those primary labels. –  Sep 17 '19 at 07:54
  • @EmonHaque you can find out from GParted itself. The logs usually include the command that GParted ran. – muru Sep 17 '19 at 07:54
  • could you please help me with the location of the log file gparted puts out? –  Sep 17 '19 at 07:57
  • 1
    @EmonHaque I don't have a system with on hand, but it looks like this: https://gparted.org/screens/gparted_9_big.png – muru Sep 17 '19 at 08:01
  • @muru, see the last EDIT, gparted doesn't show the command! –  Sep 17 '19 at 09:14
  • 1
    @EmonHaque then it's probably using the parted library directly. Another option you could try would be gdisk – muru Sep 17 '19 at 09:18
2

You can avoid naming the partition when using parted by providing an empty string.
I'll use the same quote from the official documentation:

Command: mkpart [part-type name fs-type] start end
...
part-type is one of ‘primary’, ‘extended’ or ‘logical’, and may be specified only with ‘msdos’ or ‘dvh’ partition tables. A name must be specified for a ‘gpt’ partition table. Neither part-type nor name may be used with a ‘sun’ partition table.

Now, let's dissect this (emphasize mine):

part-type is one of ‘primary’, ‘extended’ or ‘logical’, and may be specified only withmsdos’ or ‘dvh’ partition tables.

So, when you create a gpt partition table you don't use part-type (for obvious reasons: there's only one type of partition). Which means that for gpt disks the command becomes

mkpart [name fs-type] start end  

which means the first argument to mkpart is the name. Let's go back to the quote:

A name must be specified for a ‘gpt’ partition table.

in other words that first argument is mandatory so whatever string follows the mkpart command it will be interpreted as the designated name for the partition. Now, how do you create a new partition without a name when using parted in interactive mode? You use an empty string "" e.g.

(parted) mkpart "" 0% 100% 

When you run that command in scripted mode you have to avoid those quotes to be expanded by the shell (to nothing), they need to be passed literally to parted so you have to escape/quote them, e.g.

parted -a optimal -s /dev/sda mklabel gpt mkpart '""' 0% 100%

that is, in your particular case, instead of using "primary" which will used as a name for the partitions, you use an empty string:

parted -s /dev/sda \
    mklabel gpt \
    mkpart '""' 1MiB 261MiB \
    set 1 esp on \
    mkpart '""' 261MiB 50GiB \
    mkpart '""' 50GiB 550GiB \
    mkpart '""' 550GiB 100%
don_crissti
  • 82,805
0

You can use fdisk

You can use fdisk from util-linux 2.31.1, probably also some other fairly new versions.

I tested with the following script file, where X should be replaced by the actual device letter for your target drive. Of course you have to set up the correct numbers of partitions and their sizes. You can find out what syntax to use by running fdisk interactively.

#!/bin/bash

LANG=C

echo "g
n


+256m

n


+1g

n




w" | fdisk /dev/sdX

Explanation

The following list does not work (the comments are not accepted by fdisk), but it helps understanding the script above.

#!/bin/bash

LANG=C

echo "g     # gpt, GUID partition table
n           # new partition
            # default partition number
            # default start location
+256m       # size
            # default answer to partition name
n           # new partition
            # default partition number
            # default start location
+1g         # size
            # default answer to partition name
n           # new partition
            # default partition number
            # default start location
            # default end location at the drive's tail end
            # default answer to partition name
w           # write to the drive" | fdisk /dev/sdX

Verification that there will be no 'Name'

$ sudo partprobe;sleep 1;LANG=C sudo parted /dev/sdc p
Model: Kingston DataTraveler G3 (scsi)
Disk /dev/sdc: 4010MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  269MB   268MB
 2      269MB   1343MB  1074MB
 3      1343MB  4010MB  2667MB
sudodus
  • 6,421
  • What about the last partition? I want /dev/sda4 to take rest of the available space. –  Sep 17 '19 at 10:14
  • 1
    @EmonHaque, It is simple, use the default (an empty line) and it will use the rest of the available space. – sudodus Sep 17 '19 at 10:16