Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⭐️ detect logical volume and block device #4063

Closed
wants to merge 1 commit into from
Closed

Conversation

afiune
Copy link
Contributor

@afiune afiune commented May 23, 2024

Most modern Linux distributions use Logical Volume Manager (LVM) as a device mapper,
in such cases, we need to guess the block device so that we can mount the
attached disk, if not, we will get the error:

DBG found block device children=[{"fstype":"vfat","name":"sdd1","uuid":"6BDD-84EA"},{"fstype":"xfs","label":"boot","name":"sdd2","uuid":"9dd560e5-b943-4e7f-b05f-e79021d9b117"},{"name":"sdd3"},{"name":"sdd4"},{"children":[{"fstype":"xfs","name":"rocky-root","uuid":"73976867-73e1-4771-8799-d725d54fa440"}],"fstype":"LVM2_member","name":"sdd5","uuid":"VtYqiy-LKfB-HUNG-1JMw-z1J2-erkv-J1DxAs"}] mountpoint= name=sdd
DBG found match
DBG found target volume device name=/dev/sdd5
DBG mount volume to scan dir device=/dev/sdd5 fstype=LVM2_member opts= scandir=/tmp/cnspec-scan4160323020
x failed to mount dir error="no such device" attached-fs=/dev/sdd5 fs-type=LVM2_member opts= scan-dir=/tmp/cnspec-scan4160323020
x unable to complete mount step error="no such device"

This PR adds a detection for LVM devices, if one is found, we try to detect the block device
and use it to mount the volume.

Tested on a running VM, works as expected:

DBG found block device children=[{"fstype":"vfat","name":"sdd1","uuid":"6BDD-84EA"},{"fstype":"xfs","label":"boot","name":"sdd2","uuid":"9dd560e5-b943-4e7f-b05f-e79021d9b117"},{"name":"sdd3"},{"name":"sdd4"},{"children":[{"fstype":"xfs","name":"rocky-root","uuid":"73976867-73e1-4771-8799-d725d54fa440"}],"fstype":"LVM2_member","name":"sdd5","uuid":"VtYqiy-LKfB-HUNG-1JMw-z1J2-erkv-J1DxAs"}] mountpoint= name=sdd
DBG found match
DBG found target volume device name=/dev/rocky-root
DBG logical volume detected, getting block device name=/dev/rocky-root uuid=73976867-73e1-4771-8799-d725d54fa440
DBG block device found, setting as new device name device=/dev/mapper/rocky-root
DBG mount volume to scan dir device=/dev/mapper/rocky-root fstype=xfs opts=nouuid scandir=/tmp/cnspec-scan3433523306
DBG load filesystem path=/tmp/cnspec-scan3433523306

Copy link
Contributor

github-actions bot commented May 23, 2024

Test Results

3 004 tests   3 003 ✅  1m 27s ⏱️
  332 suites      1 💤
   23 files        0 ❌

Results for commit 7842be0.

♻️ This comment has been updated with latest results.

@afiune afiune force-pushed the afiune/mount-lvm branch 2 times, most recently from fcde09e to fb4e731 Compare May 23, 2024 22:22
Most modern Linux distributions use
[Logical Volume Manager (LVM)](https://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux))
as a device mapper, in such cases, we need to guess
the block device so that we can mount the attached
disk, if not, we will get the error:

```
DBG found block device children=[{"fstype":"vfat","name":"sdd1","uuid":"6BDD-84EA"},{"fstype":"xfs","label":"boot","name":"sdd2","uuid":"9dd560e5-b943-4e7f-b05f-e79021d9b117"},{"name":"sdd3"},{"name":"sdd4"},{"children":[{"fstype":"xfs","name":"rocky-root","uuid":"73976867-73e1-4771-8799-d725d54fa440"}],"fstype":"LVM2_member","name":"sdd5","uuid":"VtYqiy-LKfB-HUNG-1JMw-z1J2-erkv-J1DxAs"}] mountpoint= name=sdd
DBG found match
DBG found target volume device name=/dev/sdd5
DBG mount volume to scan dir device=/dev/sdd5 fstype=LVM2_member opts= scandir=/tmp/cnspec-scan4160323020
x failed to mount dir error="no such device" attached-fs=/dev/sdd5 fs-type=LVM2_member opts= scan-dir=/tmp/cnspec-scan4160323020
x unable to complete mount step error="no such device"
```

This commit adds a detection for LVM devices, if one is
found, we try to detect the block device and use it to
mount the volume.

Tested on a running VM, works as expected:
```
DBG found block device children=[{"fstype":"vfat","name":"sdd1","uuid":"6BDD-84EA"},{"fstype":"xfs","label":"boot","name":"sdd2","uuid":"9dd560e5-b943-4e7f-b05f-e79021d9b117"},{"name":"sdd3"},{"name":"sdd4"},{"children":[{"fstype":"xfs","name":"rocky-root","uuid":"73976867-73e1-4771-8799-d725d54fa440"}],"fstype":"LVM2_member","name":"sdd5","uuid":"VtYqiy-LKfB-HUNG-1JMw-z1J2-erkv-J1DxAs"}] mountpoint= name=sdd
DBG found match
DBG found target volume device name=/dev/rocky-root
DBG logical volume detected, getting block device name=/dev/rocky-root uuid=73976867-73e1-4771-8799-d725d54fa440
DBG block device found, setting as new device name device=/dev/mapper/rocky-root
DBG mount volume to scan dir device=/dev/mapper/rocky-root fstype=xfs opts=nouuid scandir=/tmp/cnspec-scan3433523306
DBG load filesystem path=/tmp/cnspec-scan3433523306
```

Signed-off-by: Salim Afiune Maya <[email protected]>
@afiune afiune force-pushed the afiune/mount-lvm branch from fb4e731 to 7842be0 Compare May 23, 2024 22:27
continue
}
}
log.Debug().Msg("found match")
for i := range d.Children {
entry := d.Children[i]
if entry.IsNotBootOrRootVolumeAndUnmounted() {
devFsName := "/dev/" + entry.Name
return &fsInfo{Name: devFsName, FsType: entry.FsType}, nil
if strings.Contains(entry.FsType, "LVM2") && len(entry.Children) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we extract this into a IsLVMPartition function?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that way we dont repeat the logic in two places

if err != nil {
return err
}
fsInfo.Name = strings.Trim(string(data), "\t\n")
Copy link
Contributor

@vjeffrey vjeffrey May 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can u put an example here of what u expect before the strings trim?

@@ -107,8 +108,34 @@ func (m *VolumeMounter) mountVolume(fsInfo *fsInfo) error {
if fsInfo.FsType == "xfs" {
opts = append(opts, "nouuid")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll probably be able to organize this logic a bit more once #4101 is in as well.
that could allow us to kinda "tier" the options...like this LVM check feels like it could be a little earlier in the func?

@afiune
Copy link
Contributor Author

afiune commented May 28, 2024

We currently don't support LVM. Closing for now.

@afiune afiune closed this May 28, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants