Can’t open /dev/sdb1 exclusively. Mounted filesystem?

I got this error when I tried to add a volume group in my VBOX Linux (guest) environment using the following command:

# pvcreate /dev/sdb1

Listing all my disk show this

# fdisk -l

Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        7832    62806117+  8e  Linux LVM

Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        5221    41937651   8e  Linux LVM

Disk /dev/dm-5: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

     Device Boot      Start         End      Blocks   Id  System
/dev/dm-5p1               1        5221    41937651   8e  Linux LVM

Strangely /dev/dm-5 matche the new disk that I have declared and then locking the disk when I tried to use it.
Please Refer to Redhat documentation: https://access.redhat.com/site/documentation/fr-FR/Red_Hat_Enterprise_Linux/6/html/DM_Multipath/ignore_localdisk_procedure.html

To solve this issue quicky, apply the following command:

#dmsetup status
SATA_VBOX_HARDDISK_VB0328c5be-a314686b_: 0 83886080 multipath 2 0 0 0 1 1 A 0 1 0 8:16 A 0
root_vg-lv_var: 0 4194304 linear
root_vg-lv_var: 4194304 16777216 linear
root_vg-lv_home: 0 2097152 linear
root_vg-lv_home: 2097152 18874368 linear
root_vg-lv_swap: 0 2162688 linear
root_vg-lv_root: 0 8388608 linear
root_vg-lv_root: 8388608 62914560 linear
root_vg-lv_tmp: 0 2097152 linear
root_vg-lv_tmp: 2097152 6291456 linear

# dmsetup ls
SATA_VBOX_HARDDISK_VB0328c5be-a314686b_ (253, 5)
root_vg-lv_var  (253, 3)
root_vg-lv_home (253, 2)
root_vg-lv_swap (253, 4)
root_vg-lv_root (253, 0)
root_vg-lv_tmp  (253, 1)

# ls /dev/mpath/*
/dev/mpath/SATA_VBOX_HARDDISK_VB0328c5be-a314686b_

# dmsetup remove SATA_VBOX_HARDDISK_VB0328c5be-a314686b_
# fdisk -l

Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        7832    62806117+  8e  Linux LVM

Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        5221    41937651   8e  Linux LVM

Now your (iscsi)-disk is not locked by the Device Mapper and you can then apply the disk-related command.

An easiest way to solve this issue to to provide this simple command (works for me)

dmsetup remove_all

Another solution is to applied what is described here: http://www.centos.org/docs/5/html/5.1/DM_Multipath/ignore_localdisk_procedure.html

Or to make it persistent after a reboot, you can use the following command:

vi /etc/multipathd.conf

blacklist {
devnode "*"
}

More to come …

Advertisements

About Chenda Mok

19 years of hands on experience in software design and development with emphasis on Enterprise Application Integration (EAI), Services Oriented Architecture (SOA) and Identity Management (IDM) solutions. I’m a software engineer, member of the professional service delivery team working for Salesforce. Prior to this, I worked for Oracle as Solution Architect, through SeeBeyond(06/2005), then SUN’s acquisition (04/2009). After my master’s degree in computer science in 1997; I always delivered consulting on architecture, design, implementation on integration’s field. I’m interested in architecture using EAI/SOA/IDM/BPM/Cloud technologies, software development and Java’s related technologies. I may blog about my work/activities at Salesforce, but I do not speak for my employer, past, present or future.
This entry was posted in commands, Linux, VBox and tagged , , . Bookmark the permalink.