You are not logged in.

#1 2014-06-09 12:28:19

Ovion
Member
Registered: 2013-02-24
Posts: 78

determine type of unmounted device (lvm, luks of filesystem)

Hi,

I'd like to determine the type of a given block-device, whether there is a luks or an lvm on it or whether it is carrying a filesystem.

I can deremine the relations of several devices by looking at /sys/block/$name/{holders,slaves}. For device-mapper there is /sys/block/[name]/dm/uuid, which seem to start with a device-type ("LVM-$uuid" and "CRYPT-LUKS1-$uuid"). However, as I want to use it in a script, I'm not sure if I can rely on that for parsing and it does't exactly solve my problem with what is actually *on* the device.

I finally want to determine things like "this is carrying a luks, is this luks already opened and if, is it mounted or not?" For that I need information not only what this device is but what's on there, because if a luks is unopened, I cannot determine that it's a luks via looking at the holders (as there are none).

Does anyone have an idea how to deal with this or where I can read out this information? I could brute-force it by asking lvm, cryptsetup and so on, however, this seems quite unelegant to me, there might be a better way, doesn't it?

Thanks in advance!

Last edited by Ovion (2014-06-14 17:46:18)

Offline

#2 2014-06-10 07:26:18

R3D
Member
Registered: 2014-01-12
Posts: 14

Re: determine type of unmounted device (lvm, luks of filesystem)

I dont know of a single utility. you could parse through /etc/crypttab and use vgdisplay with grep.


"Do not attribute to malice that which can be explained through incompetence"

Offline

#3 2014-06-10 15:39:42

Leonid.I
Member
From: Aethyr
Registered: 2009-03-22
Posts: 999

Re: determine type of unmounted device (lvm, luks of filesystem)

man 8 lsblk


Arch Linux is more than just GNU/Linux -- it's an adventure
pkill -9 systemd

Offline

#4 2014-06-10 16:05:30

clfarron4
Member
From: London, UK
Registered: 2013-06-28
Posts: 2,163
Website

Re: determine type of unmounted device (lvm, luks of filesystem)

Leonid.I wrote:

man 8 lsblk

This.

The number of times I've used lsblk to work out what is there is unbelievable.


Claire is fine.
Problems? I have dysgraphia, so clear and concise please.
My public GPG key for package signing
My x86_64 package repository

Offline

#5 2014-06-13 13:28:41

Ovion
Member
Registered: 2013-02-24
Posts: 78

Re: determine type of unmounted device (lvm, luks of filesystem)

lsblk is awesome! big_smile Thanks a lot!

Edit: nope, not exactely what I was looking for (but still quite awesome big_smile).

The Problem is that lsblk is just working for already mounted/opened/... devices. What I plan to do is to use it in a way that I determine the type on a device (e.g. crypt) in a program and if this cryptocontainer is not open, I want to automatically open it. To know that I must call cryptsetup I must know what's on a device (e.g. crypt) before it's opened so that my script knows it has to open that with cryptsetup.

Any way to do this?

Last edited by Ovion (2014-06-13 14:14:57)

Offline

Board footer

Powered by FluxBB