建立LVM是從物理分區-物理卷-卷組-邏輯卷-掛載到目錄這個順序來的
物理卷(physical volumes-PV)。
卷組(volume groups-VG)。
邏輯卷(logical volumes-LV),
第一步、建立物理分區,改變分區ID位8e
#fdisk /dev/sda
而後分一個分區,你想多大就多大,改變分區ID位8e。 而後保存退出
# fdisk /dev/sda
Command (m for help): n
First cylinder (2789-3916, default 2789):
Using default value 2789
Last cylinder or +size or +sizeM or +sizeK (2789-3916, default 3916): +500M
Command (m for help): p
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
......
/dev/sda9 2789 2850 497983+ 83 Linux
Command (m for help): t
Partition number (1-9): 9
Hex code (type L to list codes): 8e
Changed system type of partition 9 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
.....
/dev/sda9 2789 2850 497983+ 8e Linux LVM
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.
Syncing disks.
使用partprobe 使分區立刻生效
#partprobe
2.建立LVM物理卷
#pvcreate /dev/sda3
(先要umount)
3.查看LVM物理卷
#pvcreate
4.建立LVM組卷,將物理卷加入組
#vgedtend G1 /dev/sda9 ( /dev/sda8將sda8也加入該組)
5.查看LVM組卷
#vgscan(搜索卷組)
#vgdisplay G1
6.建立邏輯卷
#lvcreate -L 100M G1 -n L1
7.格式化邏輯卷
#mkfs.ext3 /dev/G1/L1
8.掛載邏輯卷
#mkdir /mnt/G1L1
#mount /dev/G1/L1 /mnt/G1L1
9.查看邏輯卷
#lvdisplay
10.增長邏輯卷大小
#lvresize -L 100M(絕對大小) /dev/G1/L1
或者
#lvlextend -L +100M(至關大小) /dev/G1/L1
11.用resize2fs 加入到卷組中的卷標
#resize2fs /dev/G1/L1
(這裏要說一下,若是要運行resize2fs,先要卸下這個卷,例如:LogVol01是掛在
了/myfile這個文件夾下,要用「umount /myfile」把它卸下來,再運行resize2fs,否則會
提示「can't resize a mounted filesystem」(沒法對已掛載的文件系統重設大小))
12.縮小邏輯卷
#lvreduce -L -50M /dev/G1/L1
#resize2fs /dev/G1/L1 -f(強制)
對於lvm,若是是擴大某個lv,操做比較簡單,但若是是縮小lv,則有必定的風險。咱們先
要縮小/dev/G1/L1文件系統,而後才能縮小lvm