LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-17-2016, 05:01 PM   #1
thllgo
Member
 
Registered: Sep 2003
Location: Laurel MD
Posts: 296

Rep: Reputation: 32
/dev/mapper devices and how to use


Hello,
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
/dev/dm-0
/dev/dm-1
/dev/dm-2

"ls -la /dev/sd*" shows
/dev/sda
/dev/sda1
/dev/sda2

I added a new drive and ran an "fdisk /dev/sdb" and now I have in addition
/dev/sdb1
/dev/mapper/ddf1_4459...ba8
/dev/dm-3

There is a clear link between the 3 files
/dev/sdb1
/dev/dm-3
/dev/mapper/ddf1_4459...ba8


Questions
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
 
Old 06-17-2016, 06:27 PM   #2
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,318

Rep: Reputation: Disabled
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:
Code:
lvdisplay

vgdisplay

pvdisplay
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.
 
1 members found this post helpful.
Old 06-20-2016, 10:16 AM   #3
thllgo
Member
 
Registered: Sep 2003
Location: Laurel MD
Posts: 296

Original Poster
Rep: Reputation: 32
Firstly thank you for your help

lvdisplay only shows
/dev/centos/root
/dev/centos/home
/dev/centos/swap

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?
 
Old 06-20-2016, 10:24 AM   #4
thllgo
Member
 
Registered: Sep 2003
Location: Laurel MD
Posts: 296

Original Poster
Rep: Reputation: 32
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
/dev/mapper/centos-swap
/dev/mapper/centos-root
/dev/mapper/centos-home
/dev/mapper/ddf1_4459..ba8
 
Old 06-20-2016, 11:57 AM   #5
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,747

Rep: Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203
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"?
 
1 members found this post helpful.
Old 06-20-2016, 12:32 PM   #6
thllgo
Member
 
Registered: Sep 2003
Location: Laurel MD
Posts: 296

Original Poster
Rep: Reputation: 32
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.
 
Old 06-20-2016, 08:10 PM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 24,985

Rep: Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678
/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.
 
Old 06-21-2016, 12:55 PM   #8
thllgo
Member
 
Registered: Sep 2003
Location: Laurel MD
Posts: 296

Original Poster
Rep: Reputation: 32
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
 
Old 06-21-2016, 01:02 PM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 24,985

Rep: Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678
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?
 
Old 06-21-2016, 01:04 PM   #10
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,747

Rep: Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203
The output from "lsblk /dev/sdb" might show what it is being used for.
 
Old 06-21-2016, 01:32 PM   #11
thllgo
Member
 
Registered: Sep 2003
Location: Laurel MD
Posts: 296

Original Poster
Rep: Reputation: 32
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
 
Old 06-21-2016, 01:55 PM   #12
michaelk
Moderator
 
Registered: Aug 2002
Posts: 24,985

Rep: Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678
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?
 
Old 06-21-2016, 04:38 PM   #13
thllgo
Member
 
Registered: Sep 2003
Location: Laurel MD
Posts: 296

Original Poster
Rep: Reputation: 32
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
https://www.howtoforge.com/linux_lvm
 
Old 06-21-2016, 04:54 PM   #14
michaelk
Moderator
 
Registered: Aug 2002
Posts: 24,985

Rep: Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678Reputation: 5678
Possible, I thought I had tried it both ways and it worked on my system so I did not ask.
 
Old 06-21-2016, 04:59 PM   #15
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,747

Rep: Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203Reputation: 2203
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Which is faster /dev/mapper or /dev/cciss? mohamed.a.mostafa Red Hat 1 03-30-2013 06:30 PM
df -h shows /dev/mapper/ddf1...devices parkarnoor Linux - Newbie 1 08-14-2012 05:01 AM
LVM pvs is showing /dev/dm-x as PV name instead of /dev/mapper n0rus Linux - Enterprise 3 08-05-2012 01:12 PM
[SOLVED] CURRENT: LVM/CRYPTSETUP duplicate devices in /dev/mapper again. GazL Slackware 11 01-31-2011 07:36 PM
vgcreate command is changing /dev/mapper as PV Name in pvdisplay to /dev/dm-xx path neeravsingh Linux - Enterprise 6 03-23-2010 04:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration