microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.54k stars 823 forks source link

Logical Volume Groups is not importing(LVM2) #7566

Closed ChroniKom closed 9 months ago

ChroniKom commented 3 years ago

Version

Microsoft Windows [Version 10.0.22000.258]

WSL Version

Kernel Version

5.10.60.1

Distro Version

Ubuntu 20.04

Other Software

LVM2 (2.03.07-1ubuntu1)

adlin@ServerPC:/mnt/c/Users/admin$ sudo apt install lvm2 Reading package lists... Done Building dependency tree Reading state information... Done lvm2 is already the newest version (2.03.07-1ubuntu1). 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Repro Steps

1) Assign HDD into WSL as a --bare hard drive with exported Logical Volume Groups inside of it PS: the HardDrive is not Initialized by Windows DiskManager, to get access to it only through WSL

wsl --mount \.\PHYSICALDRIVE_ADDRESS --bare

2) Try to import Volume Group using LVM2 default commands $: pvscan $: vgimport vg_name $: vgchange -ay vg_name

3) check if Volume Group imported successfully to see the data inside of HardDrive, to mount it in future $: ls /dev/vg_name/

Expected Behavior

vg_name to be imported and files to be accessed from Hard Drive

Actual Behavior

there is no vg_name is imported while trying to simply access the files using volume group name but paths is getting displayed by lvdisplay command

adlin@ServerPC:/mnt/c/Users/admin$ ll /dev/vgpool/public ls: cannot access '/dev/vgpool/public': No such file or directory

Diagnostic Logs

Output of Console is attached:

adlin@ServerPC:/mnt/c/Users/admin$ sudo lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 256G 0 disk sdb 8:16 0 339.8M 1 disk sdc 8:32 0 7.3T 0 disk sdd 8:48 0 256G 0 disk /

adlin@ServerPC:/mnt/c/Users/admin$ sudo pvscan PV /dev/sdc is in exported VG vgpool [<7.28 TiB / 6.14 TiB free] Total: 1 [<7.28 TiB] / in use: 1 [<7.28 TiB] / in no VG: 0 [0 ]

adlin@ServerPC:/mnt/c/Users/admin$ sudo vgimport vgpool Volume group "vgpool" successfully imported

adlin@ServerPC:/mnt/c/Users/admin$ sudo vgchange -ay vgpool 3 logical volume(s) in volume group "vgpool" now active

adlin@ServerPC:/mnt/c/Users/admin$ sudo lvdisplay --- Logical volume --- LV Path /dev/vgpool/stream LV Name stream VG Name vgpool LV UUID KRA3VC-899P-skZX-KR2F-0KeV-eqLK-naz2Sl LV Write Access read/write LV Creation host, time linux_srv, 2020-02-27 21:32:41 +0100 LV Status available # open 0 LV Size 150.00 GiB Current LE 38400 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:0

--- Logical volume --- LV Path /dev/vgpool/media LV Name media VG Name vgpool LV UUID JrpclX-1hT7-9mBe-0aUG-6371-vv2g-nOAgGW LV Write Access read/write LV Creation host, time linux_srv, 2020-02-27 22:03:14 +0100 LV Status available # open 0 LV Size 1000.00 GiB Current LE 256000 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:1

--- Logical volume --- LV Path /dev/vgpool/public LV Name public VG Name vgpool LV UUID W3AsW2-PIUW-fDTr-PURv-oDQW-jRnp-ndEPZ6 LV Write Access read/write LV Creation host, time home-pr-server, 2020-06-30 17:50:40 +0200 LV Status available # open 0 LV Size 10.00 GiB Current LE 2560 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:2

adlin@ServerPC:/mnt/c/Users/admin$ ll /dev/vgpool/public ls: cannot access '/dev/vgpool/public': No such file or directory

adlin@ServerPC:/mnt/c/Users/admin$ lsb_release -r Release: 20.04

OneBlue commented 3 years ago

Thanks for reporting this @ChroniKom.

LVM isn't officially supported by wsl --mount, but I think this can work. What I'd do would be to manually start lvmetad, which is necessary to access lvm volumes before running any lvm commands.

