-   Linux - Server (
-   -   /dev/mapper devices and how to use (

thllgo 06-17-2016 04:01 PM

/dev/mapper devices and how to use
How do I work with /dev/mapper devices on Centos 7, and yes I know its an old OS but the customer insists on using it.
I'm used to just working with devices such as /dev/sdb1 but I now have a system that is using dev mapper and have not used this before. My attempts to google the info have come up short

I have a desktop
"ls -la /dev/mapper" shows
centos-home -> ../dm-2
centos-root -> ../dm-1
centos-swap -> ../dm-0

"ls -la /dev/dm*" shows

"ls -la /dev/sd*" shows

I added a new drive and ran an "fdisk /dev/sdb" and now I have in addition

There is a clear link between the 3 files

1. How do I give /dev/mapper/ddf1_4459...ba8 and better name like was done with centos-root above
2. How do I link /dev/mapper/ddf1_4459...ba8 to /dev/dm-3
3. What device do I run mkfs on? I've tried to run mkfs on /dev/dm-3, /dev/sdb1, /dev/mapper/ddf1_4459..ba8 and it fails on them all
4. A good site that explains how these devices are connected and how to use them

Thank you

Ser Olmy 06-17-2016 05:27 PM

The server in question is using Logical Volume Manager (LVM), which is a vastly superior way to manage storage space compared to just creating regular partitions with file systems on various disks.

The devices in /dev/mapper are Logical Volumes. These are virtual block devices carved out of storage space allocated to one or more Volume Groups. The Volume Groups in turn are created from a number of Physical Volumes, which can be entire block devices or partitions.

Try the following commands and see if things don't start to make sense:




Also, you shouldn't try to change the names of the devices. The subfolders under /dev/mapper are actually names of Volume Groups, and the device nodes in those subfolders represent Logical Volumes.

Rather then using device names (be they /dev/sdaX or /dev/mapper/something/or_other), you should just refer to UUIDs or even labels in /etc/fstab. That way it makes no difference what the actual device is called, which is something you'll learn to appreciate when a new disk or array volume is added to a system and it ends up being enumerated before one of the existing disks.

thllgo 06-20-2016 09:16 AM

Firstly thank you for your help

lvdisplay only shows

vgdisplay shows 1 disk it calls centos

pvdisplay only shows
PV name /dev/sda2
VG name centos

None of the commands show the added disk in the system. The only thing to show the added disk is /dev/sdb /dev/sdb1

How do I get LVM to recognize the second disk?

thllgo 06-20-2016 09:24 AM

additional info

pvscan -u only shows 1 disk at /dev/sda2 only one partition

fdisk -l shows
/dev/sda a 320GB drive with /dev/sda1 /dev/sda2
/dev/sdb a 500GB drive with /dev/sdb1

rknichols 06-20-2016 10:57 AM

Was this drive really "new"? It appears to have already been partitioned and something stored in partition 1.

To make the drive available for LVM you would need to run "pvcreate /dev/sdb1", but since that's going to overwrite whatever is on that partition, let's first see if there is anything on there that you might want to save. What is the output from "lsblk /dev/sdb" and "file -s /dev/sdb1"?

thllgo 06-20-2016 11:32 AM

Yes it was new I had done a fdisk on /dev/sdb to create /dev/sdb1. I tried to run an mkfs on /dev/sdb1 but to no avail I ran the pvcreate on /dev/sdb1 and it failed. I found out there was a new /dev/dm-3 and discovered it was the new disk. I could run an mkfs on /dev/dm-3 and was able to mount /dev/dm-3.

There is still nothing in /dev/mapper for this new drive. Also neither vgdisplay or lvdisplay show any info on the new drive. After running the pvcreate there is an entry in pvdisplay.

Curiously the old disk has
PV Name = /dev/sda2

The new disk has
PV Name = /dev/disk/by-id/dm-name-ddf1.....ba8

I don't understand the inconsistencies
1. For the old disk pvdisplay only shows /dev/sda2 but not /dev/sda1
2. The PV name for the old drive is /dev/sda2 where as the new drive is a /dev/disk/by-id name.

I'm still very confused but it's working
Thanks for all your help.

michaelk 06-20-2016 07:10 PM

/boot is a regular partition and not part of the LVM. legacy grub could not boot from a LVM and I assume it was Redhat's decision to keep it that way.

I have a CentOS 7 virtual machine and I added a new disk to see what happens. Nothing in /dev/mapper or a /dev/dm was created until I added the logical volume. /dev/disk/by-id was automatically created.

Very odd that you could not create a filesystem using /dev/sdb1 or create a PV. Would be interesting to know what error messages were displayed. None of the posted commands by Ser Olmy would create anything. They only displayed the current information.

Post the output from the lsblk command.

thllgo 06-21-2016 11:55 AM

Attempting to use /dev/sdb1 directly resulted in the error partition is in use

Name MAJ:MIN RM SIZE RO Type Mountpoint
sda 8:0 0 298.1G 0 disk
---sda1 8:1 0 500MB 0 part /boot
---sda2 8:2 0 232.4G 0 part
------centos-swap 253:0 0 7.9G 0 lvm [SWAP]
------centos-root 253:1 0 50G 0 lvm /
------centos-home 253:2 0 174G 0 lvm /home
sdb 8:16 0 465.8G 0 disk
---sdb1 8:17 0 465.8 0 part

got a /dev/disk/by-id and a /dev/dm entry when I booted with the new disk
still no /dev/mapper entry

michaelk 06-21-2016 12:02 PM

Since you never created a PV, VG or LV no /dev/mapper was created.

In addition you can not create format any of the above if the partition is mounted. So is this an internal or external drive?

rknichols 06-21-2016 12:04 PM

The output from "lsblk /dev/sdb" might show what it is being used for.

thllgo 06-21-2016 12:32 PM

Steps I did

1. Install new disk and boot
2. After booting I had a new /dev/disk/by-id and /dev/sdb
3. I ran fdisk on /dev/sdb to get /dev/sdb1, this also created the /dev/dm device though I did not realize it at the time. The /dev/dm device is now equivalent to /dev/sdb1. According to one website I reviewed it said if you have a /dev/dm device you can't use the /dev/sd device since the /dev/sd device is being used by the devmapper software.
4. I tried to run mkfs on /dev/sdb1 and received the error the drive was mounted or busy, it was not being used for anything
5. I tried to run mkfs on /dev/dm-3 and got the same error as when I ran it on /dev/sdb1
6. I read on another website don't use /dev/sdb1 use the /dev/dm device and run a pvcreate on the device first then use as normal
7. I ran the pvcreate on /dev/dm-3 then ran the mkfs on /dev/dm-3 and then mounted /dev/dm-3

michaelk 06-21-2016 12:55 PM

I will have to play more since my system does not behave like yours.

Running mkfs without creating a VG or LV basically erased the PV so you just have a regular partition. Did you want to add the new drive space to an existing LV or keep it separate?

thllgo 06-21-2016 03:38 PM

I think I found out why I couldn't do a pvcreate on /dev/sdb1
When I ran fdisk on it, I did not change it's partition type to LVM

Found an informative page at

michaelk 06-21-2016 03:54 PM

Possible, I thought I had tried it both ways and it worked on my system so I did not ask.

rknichols 06-21-2016 03:59 PM

Linux doesn't care about the partition type. The only types that are treated specially are the "extended" types (codes 0x05, 0x85, and 0x0f) and a couple of others like the BSD type that can contain subpartitons. All that matters in the others is their content. The partition types are irrelevant except for human recognition.

All times are GMT -5. The time now is 06:22 AM.