From 3085c59f1b794e914bdc16c7c39f27a156d2d659 Mon Sep 17 00:00:00 2001 From: Mateus Melchiades Date: Fri, 13 Oct 2023 10:55:54 -0300 Subject: [PATCH] recipe: Handle LVM mountpoints --- core/recipe.go | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/core/recipe.go b/core/recipe.go index d3ad91ff..c7463102 100644 --- a/core/recipe.go +++ b/core/recipe.go @@ -795,9 +795,6 @@ func (recipe *Recipe) SetupMountpoints() error { diskCache := map[string]*Disk{} rootAMounted := false - diskExpr := regexp.MustCompile("^/dev/[a-zA-Z]+([0-9]+[a-z][0-9]+)?") - partExpr := regexp.MustCompile("[0-9]+$") - /* We need to mount the partitions in order to prevent one mountpoint * from overriding another. * For example, if we mount /boot first in /mnt/a/boot and then mount / in @@ -819,33 +816,49 @@ func (recipe *Recipe) SetupMountpoints() error { mount_depth += 1 } + lvmExpr := regexp.MustCompile(`^/dev/(?P[\w-]+)/(?P[\w-]+)$`) + diskExpr := regexp.MustCompile("^/dev/[a-zA-Z]+([0-9]+[a-z][0-9]+)?") + partExpr := regexp.MustCompile("[0-9]+$") + for _, mnt := range ordered_mountpoints { - diskName := diskExpr.FindString(mnt.Partition) - part := partExpr.FindString(mnt.Partition) + baseRoot := RootA + if mnt.Target == "/" && rootAMounted { + baseRoot = RootB + } else if mnt.Target == "/" && !rootAMounted { + rootAMounted = true + } - disk, ok := diskCache[diskName] - if !ok { - diskPtr, err := LocateDisk(diskName) + // LVM partition + if lvmExpr.MatchString(mnt.Partition) { + lvmPartition := Partition{ + Number: -1, + Path: mnt.Partition, + } + err := lvmPartition.Mount(baseRoot + mnt.Target) if err != nil { return err } - diskCache[diskName] = diskPtr - disk = diskCache[diskName] + continue } - partInt, err := strconv.Atoi(part) + // Regular partition + diskName := diskExpr.FindString(mnt.Partition) + part, err := strconv.Atoi(partExpr.FindString(mnt.Partition)) if err != nil { return err } - baseRoot := RootA - if mnt.Target == "/" && rootAMounted { - baseRoot = RootB - } else if mnt.Target == "/" && !rootAMounted { - rootAMounted = true + disk, ok := diskCache[diskName] + if !ok { + diskPtr, err := LocateDisk(diskName) + if err != nil { + return err + } + diskCache[diskName] = diskPtr + disk = diskCache[diskName] } - err = disk.Partitions[partInt-1].Mount(baseRoot + mnt.Target) + err = disk.Partitions[part-1].Mount(baseRoot + mnt.Target) if err != nil { return err }