Skip to content

Commit

Permalink
recipe: Handle LVM mountpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
matbme committed Oct 13, 2023
1 parent 0e4b345 commit 3085c59
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions core/recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -819,33 +816,49 @@ func (recipe *Recipe) SetupMountpoints() error {
mount_depth += 1
}

lvmExpr := regexp.MustCompile(`^/dev/(?P<vg>[\w-]+)/(?P<lv>[\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
}
Expand Down

0 comments on commit 3085c59

Please sign in to comment.