From: Karel Zak Date: Tue, 3 Mar 2020 15:07:00 +0000 (+0100) Subject: sfdisk: extend --part-type, support aliases X-Git-Tag: v2.36-rc1~199^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5839a4ea032b47813d4be6406e6d1ad7ee33afe1;p=thirdparty%2Futil-linux.git sfdisk: extend --part-type, support aliases * add support for aliases to sfdisk scripts * add shortcuts and aliases to --part-type command Note that --part-type evaluates shortcuts and aliases as the last possibility (so after regular type string). This is necessary for backward compatibility. Example ('raid' type alias): # sfdisk --part-type /dev/sdc 1 raid # fdisk -l /dev/sdc ... Device Boot Start End Sectors Size Id Type /dev/sdc1 2048 204799 202752 99M fd Linux raid autodetect Example ('L' type shortcut): # sfdisk --part-type /dev/sdc 1 L # fdisk -l /dev/sdc ... Device Boot Start End Sectors Size Id Type /dev/sdc1 2048 204799 202752 99M 83 Linux Addresses: https://github.com/karelzak/util-linux/issues/958 Signed-off-by: Karel Zak --- diff --git a/disk-utils/sfdisk.8 b/disk-utils/sfdisk.8 index 2ba72b1369..da841cceb6 100644 --- a/disk-utils/sfdisk.8 +++ b/disk-utils/sfdisk.8 @@ -132,7 +132,9 @@ List the free unpartitioned areas on all or the specified devices. .TP .BR "\-\-part\-attrs \fIdevice partition-number " [ \fIattributes ] Change the GPT partition attribute bits. If \fIattributes\fR is not specified, -then print the current partition settings. The \fIattributes\fR argument is a +then print the current partition settings. +.sp +The \fIattributes\fR argument is a comma- or space-delimited list of bits. The currently supported attribute bits are: RequiredPartition, NoBlockIOProtocol, LegacyBIOSBootable and GUID-specific bits in the range from 48 to 63. For example, the string @@ -144,8 +146,11 @@ then print the current partition label. .TP .BR "\-\-part\-type \fIdevice partition-number " [ \fItype ] Change the partition type. If \fItype\fR is not specified, then print the -current partition type. The \fItype\fR argument is hexadecimal for MBR, -or a GUID for GPT. For backward compatibility the options \fB\-c\fR and +current partition type. +.sp +The \fItype\fR argument is hexadecimal for MBR, +GUID for GPT, type alias (e.g. "linux") or type shortcut (e.g. 'L'). +For backward compatibility the options \fB\-c\fR and \fB\-\-id\fR have the same meaning as this one. .TP .BR "\-\-part\-uuid \fIdevice partition-number " [ \fIuuid ] @@ -405,42 +410,48 @@ partition; existing partitions will be resized as required. The partition .I type is given in hex for MBR (DOS) where 0x prefix is optional; a GUID string for -GPT; or a shortcut. It's recommended to use two letters for MBR hex codes to -avoid collision between shortcut 'E' and '0E' MBR hex code. For backward +GPT; a shortcut or an alias. It's recommended to use two letters for MBR hex codes to +avoid collision between deprecated shortcut 'E' and '0E' MBR hex code. For backward compatibility sfdisk tries to interpret .I type -as a shortcut as a first possibility. Supported shortcuts: +as a shortcut as a first possibility in partitioning scripts although on another places (e.g. +\fB\-\-part-type command)\fR it tries shortcuts as the last possibility. + +Since v2.36 libfdisk supports partition type aliases as extension to shortcuts. The alias is a +simple human readable word (e.g. "linux"). + +Supported shortcuts and aliases: .RS .TP -.B L +.B L - alias 'linux' Linux; means 83 for MBR and 0FC63DAF-8483-4772-8E79-3D69D8477DE4 for GPT. .TP -.B S +.B S - alias 'swap' swap area; means 82 for MBR and 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F for GPT .TP -.B E -extended partition; means 05 for MBR +.B Ex - alias 'extended' +MBR extended partition; means 05 for MBR. The original shortcut 'E' is deprecated due to collision with +0x0E MBR partition type. .TP -.B H +.B H - alias 'home' home partition; means 933AC7E1-2EB4-4F13-B844-0E14E2AEF915 for GPT .TP -.B X -linux extended partition; means 85 for MBR. -.TP -.B U +.B U - alias 'uefi' EFI System partition, means EF for MBR and C12A7328-F81F-11D2-BA4B-00A0C93EC93B for GPT .TP -.B R +.B R - alias 'raid' Linux RAID; means FD for MBR and A19D880F-05FC-4D3B-A006-743F0F84911E for GPT .TP -.B V +.B V - alias 'lvm' LVM; means 8E for MBR and E6D6D379-F507-44C2-A23C-238F2A3DF928 for GPT .RE .PP The default .I type value is -.I L +.I linux +.sp +The shortcut 'X' for Linux extended partition (85) is deprecated in favour of 'Ex'. .I bootable is specified as [\fB*\fR|\fB-\fR], with as default not-bootable. The diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c index bc6b22e011..d8f90b74fc 100644 --- a/disk-utils/sfdisk.c +++ b/disk-utils/sfdisk.c @@ -1152,7 +1152,10 @@ static int command_parttype(struct sfdisk *sf, int argc, char **argv) backup_partition_table(sf, devname); /* parse and apply to PT */ - type = fdisk_label_parse_parttype(lb, typestr); + type = fdisk_label_advparse_parttype(lb, typestr, + FDISK_PARTTYPE_PARSE_DATA + | FDISK_PARTTYPE_PARSE_ALIAS + | FDISK_PARTTYPE_PARSE_SHORTCUT); if (!type) errx(EXIT_FAILURE, _("failed to parse %s partition type '%s'"), fdisk_label_get_name(lb), typestr); @@ -1467,7 +1470,7 @@ static void command_fdisk_help(void) fputc('\n', stdout); fputs(_(" The partition type. Default is a Linux data partition.\n"), stdout); - fputs(_(" MBR: hex or L,S,E,X,U,R,V shortcuts.\n"), stdout); + fputs(_(" MBR: hex or L,S,Ex,X,U,R,V shortcuts.\n"), stdout); fputs(_(" GPT: UUID or L,S,H,U,R,V shortcuts.\n"), stdout); fputc('\n', stdout);