ChroniKom commented 3 years ago

@OneBlue thanks for helping on this, probably i'm wrong here, but this is what i did:

adlin@ServerPC:/mnt/c/Users/admin$ sudo service --status-all | grep lvm2
 [ - ]  lvm2
 [ - ]  lvm2-lvmpolld

i dont see lvmetad service at all in the list i've tried to reinstall LVM2 by using:

sudo apt-get purge lvm2
sudo apt autoremove
sudo apt install lvm2

but still no luck, it's only lvmpolld in the list

OneBlue commented 3 years ago

service isn't supported inside WSL right now, so to get those daemon running manually you'd need to look at the service files and start those manually.

After having a quick look at the service files, what I'd try would be something like this:

/sbin/lvmpolld -t 60 -f
ChroniKom commented 3 years ago

@OneBlue yes, i did run this, still no luck with importing the Volume Group, while this daemon is running looks like at this point of time to just access VolumeGroup data, regular VM is better choice

thanks for your help anyway, i appreciate

neon64 commented 3 years ago

I too have encountered this issue when trying to access a LVM on LUKS filesystem I set up for dual-booting Linux.

If I could get LVM working in WSL, then I could do Linux development work directly within Windows (also making use of WSLg to run GUI apps seamlessly on the Windows desktop), but then also reboot into Linux directly when needed. I already accomplished this with VirtualBox "raw disk images", but it is ever so slightly unstable, and also their seamless mode is nowhere near as crisp as WSLg, which I am really excited to try.

At this point in time I don't really use any of the features of LVM, I just set it up that way for flexibility, and it would be annoying to wipe that partition to convert it to a plain LUKS-encrypted partition. I tried running lvmpolld manually as described above, but it didn't appear to help - I still couldn't gett logical volumes to show up in /dev.

I'm not super familiar with LVM, but from what I understand, it uses udev to create the device nodes as required. All the LVM commands seem to work fine (e.g.: sudo lvs or sudo vgs). My next attempt involved manually running systemd-udevd - this finally gave some errors, since WSL doesn't use systemd as it's init system, so systemd-udevd was calling systemd-run which then failed.

What finally worked (albeit kind of a hack), was to use https://github.com/sorah/subsystemctl (or a similar project https://github.com/arkane-systems/genie) to create a container in which systemd is PID 1, and then mount the drive, use cryptsetup open to unlock the encrypted partition, and then logical volumes show up as they are supposed to.

This has the significant downside of requiring the use of this extra container, so instead of just running wsl, I instead have to write wsl subsystemctl shell or similar. It would be cool to find out what extra work is required to get LVM working natively in WSL. I suspect the missing piece might be a (modified?) version of udevd without the systemd dependency? Perhaps someone can point me in the right direction.

akarasulu commented 2 years ago

This topic and proper support for LVM should be reopened. It's an integral part of storage management for Linux systems. WSL2 would be incomplete without LVM.

wxfjamdc commented 2 years ago

Did you forget to "mount /dev/vgpool/public /mnt/{vgpool}".

ChroniKom commented 2 years ago

https://github.com/microsoft/WSL/issues/7566#issuecomment-1056049985

Did you forget to "mount /dev/vgpool/public /mnt/{vgpool}".

there is nothing to mount actuyally, as volume group is displays as empty while trying to access that location

but when trying to see the records by lvdisplay it shows the lvm's not sure if it's fixed or work already in WSL

omnisip commented 2 years ago

This doesn't work that I can see. The LVM device nodes aren't created even if lvdisplay works.

ChroniKom commented 2 years ago

This doesn't work that I can see. The LVM device nodes aren't created even if lvdisplay works.

can try to reopen this then, i'm not using it this way anymore, probably somebody from developers will take a look

Czuz commented 1 year ago

I've got same issue, i.e.: vgscan and vgchange -ay completes successfully but VG is not available under /dev/. vgdisplay and lvdisplay shows correct configuration.

wsl --version

Wersja podsystemu WSL: 1.0.0.0 Wersja jądra: 5.15.74.2 Wersja usługi WSLg: 1.0.47 Wersja MSRDC: 1.2.3575 Wersja Direct3D: 1.606.4 Wersja DXCore: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp wersja Windows: 10.0.19045.2311

Kernel: 5.15.74.2-microsoft-standard-WSL2

$ sudo lvm version

LVM version: 2.03.07(2) (2019-11-30) Library version: 1.02.167 (2019-11-30) Driver version: 4.45.0 Configuration: ./configure --build=x86_64-linux-gnu --prefix=/usr --includedir=${prefix}/include --mandir=${prefix}/share/man --infodir=${prefix}/share/info --sysconfdir=/etc --localstatedir=/var --disable-silent-rules --libdir=${prefix}/lib/x86_64-linux-gnu --libexecdir=${prefix}/lib/x86_64-linux-gnu --runstatedir=/run --disable-maintainer-mode --disable-dependency-tracking --exec-prefix= --bindir=/bin --libdir=/lib/x86_64-linux-gnu --sbindir=/sbin --with-usrlibdir=/usr/lib/x86_64-linux-gnu --with-optimisation=-O2 --with-cache=internal --with-device-uid=0 --with-device-gid=6 --with-device-mode=0660 --with-default-pid-dir=/run --with-default-run-dir=/run/lvm --with-default-locking-dir=/run/lock/lvm --with-thin=internal --with-thin-check=/usr/sbin/thin_check --with-thin-dump=/usr/sbin/thin_dump --with-thin-repair=/usr/sbin/thin_repair --enable-applib --enable-blkid_wiping --enable-cmdlib --enable-dmeventd --enable-dbus-service --enable-lvmlockd-dlm --enable-lvmlockd-sanlock --enable-lvmpolld --enable-notify-dbus --enable-pkgconfig --enable-readline --enable-udev_rules --enable-udev_sync

inmadria commented 1 year ago

Try to follow these steps:

  1. sudo cryptsetup luksOpen /dev/sdc3 lukspart (if your device is encrypted) and type the passphrase.
  2. sudo vgscan (optional)
  3. sudo vgchange -ay
  4. sudo lvscan (optional)
  5. sudo mount /dev/dm-1 /mnt/disk/ (here dm-1 is the root device I wanted to mount).

and to eject the device, follow these steps:

  1. sudo umount /mnt/disk/
  2. sudo vgchange -an
  3. sudo cryptsetup luksClose lukspart
omnisip commented 1 year ago

The problem isn't lvscan, vgscan, or pvscan. It's that the normal mechanism for making device nodes (udev) doesn't exist or doesn't work on wsl.

There is a command to make the device nodes manually.

Try "dmsetup mknodes"

If that doesn't work, dig through the udev stuff until you find the same command it uses.

omnisip commented 1 year ago

You may have to run vgscan or lvscan before the dmsetup command.

Czuz commented 1 year ago

Thank you!

dmsetup mknodes have done the trick. Devices has been created as /dev/mapper/- instead of /dev// but I can mount them anyway.

inmadria commented 1 year ago

@Czuz don't you have /dev/dm-XX? I was able to mount these devices. @omnisip I never said that *scan solve the problem. It's just optional command to understand the system state.

Czuz commented 1 year ago

@Czuz don't you have /dev/dm-XX? I was able to mount these devices.

No - this was the issue. dmsetup mknodes solved it.

MichelDiz commented 1 year ago

I use Proxmox and they use LVM file system. I use Proxmox with Windows boxes to do test env of building process. Sometimes I do some edgy tests in Proxmox and it breaks. I can use another distro to fix it. But from WSL would be pretty handy.

ChrisLynchHPE commented 1 year ago

I too can confirm dmsetup mknodes helps. However, in my case the logical volumes were all inactive. I had to make them active first before running dmsetup mknodes. Then, they show up in /dev/mapper/{vg_name]-{lv_name}. Mount was successful and I can complete my workflow.

microsoft-github-policy-service[bot] commented 9 months ago

This issue has been automatically closed since it has not had any activity for the past year. If you're still experiencing this issue please re-file this as a new issue or feature request.

Thank you!