创建物理卷报错Can't open /dev/sdb5 exclusively. Mounted filesystem的问题解决过程记录...

yum服务器lvm扩容,data目录是yum存放rpm包的目录,只有20G,需要添加磁盘扩容到80G

# df -lh
Filesystem                 Size  Used Avail Use% Mounted on
/dev/mapper/vg_node5-root   20G  479M   18G   3% /
tmpfs                      935M     0  935M   0% /dev/shm
/dev/sda1                  485M   39M  421M   9% /boot
/dev/mapper/vg_node5-data   20G  172M   19G   1% /data
/dev/mapper/vg_node5-usr   9.7G  1.6G  7.6G  18% /usr
/dev/mapper/vg_node5-web    15G  165M   14G   2% /web


1.添加一块硬盘


2.对硬盘分区,并将格式调整为8e即linux lvm格式
#挂载系统分区
# kpartx -l /dev/sdb
# kpartx -af /dev/sdb
# partx -a /dev/sdb


3.创建物理卷
在将几块盘做LVM时,遇到一个之前都没遇到过的问题:
# pvcreate /dev/sdb5
  Can't open /dev/sdb5 exclusively.  Mounted filesystem?
首先第一反应就是查看这个分区是否已经在使用了,但是没有。


查看硬盘的一些信息:


# cat /proc/partitions
major minor  #blocks  name


   8        0   83886080 sda
   8        1     512000 sda1
   8        2   83373056 sda2
   8       16  125829120 sdb
   8       17          1 sdb1
   8       21  125796982 sdb5
 253        0   20480000 dm-0
 253        1    4096000 dm-1
 253        2   15360000 dm-2
 253        3   20480000 dm-3
 253        4   10240000 dm-4
 253        5          1 dm-5
 253        6  125796982 dm-6




# fdisk /dev/sdb -l


Disk /dev/sdb: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x44c662ff


   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       15665   125829081    5  Extended
/dev/sdb5               5       15665   125796982+  8e  Linux LVM


接着看一些底层的信息:


dmsetup 是一个底层的逻辑卷管理, dm 应该是 Device Mapper的简称。
[root@node5 /]# dmsetup status
sdb1: 0 2 linear 
vg_node5-web: 0 30720000 linear 
sdb5: 0 251593965 linear 
vg_node5-usr: 0 20480000 linear 
vg_node5-swap: 0 8192000 linear 
vg_node5-root: 0 40960000 linear 
vg_node5-data: 0 40960000 linear 
[root@node5 /]# dmsetup ls
sdb1 (253:5)
vg_node5-web (253:2)
sdb5 (253:6)
vg_node5-usr (253:4)
vg_node5-swap (253:1)
vg_node5-root (253:0)
vg_node5-data (253:3)


例如:
root@ubuntu:~# dmsetup ls
35000c50026716847       (254, 2)
vg_data-lv_home (254, 0)
35000c5002670f03e       (254, 3)
35000c5002670f03e-part1 (254, 5)
35000c50026716847-part1 (254, 4)
vg_data-lv_swap (254, 1)
可以看到 35000c5002670f03e 和 35000c50026716847 组成了multipath(多路径)




# ll /dev/mapper/
total 0
crw-rw---- 1 root root 10, 58 Jul 26 19:51 control
lrwxrwxrwx 1 root root      7 Jul 26 19:59 vg_node5-data -> ../dm-3
lrwxrwxrwx 1 root root      7 Jul 26 19:59 /dev/sdb1 -> ../dm-5
lrwxrwxrwx 1 root root      7 Jul 26 19:59 /dev/sdb5 -> ../dm-6
lrwxrwxrwx 1 root root      7 Jul 26 19:59 vg_node5-root -> ../dm-0
lrwxrwxrwx 1 root root      7 Jul 26 19:59 vg_node5-swap -> ../dm-1
lrwxrwxrwx 1 root root      7 Jul 26 19:59 vg_node5-usr -> ../dm-4
lrwxrwxrwx 1 root root      7 Jul 26 19:59 vg_node5-web -> ../dm-2
使用 dmsetup remove xxx 移除掉就可以创建PV了:


# dmsetup remove /dev/sdb1
# dmsetup remove /dev/sdb5


重新创建物理卷成功
root@ubuntu:~# pvcreate /dev/sdb5
  Physical volume "/dev/sdb5" successfully created
也可以使用dmsetup remove_all移除所有。


# vgdisplay 
  --- Volume group ---
  VG Name               vg_node5
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                5
  Open LV               5
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               79.51 GiB
  PE Size               4.00 MiB
  Total PE              20354
  Alloc PE / Size       17250 / 67.38 GiB
  Free  PE / Size       3104 / 12.12 GiB
  VG UUID               tNuKXc-UdQO-Z8BK-ZtOQ-W93k-pqui-HAxKja


4.对物理卷vg_node5进行扩容
# vgextend vg_node5 /dev/sdb5
  Volume group "vg_node5" successfully extended
[root@node5 ~]# vgs
  VG       #PV #LV #SN Attr   VSize   VFree  
  vg_node5   2   5   0 wz--n- 199.47g 132.09g


将逻辑卷vg_node5-data即/data分区扩容到80G
[root@node5 ~]# lvextend -L 80G /dev/mapper/vg_node5-data 
  Extending logical volume data to 80.00 GiB
  Logical volume data successfully resized


重新读取大小
[root@node5 ~]# resize2fs /dev/mapper/vg_node5-data 
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_node5-data is mounted on /data; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 5
Performing an on-line resize of /dev/mapper/vg_node5-data to 20971520 (4k) blocks.
The filesystem on /dev/mapper/vg_node5-data is now 20971520 blocks long.


[root@node5 ~]# df -lh
Filesystem                 Size  Used Avail Use% Mounted on
/dev/mapper/vg_node5-root   20G  479M   18G   3% /
tmpfs                      935M     0  935M   0% /dev/shm
/dev/sda1                  485M   39M  421M   9% /boot
/dev/mapper/vg_node5-data   79G  184M   75G   1% /data
/dev/mapper/vg_node5-usr   9.7G  1.6G  7.6G  18% /usr
/dev/mapper/vg_node5-web    15G  165M   14G   2% /web

你可能感兴趣的:(创建物理卷报错Can't open /dev/sdb5 exclusively. Mounted filesystem的问题解决过程记录...)