3.2 建立一個VG
# vgcreate -s 16M [VG名稱] [PV名稱]
[root@localhost ~]# vgcreate -s 16M faqvg /dev/sda{5,6,7}
#參數-s後面接的是PE的大小,單位可為m,g,t
/dev/cdrom: open failed: Read-only file system
/dev/cdrom: open failed: Read-only file system
/dev/cdrom: open failed: Read-only file system
/dev/cdrom: open failed: Read-only file system
Volume group "faqvg" successfully created
3.3 查看建立的VG是否有問題
[root@localhost ~]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "faqvg" using metadata type lvm2
#確實有建立成功
[root@localhost ~]# pvscan
PV /dev/sda5 VG faqvg lvm2 [1.86 GB / 1.86 GB free]
PV /dev/sda6 VG faqvg lvm2 [1.86 GB / 1.86 GB free]
PV /dev/sda7 VG faqvg lvm2 [1.86 GB / 1.86 GB free]
PV /dev/sda8 lvm2 [1.87 GB]
Total: 4 [7.45 GB] / in use: 3 [5.58 GB] / in no VG: 1 [1.87 GB]
#查詢是否已用掉/dev/sda5,6,7
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name faqvg
System ID
Format lvm2
Metadata Areas 3
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 3
Act PV 3
VG Size 5.58 GB #整個VG容量大小
PE Size 16.00 MB #內部每個PE的大小
Total PE 357 #總共PE數
Alloc PE / Size 0 / 0
Free PE / Size 357 / 5.58 GB
VG UUID e2lS1t-7Rop-YHU4-qygQ-tDFq-LjVn-jOnv0h
3.4新增VG的大小。(把剩下的/dev/sda8加進去)
[root@localhost ~]# vgextend faqvg /dev/sda8
/dev/cdrom: open failed: Read-only file system
/dev/cdrom: open failed: Read-only file system
Volume group "faqvg" successfully extended
#增加後再檢查一下VG容量大小是不是有改變
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Size 7.44 GB
PE Size 16.00 MB
Total PE 476
Alloc PE / Size 0 / 0
Free PE / Size 476 / 7.44 GB
VG UUID e2lS1t-7Rop-YHU4-qygQ-tDFq-LjVn-jOnv0h
4.2 建立一個LV
建立的方式有兩種請選一種建立即可
#方法一 :
[root@localhost ~]# lvcreate -l 476 -n faqlv faqvg
Logical volume "faqlv" created
#方法二 :
[root@localhost ~]# lvcreate -L 7.44G -n faqlv faqvg
Logical volume "faqlv" created
參數說明:
-L 後面接容量大小,單位可為M,G,T。最小單位為PE此數量必須為PE的倍數,要不系統會以
最相近的容量為主。
-l 後面接的為PE的個數,可參考vgdisplay所顯示出的PE數。
-n 後面接的為LV的名稱
4.3 查看建立的LV是否有問題
#查看是否有建立成功
[root@localhost ~]# ll /dev/faqvg/faqlv
lrwxrwxrwx 1 root root 23 Nov 1 17:30 /dev/faqvg/faqlv -> /dev/mapper/faqvg-faqlv
#查看系統上的LV狀態
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Name /dev/faqvg/faqlv #LV的全名
VG Name faqvg
LV UUID QMOpsQ-3k87-BHSx-7crB-Wrlh-Zx11-Hn332K
LV Write Access read/write
LV Status available
# open 0
LV Size 7.44 GB #LV的容量大小
Current LE 476
Segments 4
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
掛載使用LV
[root@localhost ~]# mkfs -t ext3 /dev/faqvg/faqlv #格式化
[root@localhost ~]# mkdir /mnt/lvm #建立要mount的資料夾
[root@localhost ~]# mount /dev/faqvg/faqlv /mnt/lvm/ #掛載
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 4.9G 1.2G 3.5G 25% /
/dev/sda1 99M 12M 83M 13% /boot
tmpfs 506M 0 506M 0% /dev/shm
/dev/mapper/faqvg-faqlv
7.4G 145M 6.9G 3% /mnt/lvm #多出此行就表示掛載成功
設定到這邊LVM的基本設定已經完成了,將LV掛載上後就可以開始使用了。
LVM 設定說明(上)
全文同步於FAQ-BOOK
IT鐵人文章分享