From 0bf4676573a71db864dcffb0486e0d51ed8c1a97 Mon Sep 17 00:00:00 2001 From: Vignesh Raman Date: Tue, 27 Jul 2021 10:31:08 +0530 Subject: [PATCH] actions/image-partition: add optional argument filesystem label Add optional argument filesystem label which defaults to partiton name and is used in mkfs commands. Fixes: #251 Suggested-by: Christopher Obbard Signed-off-by: Vignesh Raman --- actions/image_partition_action.go | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/actions/image_partition_action.go b/actions/image_partition_action.go index 442168bd..4e967d17 100644 --- a/actions/image_partition_action.go +++ b/actions/image_partition_action.go @@ -43,6 +43,7 @@ Yaml syntax for partitions: - name: partition name partlabel: partition label fs: filesystem + fslabel: filesystem label start: offset end: offset features: list of filesystem features @@ -72,6 +73,11 @@ Optional properties: - partlabel -- label for the partition in the GPT partition table. Defaults to the `name` property of the partition. May only be used for GPT partitions. +- fslabel -- Sets the volume name (label) of the filesystem. Defaults to the +`name` property of the partition. The filesystem label can be up to 11 characters +long for vfat, 16 characters long for ext2/3/4, 255 characters long for btrfs, +512 characters long for hfs/hfsplus and 12 characters long for xfs. + - parttype -- set the partition type in the partition table. The string should be in a hexadecimal format (2-characters) for msdos partition tables and GUID format (36-characters) for GPT partition tables. For instance, "82" for msdos sets the @@ -168,6 +174,7 @@ type Partition struct { number int Name string PartLabel string + FSLabel string PartType string Start string End string @@ -305,10 +312,10 @@ func (i ImagePartitionAction) formatPartition(p *Partition, context debos.DebosC cmdline := []string{} switch p.FS { case "vfat": - cmdline = append(cmdline, "mkfs.vfat", "-F32", "-n", p.Name) + cmdline = append(cmdline, "mkfs.vfat", "-F32", "-n", p.FSLabel) case "btrfs": // Force formatting to prevent failure in case if partition was formatted already - cmdline = append(cmdline, "mkfs.btrfs", "-L", p.Name, "-f") + cmdline = append(cmdline, "mkfs.btrfs", "-L", p.FSLabel, "-f") if len(p.Features) > 0 { cmdline = append(cmdline, "-O", strings.Join(p.Features, ",")) } @@ -316,26 +323,26 @@ func (i ImagePartitionAction) formatPartition(p *Partition, context debos.DebosC cmdline = append(cmdline, "-U", p.FSUUID) } case "f2fs": - cmdline = append(cmdline, "mkfs.f2fs", "-l", p.Name) + cmdline = append(cmdline, "mkfs.f2fs", "-l", p.FSLabel) if len(p.Features) > 0 { cmdline = append(cmdline, "-O", strings.Join(p.Features, ",")) } case "hfs": - cmdline = append(cmdline, "mkfs.hfs", "-h", "-v", p.Name) + cmdline = append(cmdline, "mkfs.hfs", "-h", "-v", p.FSLabel) case "hfsplus": - cmdline = append(cmdline, "mkfs.hfsplus", "-v", p.Name) + cmdline = append(cmdline, "mkfs.hfsplus", "-v", p.FSLabel) case "hfsx": - cmdline = append(cmdline, "mkfs.hfsplus", "-s", "-v", p.Name) + cmdline = append(cmdline, "mkfs.hfsplus", "-s", "-v", p.FSLabel) // hfsx is case-insensitive hfs+, should be treated as "normal" hfs+ from now on p.FS = "hfsplus" case "xfs": - cmdline = append(cmdline, "mkfs.xfs", "-L", p.Name) + cmdline = append(cmdline, "mkfs.xfs", "-L", p.FSLabel) if len(p.FSUUID) > 0 { cmdline = append(cmdline, "-m", "uuid="+p.FSUUID) } case "none": default: - cmdline = append(cmdline, fmt.Sprintf("mkfs.%s", p.FS), "-L", p.Name) + cmdline = append(cmdline, fmt.Sprintf("mkfs.%s", p.FS), "-L", p.FSLabel) if len(p.Features) > 0 { cmdline = append(cmdline, "-O", strings.Join(p.Features, ",")) } @@ -613,6 +620,12 @@ func (i *ImagePartitionAction) Verify(context *debos.DebosContext) error { } } + if i.PartitionType == "gpt" { + if p.FSLabel == "" { + p.FSLabel = p.Name + } + } + if len(p.FSUUID) > 0 { if p.FS == "btrfs" || p.FS == "ext2" || p.FS == "ext3" || p.FS == "ext4" || p.FS == "xfs" { _, err := uuid.Parse(p.FSUUID)