當前位置:
首頁 > 知識 > LVM邏輯卷管理遇到的問題

LVM邏輯卷管理遇到的問題

LVM學習邏輯卷管理創建邏輯卷遇到的問題

1 實驗環境

系統 內核 發行版本

CentOS 2.6.32-754.2.1.el6.x86_64 CentOS release 6.10 (Final)

LVM邏輯卷管理遇到的問題

由於是最小化安裝沒有xfs命令,yum安裝如下包支持此命令

[root@www ~]# yum install xfsprogs
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package xfsprogs.x86_64 0:3.1.1-20.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================
Package Arch Version Repository Size
======================================================================================================
Installing:
xfsprogs x86_64 3.1.1-20.el6 base 725 k
Transaction Summary
======================================================================================================
Install 1 Package(s)
Total download size: 725 k
Installed size: 3.2 M
Is this ok [y/N]: y
Downloading Packages:
xfsprogs-3.1.1-20.el6.x86_64.rpm | 725 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : xfsprogs-3.1.1-20.el6.x86_64 1/1
Verifying : xfsprogs-3.1.1-20.el6.x86_64 1/1
Installed:
xfsprogs.x86_64 0:3.1.1-20.el6
Complete!

2 用gdisk分區對/dev/sdb分區然後再刪除後遇到以下問題

[root@www ~]# pvcreate /dev/sdb
Device /dev/sdb not found (or ignored by filtering)

3 解決方法

