環境準備:
1.新增一個硬碟:(利用VMware測試,使用100M)
*不重開機掃描硬碟方式:
#tail /vat/log/message //確定沒抓到
#echo "- - -" > /sys/class/scsi-host/host0/scan //重新掃描scsi硬碟
#tail /var/log/message //應該就可看到
2.我的裝置為/dev/sdb
#fdisk /dev/sdb //建立分割區,並設定id為"8e"
*不重開機掃描硬碟方式:
#tail /vat/log/message //確定沒抓到
#echo "- - -" > /sys/class/scsi-host/host0/scan //重新掃描scsi硬碟
#tail /var/log/message //應該就可看到
2.我的裝置為/dev/sdb
#fdisk /dev/sdb //建立分割區,並設定id為"8e"
LVM相關指令:
PV | VG | LV | |
掃描 | pvscan | vgscan | lvscan |
檢視 | pvdisplay | vgdisplay | lvdisplay |
新增 | pvcreate | vgcreate | lvcreate |
移除 | pvremove | vgremove | lvremove |
放大 | none | vgextend | lvextend |
縮小 | none | vgreduce | lvreduce |
設定:
1.新增一個PV
# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
# pvscan //掃描PV
PV /dev/sdb1 lvm2 [101.98 MB]
Total: 1 [101.98 MB] / in use: 0 [0 ] / in no VG: 1 [101.98 MB]
// PV:/dev/sdb1 格式:lvm2
//PV大小[101.98MB] / 配置給VG的大小 / 沒有配置給VG剩餘大小
2.新增VG //至少一個PV
# vgcreate mainVG /dev/sdb1
Volume group "mainVG" successfully created
//指令格式:vgcreate VGname pv
# vgscan
Reading all physical volumes. This may take a while...
Found volume group "mainVG" using metadata type lvm2
# pvscan
PV /dev/sdb1 VG mainVG lvm2 [100.00 MB / 100.00 MB free]
Total: 1 [100.00 MB] / in use: 1 [100.00 MB] / in no VG: 0 [0 ]
//可以看到pv已經in use
*可以用display看到更詳細的內容
3.建立LV: //建立完成後會產生目錄/dev/mainVG,LV會放在裡面
# ls /dev/mainVG //應該找不到
# lvcreate -L 50M -n LV01 mainVG
Rounding up size to full physical extent 52.00 MB
Logical volume "LV01" created
//指令格式:lvcreate -L size -n lvname VGname
# lvscan
ACTIVE '/dev/mainVG/LV01' [52.00 MB] inherit
4.mount LV
#mkfs.ext3 /dev/mainVG/LV01 //格式化LV
#mkdir /dir1
#mount /dev/mainVG/LV01 /dir1
//利用dd快速建立大檔,待會要練習放大縮小
#dd if=/dev/zero of=/dir1/test bs=1M count=10 //size:1M 做10次即為10M檔案
# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
# pvscan //掃描PV
PV /dev/sdb1 lvm2 [101.98 MB]
Total: 1 [101.98 MB] / in use: 0 [0 ] / in no VG: 1 [101.98 MB]
// PV:/dev/sdb1 格式:lvm2
//PV大小[101.98MB] / 配置給VG的大小 / 沒有配置給VG剩餘大小
2.新增VG //至少一個PV
# vgcreate mainVG /dev/sdb1
Volume group "mainVG" successfully created
//指令格式:vgcreate VGname pv
# vgscan
Reading all physical volumes. This may take a while...
Found volume group "mainVG" using metadata type lvm2
# pvscan
PV /dev/sdb1 VG mainVG lvm2 [100.00 MB / 100.00 MB free]
Total: 1 [100.00 MB] / in use: 1 [100.00 MB] / in no VG: 0 [0 ]
//可以看到pv已經in use
*可以用display看到更詳細的內容
3.建立LV: //建立完成後會產生目錄/dev/mainVG,LV會放在裡面
# ls /dev/mainVG //應該找不到
# lvcreate -L 50M -n LV01 mainVG
Rounding up size to full physical extent 52.00 MB
Logical volume "LV01" created
//指令格式:lvcreate -L size -n lvname VGname
# lvscan
ACTIVE '/dev/mainVG/LV01' [52.00 MB] inherit
4.mount LV
#mkfs.ext3 /dev/mainVG/LV01 //格式化LV
#mkdir /dir1
#mount /dev/mainVG/LV01 /dir1
//利用dd快速建立大檔,待會要練習放大縮小
#dd if=/dev/zero of=/dir1/test bs=1M count=10 //size:1M 做10次即為10M檔案
縮放LVM ##容易造成data lost,請先備份在操作
1.放大 --先放大LV再放大檔案系統
# lvextend -L +30M /dev/mainVG/LV01
Rounding up size to full physical extent 32.00 MB
Extending logical volume LV01 to 84.00 MB
Logical volume LV01 successfully resized
//指令格式:lvextend -L 總大小/增加的大小:80M/+30M LVpath
//雖然成功但實際上還未變大,可用df檢查
# df |grep -B1 dir1
/dev/mapper/mainVG-LV01
51559 15237 33660 32% /dir1
# resize2fs /dev/mainVG/LV01 //放大可不用umount
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/mainVG/LV01 is mounted on /dir1; on-line resizing required
Performing an on-line resize of /dev/mainVG/LV01 to 86016 (1k) blocks.
The filesystem on /dev/mainVG/LV01 is now 86016 blocks long.
[root@a238 dir1]# df |grep -B1 dir1
/dev/mapper/mainVG-LV01
83363 15651 63619 20% /dir1
Rounding up size to full physical extent 32.00 MB
Extending logical volume LV01 to 84.00 MB
Logical volume LV01 successfully resized
//指令格式:lvextend -L 總大小/增加的大小:80M/+30M LVpath
//雖然成功但實際上還未變大,可用df檢查
# df |grep -B1 dir1
/dev/mapper/mainVG-LV01
51559 15237 33660 32% /dir1
# resize2fs /dev/mainVG/LV01 //放大可不用umount
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/mainVG/LV01 is mounted on /dir1; on-line resizing required
Performing an on-line resize of /dev/mainVG/LV01 to 86016 (1k) blocks.
The filesystem on /dev/mainVG/LV01 is now 86016 blocks long.
[root@a238 dir1]# df |grep -B1 dir1
/dev/mapper/mainVG-LV01
83363 15651 63619 20% /dir1
2.縮小 --先縮小檔案系統再縮小LV
1.再增加一個disk:/dev/sdc,同上處理分割區
2.加入VG
2.加入VG
# pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created
# vgextend mainVG /dev/sdc1
Volume group "mainVG" successfully extended
# pvscan //可以看出第二顆pv已正確加入mainVG
PV /dev/sdb1 VG mainVG lvm2 [100.00 MB / 16.00 MB free]
PV /dev/sdc1 VG mainVG lvm2 [100.00 MB / 100.00 MB free]
Total: 2 [200.00 MB] / in use: 2 [200.00 MB] / in no VG: 0 [0 ]
# vgdisplay
--- Volume group ---
VG Name mainVG
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 200.00 MB
PE Size 4.00 MB
Total PE 50
Alloc PE / Size 21 / 84.00 MB
Free PE / Size 29 / 116.00 MB
VG UUID XK0Mvy-5b4U-pcBB-061Z-0dUJ-SBFR-Ro2yBf
Physical volume "/dev/sdc1" successfully created
# vgextend mainVG /dev/sdc1
Volume group "mainVG" successfully extended
# pvscan //可以看出第二顆pv已正確加入mainVG
PV /dev/sdb1 VG mainVG lvm2 [100.00 MB / 16.00 MB free]
PV /dev/sdc1 VG mainVG lvm2 [100.00 MB / 100.00 MB free]
Total: 2 [200.00 MB] / in use: 2 [200.00 MB] / in no VG: 0 [0 ]
# vgdisplay
--- Volume group ---
VG Name mainVG
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 200.00 MB
PE Size 4.00 MB
Total PE 50
Alloc PE / Size 21 / 84.00 MB
Free PE / Size 29 / 116.00 MB
VG UUID XK0Mvy-5b4U-pcBB-061Z-0dUJ-SBFR-Ro2yBf
沒有留言:
張貼留言