@cdmonkey
2017-02-22T13:55:49.000000Z
字数 8790
阅读 1125
命令总结
http://blog.mr-zrz.com/%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%88%9B%E5%BB%BAlvm%E5%88%86%E5%8C%BA.html
http://man.linuxde.net/lvcreate
有如下存储:
Disk /dev/emcpowerh: 1099.5 GB, 1099511627776 bytes
255 heads, 63 sectors/track, 133674 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: 0x00000000
Disk /dev/emcpoweri: 1099.5 GB, 1099511627776 bytes
255 heads, 63 sectors/track, 133674 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: 0x00000000
...
首先创建物理卷(PV):
[root@t9db02 ~]# pvcreate /dev/emcpowerh
Physical volume "/dev/emcpowerh" successfully created
[root@t9db02 ~]# pvcreate /dev/emcpoweri
Physical volume "/dev/emcpoweri" successfully created
[root@t9db02 ~]# pvcreate /dev/emcpowerj
Physical volume "/dev/emcpowerj" successfully created
[root@t9db02 ~]# pvcreate /dev/emcpowerk
Physical volume "/dev/emcpowerk" successfully created
[root@t9db02 ~]# pvcreate /dev/emcpowerl
Physical volume "/dev/emcpowerl" successfully created
[root@t9db02 ~]# pvcreate /dev/emcpowerp
Physical volume "/dev/emcpowerp" successfully created
然后创建卷组(VG):
[root@t9db02 ~]# vgcreate T9DB02 /dev/emcpowerh /dev/emcpoweri /dev/emcpowerj /dev/emcpowerk /dev/emcpowerl /dev/emcpowerp
Found duplicate PV ph5n21iSpK2x0wXc3ANPdn0AldxWQWH2: using /dev/sdr not /dev/sdb
Volume group "T9DB02" successfully created
-------------
[root@t9db02 ~]# vgscan
Reading all physical volumes. This may take a while...
Found duplicate PV ph5n21iSpK2x0wXc3ANPdn0AldxWQWH2: using /dev/sdr not /dev/sdb
Found volume group "T9DB02" using metadata type lvm2
[root@t9db02 ~]# vgdisplay T9DB02
Found duplicate PV ph5n21iSpK2x0wXc3ANPdn0AldxWQWH2: using /dev/sdr not /dev/sdb
--- Volume group ---
VG Name T9DB02
System ID
Format lvm2
Metadata Areas 6
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 6
Act PV 6
VG Size 6.00 TiB
PE Size 4.00 MiB
Total PE 1572858
Alloc PE / Size 0 / 0
Free PE / Size 1572858 / 6.00 TiB
VG UUID pfjXHl-iXON-b4Cu-kxjE-1kKP-5G1s-b9PznP
创建逻辑卷(LV):
[root@t9db02 ~]# lvcreate -l 100%FREE T9DB02 -n lv_dbbackup
Found duplicate PV ph5n21iSpK2x0wXc3ANPdn0AldxWQWH2: using /dev/sdr not /dev/sdb
Logical volume "lv_dbbackup" created.
格式化
[root@t9db02 ~]# mkfs.ext4 /dev/mapper/T9DB02-lv_dbbackup
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
402653184 inodes, 1610606592 blocks
80530329 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
49152 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848, 512000000, 550731776, 644972544
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
挂载
[root@t9db02 ~]# mount -t ext4 /dev/mapper/T9DB02-lv_dbbackup /home/oracle/dbbackup/
[root@t9db02 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 518G 19G 473G 4% /
tmpfs 24G 202M 24G 1% /dev/shm
/dev/sda1 190M 41M 140M 23% /boot
/dev/mapper/T9DB02-lv_dbbackup
6.0T 56M 5.7T 1% /home/oracle/dbbackup
[root@HISDB ~]# vgscan
Reading all physical volumes. This may take a while...
Found duplicate PV 08JUGeuECScNSjsRANkBXhc08QR87drU: using /dev/sdal not /dev/sdaw
Found duplicate PV 0UU5sh3GACDzkxJobWZhvMcvjUV14x46: using /dev/sdz not /dev/sdak
Found duplicate PV 08JUGeuECScNSjsRANkBXhc08QR87drU: using /dev/sdaa not /dev/sdal
Found volume group "VolGroup" using metadata type lvm2
Found volume group "HISDB" using metadata type lvm2 # VG还在
但是“LV”处于未激活状态:
[root@HISDB ~]# lvscan
Found duplicate PV 08JUGeuECScNSjsRANkBXhc08QR87drU: using /dev/sdal not /dev/sdaw
Found duplicate PV 0UU5sh3GACDzkxJobWZhvMcvjUV14x46: using /dev/sdz not /dev/sdak
Found duplicate PV 08JUGeuECScNSjsRANkBXhc08QR87drU: using /dev/sdaa not /dev/sdal
ACTIVE '/dev/VolGroup/LogVol01' [987.25 GiB] inherit
ACTIVE '/dev/VolGroup/LogVol00' [128.00 GiB] inherit
inactive '/dev/HISDB/VolGroup-LogVol02' [3.00 TiB] inherit
进行激活:
[root@HISDB ~]# vgchange -ay HISDB
Found duplicate PV 08JUGeuECScNSjsRANkBXhc08QR87drU: using /dev/sdal not /dev/sdaw
Found duplicate PV 0UU5sh3GACDzkxJobWZhvMcvjUV14x46: using /dev/sdz not /dev/sdak
Found duplicate PV 08JUGeuECScNSjsRANkBXhc08QR87drU: using /dev/sdaa not /dev/sdal
1 logical volume(s) in volume group "HISDB" now active
[root@HISDB ~]# lvscan
Found duplicate PV 08JUGeuECScNSjsRANkBXhc08QR87drU: using /dev/sdal not /dev/sdaw
Found duplicate PV 0UU5sh3GACDzkxJobWZhvMcvjUV14x46: using /dev/sdz not /dev/sdak
Found duplicate PV 08JUGeuECScNSjsRANkBXhc08QR87drU: using /dev/sdaa not /dev/sdal
ACTIVE '/dev/VolGroup/LogVol01' [987.25 GiB] inherit
ACTIVE '/dev/VolGroup/LogVol00' [128.00 GiB] inherit
ACTIVE '/dev/HISDB/VolGroup-LogVol02' [3.00 TiB] inherit
到此就能够进行正常的挂载了。
下面是故障现象:
[root@T9DB02 ~]# mount /dev/vg_dbbackup/lv_dbbackup /home/oracle/dbbackup/
mount: /dev/vg_dbbackup/lv_dbbackup already mounted or /home/oracle/dbbackup/ busy
无论挂载到本地的任何目录都会报出上面的错误信息。我们首先将相对应的“Mapper”的信息移除掉:
[root@T9DB02 ~]# dmsetup remove vg_dbbackup-lv_dbbackup
device-mapper: remove ioctl failed: Device or resource busy
Command failed # 无法移除,显示该设备正忙。
[root@T9DB02 ~]# fuser -m /dev/mapper/vg_dbbackup-lv_dbbackup
/dev/mapper/vg_dbbackup-lv_dbbackup: 612c
[root@T9DB02 ~]# ps -ef|grep 612
oracle 612 611 0 14:36 pts/0 00:00:00 -bash # Need to kill this
root 5612 4435 0 Jan18 ? 00:00:00 [aio/20]
root 12358 4087 0 16:59 pts/2 00:00:00 grep --color=auto 612
grid 25612 1 0 Jan18 ? 00:00:00 asm_smon_+ASM2
grid 26128 1 0 Jan18 ? 00:00:00 /u01/app/11.2.0/grid/opmn/bin/ons -d
grid 26129 26128 0 Jan18 ? 00:01:17 /u01/app/11.2.0/grid/opmn/bin/ons -d
杀掉占用该逻辑卷的进程后重新挂载:
[root@T9DB02 ~]# dmsetup remove vg_dbbackup-lv_dbbackup
[root@T9DB02 ~]# dmsetup ls
VolGroup00-lv_swap (253, 1)
VolGroup00-lv_root (253, 0)
[root@T9DB02 ~]# ls /dev/mapper/
control VolGroup00-lv_root VolGroup00-lv_swap
# 没有找到该逻辑卷设备,证明我们已经将其正常的移除了。
重新扫描一下逻辑卷信息,发现该逻辑卷处于未激活的状态:
[root@T9DB02 ~]# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lv_root VolGroup00 -wi-ao 1.07T
lv_swap VolGroup00 -wi-ao 16.00G
lv_dbbackup vg_dbbackup -wi--- 3.39T
[root@T9DB02 ~]# lvscan
inactive '/dev/vg_dbbackup/lv_dbbackup' [3.39 TB] inherit
ACTIVE '/dev/VolGroup00/lv_root' [1.07 TB] inherit
ACTIVE '/dev/VolGroup00/lv_swap' [16.00 GB] inherit
重新激活该逻辑卷:
[root@T9DB02 ~]# vgchange -ay vg_dbbackup
1 logical volume(s) in volume group "vg_dbbackup" now active
---------------
[root@T9DB02 ~]# lvscan
ACTIVE '/dev/vg_dbbackup/lv_dbbackup' [3.39 TB] inherit
ACTIVE '/dev/VolGroup00/lv_root' [1.07 TB] inherit
ACTIVE '/dev/VolGroup00/lv_swap' [16.00 GB] inherit
激活后重新挂载:
[root@T9DB02 ~]# mount /dev/mapper/vg_dbbackup-lv_dbbackup /beifen/
[root@T9DB02 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-lv_root
1.1T 516G 495G 52% /
/dev/sda1 190M 14M 167M 8% /boot
tmpfs 253G 634M 252G 1% /dev/shm
/dev/mapper/vg_dbbackup-lv_dbbackup
3.4T 1.4T 1.8T 44% /beifen
查看下挂载后的情况:
[root@T9DB02 beifen]# ls
20160426L0.log archivebak databak lost+found mount-2016-04-28.txt
# 事实证明没有丢失任何的数据。
虚拟机的某个逻辑卷分区原大小60G
,后将该硬盘的空间增加到100G
,那么需要将逻辑卷分区进行扩容。
[root@PBSSXFJRDB ~]# df -h
Filesystem Size Used Avail Use% Mounted on
...
/dev/mapper/vg_home-lv_home
59G 390M 56G 1% /home
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
http://haoyou168.blog.51cto.com/284295/325865
[root@PBSSXFJRDB ~]# yum install parted
[root@PBSSXFJRDB ~]# partprobe /dev/sdc
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdc (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
[root@PBSSXFJRDB ~]# partx /dev/sdc
# 1: 2048-125829119 (125827072 sectors, 64423 MB)
# 2: 125829120-209712509 ( 83883390 sectors, 42948 MB)
# 3: 0- -1 ( 0 sectors, 0 MB)
# 4: 0- -1 ( 0 sectors, 0 MB)
[root@PBSSXFJRDB ~]# ls -al /dev/sd*
brw-rw---- 1 root disk 8, 0 May 24 11:57 /dev/sda
brw-rw---- 1 root disk 8, 1 May 23 18:16 /dev/sda1
brw-rw---- 1 root disk 8, 2 May 23 18:16 /dev/sda2
brw-rw---- 1 root disk 8, 16 May 24 11:57 /dev/sdb
brw-rw---- 1 root disk 8, 17 May 23 18:16 /dev/sdb1
brw-rw---- 1 root disk 8, 32 May 24 11:58 /dev/sdc
brw-rw---- 1 root disk 8, 33 May 23 18:16 /dev/sdc1
brw-rw---- 1 root disk 8, 34 May 24 12:00 /dev/sdc2 # 新增加分区。
进行格式化(略)。
#
[root@PBSSXFJRDB ~]# pvcreate /dev/sdc2
Physical volume "/dev/sdc2" successfully created
#
[root@PBSSXFJRDB ~]# vgextend vg_home /dev/sdc2
Volume group "vg_home" successfully extended
#
[root@PBSSXFJRDB ~]# lvextend -l +100%FREE /dev/mapper/vg_home-lv_home
Size of logical volume vg_home/lv_home changed from 60.00 GiB (15359 extents) to 99.99 GiB (25598 extents).
Logical volume lv_home successfully resized
# 最后:
[root@PBSSXFJRDB ~]# resize2fs /dev/vg_home/lv_home
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_home/lv_home is mounted on /home; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 7
Performing an on-line resize of /dev/vg_home/lv_home to 26212352 (4k) blocks.
The filesystem on /dev/vg_home/lv_home is now 26212352 blocks long.
扩容完成:
[root@PBSSXFJRDB ~]# df -h
Filesystem Size Used Avail Use% Mounted on
...
/dev/mapper/vg_home-lv_home
99G 398M 93G 1% /home