開始嘗試使用partprobe /dev/sdb但是沒有用處,後來用如下命令解決.
[root@www ~]# dd if=/dev/urandom of=/dev/sdb bs=512 count=64
64+0 records in
64+0 records out
32768 bytes (33 kB) copied, 0.0513912 s, 638 kB/s
[root@www ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 4.3G 0 rom
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 200M 0 part /boot
├─sda2 8:2 0 1G 0 part [SWAP]
└─sda3 8:3 0 18.8G 0 part /
sdb 8:16 0 1G 0 disk
sdc 8:32 0 1G 0 disk
sdd 8:48 0 1G 0 disk
sde 8:64 0 1G 0 disk
[root@www ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created
[root@www ~]#
[root@www ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb lvm2 ---- 1.00g 1.00g
/dev/sdc lvm2 ---- 1.00g 1.00g
/dev/sdd lvm2 ---- 1.00g 1.00g
為什麼會報如上的錯誤呢,我現在還沒有搞清楚.
[root@www ~]# vgcreate storage /dev/sdb /dev/sdc /dev/sdd
Volume group "storage" successfully created
[root@www ~]# vgs
VG #PV #LV #SN Attr VSize VFree
storage 3 0 0 wz--n- 2.99g 2.99g
[root@www ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb storage lvm2 a--u 1020.00m 1020.00m
/dev/sdc storage lvm2 a--u 1020.00m 1020.00m
/dev/sdd storage lvm2 a--u 1020.00m 1020.00m

4 創建一個150M大小的邏輯卷

[root@www ~]# lvcreate -n vo -L 150M storage
Rounding up size to full physical extent 152.00 MiB
Logical volume "vo" created.
[root@www ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
vo storage -wi-a----- 152.00m

5 把生成號的邏輯卷進行格式化,然後掛載使用.

[root@www ~]# mkfs.xfs /dev/storage/vo
meta-data=/dev/storage/vo isize=256 agcount=4, agsize=9728 blks
= sectsz=512 attr=2, projid32bit=0
data = bsize=4096 blocks=38912, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0
log =internal log bsize=4096 blocks=1200, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@www ~]# mount /dev/storage/vo /soft/
[root@www ~]# ls /soft/
[root@www ~]#
永久掛載,重啟後生效,這裡可以使用/dev/storage/vo也可以使用uuid推薦使用後者.
UUID="645e5ca4-d564-425b-ad50-a9d43536951f" /soft xfs defaults 0 0
可以使用umount /soft卸載,再使用mount -a檢查一下有沒有掛載成功.使用df -h查看分區情況
[root@www ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 19G 1.7G 16G 10% /
tmpfs 490M 0 490M 0% /dev/shm
/dev/sda1 190M 59M 122M 33% /boot
/dev/mapper/storage-vo
148M 7.8M 140M 6% /soft
擴容邏輯卷
這裡使用lvextend -l 50指定200M大小的邏輯卷,計算方法為4M*50.
[root@www ~]# lvextend -l 50 /dev/storage/vo
Size of logical volume storage/vo changed from 152.00 MiB (38 extents) to 200.00 MiB (50 extents).
Logical volume vo successfully resized.
[root@www ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
vo storage -wi-a----- 200.00m
新硬碟加入vg卷組
[root@www ~]# pvcreate /dev/sde
Physical volume "/dev/sde" successfully created
[root@www ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb storage lvm2 a--u 1020.00m 820.00m
/dev/sdc storage lvm2 a--u 1020.00m 1020.00m
/dev/sdd storage lvm2 a--u 1020.00m 1020.00m
/dev/sde lvm2 ---- 1.00g 1.00g
[root@www ~]# vgextend storage /dev/sde
Volume group "storage" successfully extended
[root@www ~]# vgs
VG #PV #LV #SN Attr VSize VFree
storage 4 1 0 wz--n- 3.98g 3.79g
[root@www ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb storage lvm2 a--u 1020.00m 820.00m
/dev/sdc storage lvm2 a--u 1020.00m 1020.00m
/dev/sdd storage lvm2 a--u 1020.00m 1020.00m
/dev/sde storage lvm2 a--u 1020.00m 1020.00m
從vg卷組移除一塊硬碟
[root@www ~]# vgreduce storage /dev/sde
Removed "/dev/sde" from volume group "storage"
[root@www ~]# vgs
VG #PV #LV #SN Attr VSize VFree
storage 3 1 0 wz--n- 2.99g 2.79g
[root@www ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb storage lvm2 a--u 1020.00m 820.00m
/dev/sdc storage lvm2 a--u 1020.00m 1020.00m
/dev/sdd storage lvm2 a--u 1020.00m 1020.00m
/dev/sde lvm2 ---- 1.00g 1.00g
邏輯卷裁剪大小為120M
[root@www ~]# lvreduce -L 120M /dev/storage/vo
WARNING: Reducing active logical volume to 120.00 MiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce storage/vo? [y/n]: y
Size of logical volume storage/vo changed from 200.00 MiB (50 extents) to 120.00 MiB (30 extents).
Logical volume vo successfully resized.
[root@www ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
vo storage -wi-a----- 120.00m
[root@www ~]#
刪除邏輯卷,依次刪除lv邏輯卷,gv卷組,pv物理卷
[root@www ~]# lvremove /dev/storage/vo
Do you really want to remove active logical volume vo? [y/n]: y
Logical volume "vo" successfully removed
[root@www ~]# lvs
[root@www ~]# vgremove storage
Volume group "storage" successfully removed
[root@www ~]# vgs
[root@www ~]# pvremove /dev/sde
Labels on physical volume "/dev/sde" successfully wiped
[root@www ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb lvm2 ---- 1.00g 1.00g
/dev/sdc lvm2 ---- 1.00g 1.00g
/dev/sdd lvm2 ---- 1.00g 1.00g
[root@www ~]# pvremove /dev/sdd /dev/sdc /dev/sdb
Labels on physical volume "/dev/sdd" successfully wiped
Labels on physical volume "/dev/sdc" successfully wiped
Labels on physical volume "/dev/sdb" successfully wiped
[root@www ~]# pvs

數據遷移,首先創建一些文件touch /soft/{00..100}.txt,然後進行數據遷移.
[root@www ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb oradata lvm2 a--u 1020.00m 140.00m
/dev/sdc oradata lvm2 a--u 1020.00m 1020.00m
/dev/sdd oradata lvm2 a--u 1020.00m 1020.00m
/dev/sde oradata lvm2 a--u 1020.00m 1020.00m
[root@www ~]# pvmove /dev/sdb /dev/sdd
/dev/sdb: Moved: 0.9%
/dev/sdb: Moved: 36.4%
/dev/sdb: Moved: 54.5%
/dev/sdb: Moved: 100.0%
[root@www ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb oradata lvm2 a--u 1020.00m 1020.00m
/dev/sdc oradata lvm2 a--u 1020.00m 1020.00m
/dev/sdd oradata lvm2 a--u 1020.00m 140.00m
/dev/sde oradata lvm2 a--u 1020.00m 1020.00m
[root@www ~]#
遷移後查看文件並沒有丟失,最後刪除這些文件.
[root@www ~]# ls /soft/
000.txt 010.txt 020.txt 030.txt 040.txt 050.txt 060.txt 070.txt 080.txt 090.txt 100.txt
001.txt 011.txt 021.txt 031.txt 041.txt 051.txt 061.txt 071.txt 081.txt 091.txt
002.txt 012.txt 022.txt 032.txt 042.txt 052.txt 062.txt 072.txt 082.txt 092.txt
003.txt 013.txt 023.txt 033.txt 043.txt 053.txt 063.txt 073.txt 083.txt 093.txt
004.txt 014.txt 024.txt 034.txt 044.txt 054.txt 064.txt 074.txt 084.txt 094.txt
005.txt 015.txt 025.txt 035.txt 045.txt 055.txt 065.txt 075.txt 085.txt 095.txt
006.txt 016.txt 026.txt 036.txt 046.txt 056.txt 066.txt 076.txt 086.txt 096.txt
007.txt 017.txt 027.txt 037.txt 047.txt 057.txt 067.txt 077.txt 087.txt 097.txt
008.txt 018.txt 028.txt 038.txt 048.txt 058.txt 068.txt 078.txt 088.txt 098.txt
009.txt 019.txt 029.txt 039.txt 049.txt 059.txt 069.txt 079.txt 089.txt 099.txt
[root@www ~]# find /soft/ -type f -size 0 -delete

喜歡這篇文章嗎?立刻分享出去讓更多人知道吧!

本站內容充實豐富,博大精深,小編精選每日熱門資訊,隨時更新,點擊「搶先收到最新資訊」瀏覽吧!


請您繼續閱讀更多來自 程序員小新人學習 的精彩文章:

IMUL、MUL和div的用法
Node.js中的URL處理方法

TAG:程序員小新人學習 |