================LVM的配置===============
說明:LVM是logical volume manager 的縮寫,叫邏輯卷管理,是一種用來管理LV的工具。我們所用到的RAID是不提供存儲數據空間的動態增長和收縮的,假如磁盤的空間已經滿了而你又想寫入一些數據那隻能再去手動添加一塊物理硬盤了 ,而LV是一種可以動態增長和收縮的邏輯卷,它是以塊設備作爲基礎的,當然也可以以raid作爲基礎的。LV的構建架構是:PD-->PV-->VG--->LV,PD是最底層的物理設備,PV是物理卷,VG是邏輯卷組,LV就是邏輯卷。PV有一些常用的命令:pvcreate,pvscan,pvdisplay,pvmove,pvremove。VG有一些常用的命令:vgcreate,vgdisplay,vgscan,vgremove。LV有一些常用的命令:lvcreate,lvdisplay,lvextend,lvreduce。
如下是配置LV的步驟(一下所示的參數均爲參考):
1. 首先需要有一個邏輯卷格式(8e)的分區,在這裏我們用的是/dev/sdc7,然後創建PV:
[root@server27 ~]# pvcreate /dev/sdc7 –v
Set up physical volume for "/dev/sdc5" with 1975932 available sectors
Zeroing start of device /dev/sdc5
Physical volume "/dev/sdc5" successfully created
2. 創建VG,,創建的VG名字是Vol1
[root@server27 ~]# vgcreate vol2 /dev/sdc7
/dev/cdrom: open failed: Read-only file system
Attempt to close device '/dev/cdrom' which is not open.
Volume group "vol2" successfully created
3.然後就可以創建LV了:
[root@server27 ~]# lvcreate -L 512M -n LV2 vol2
Logical volume "LV2" created
4.使用命令lvdisplay查看lv的配置:
[root@server27 ~]# lvdisplay /dev/vol2/LV2
--- Logical volume ---
LV Name /dev/vol2/LV2
VG Name vol2
LV UUID 9YfPDN-u8UE-1uaX-Wf8b-R1C8-WPFu-OSfAjR
LV Write Access read/write
LV Status available
# open 0
Current LE 128
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:6
[root@server27 ~]#
5.創建一個掛載點/lvm2
[root@server27 ~]# mkdir /lvm2
6.格式化LV邏輯卷:
[root@server27 ~]# mkfs -t ext3 /dev/vol2/LV2
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
131072 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
64 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@server27 ~]#
7.然後掛載LV2
[root@server27 ~]# mount /dev/vol2/LV2 /lvm2
[root@server27 ~]#
8.切換到/lvm2目錄查看LV2邏輯卷
[root@server27 lvm2]# ls
lost+found
[root@server27 lvm2]#
可以看到邏輯卷創建成功.
9.查看LV2的空間大小
[root@server27 lvm2]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vol0-root
18G 5.1G 12G 32% /
/dev/mapper/vol0-home
465M 11M 431M 3% /home
/dev/sda1 99M 29M 66M 31% /boot
tmpfs 147M 0 147M 0% /dev/shm
/dev/md3 1.9G 35M 1.8G 2% /liu
/dev/mapper/vol1-lv1 146M 18M 122M 13% /lvm1
/dev/mapper/vol1-sanp
146M 18M 122M 13% /snap
/dev/hdc 2.8G 2.8G 0 100% /media/RHEL_5.4 i386 DVD
/dev/mapper/vol2-LV2 496M 19M 452M 4% /lvm2
[root@server27 lvm2]#
由圖可知現在空閒的空間爲452M
10.增加LV2的空間大小
[root@server27 ~]# lvextend -L +100M /dev/vol2/LV2
Extending logical volume LV2 to 612.00 MB
Logical volume LV2 successfully resized
[root@server27 ~]#
顯示成功,但是現在我們去查看它的free空間:
[root@server27 ~]# df –lh
/dev/mapper/vol2-LV2 496M 19M 452M 4% /lvm2
可以看到,依然爲452M
11.這時我們去執行一個命令讓它重新讀取一下:
[root@server27 ~]# resize2fs /dev/vol2/LV2
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/vol2/LV2 is mounted on /lvm2; on-line resizing required
Performing an on-line resize of /dev/vol2/LV2 to 626688 (1k) blocks.
The filesystem on /dev/vol2/LV2 is now 626688 blocks long.
[root@server27 ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vol0-root
18G 5.1G 12G 32% /
/dev/mapper/vol0-home
465M 11M 431M 3% /home
/dev/sda1 99M 29M 66M 31% /boot
tmpfs 147M 0 147M 0% /dev/shm
/dev/md3 1.9G 35M 1.8G 2% /liu
/dev/mapper/vol1-lv1 146M 18M 122M 13% /lvm1
/dev/mapper/vol1-sanp
146M 18M 122M 13% /snap
/dev/hdc 2.8G 2.8G 0 100% /media/RHEL_5.4 i386 DVD
/dev/mapper/vol2-LV2 593M 19M 544M 4% /lvm2
[root@server27 ~]#
這時可以看,它的大小已經變爲544M(可以有一點差錯)
我們再去減少一下它的大小:
1. 卸載分區:
[root@server27 ~]# umount /lvm2
[root@server27 ~]#
2. 檢測LV2:
[root@server27 ~]# e2fsck -f /dev/vol2/LV2
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vol2/LV2: 11/157696 files (9.1% non-contiguous), 38662/626688 blocks
[root@server27 ~]#
3.執行resize2fs命令,指定縮減後的大小:
[root@server27 ~]# resize2fs /dev/vol2/LV2 250M
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/vol2/LV2 to 256000 (1k) blocks.
The filesystem on /dev/vol2/LV2 is now 256000 blocks long.
[root@server27 ~]#
4然後執行命令,縮減LV2:
[root@server27 ~]# resize2fs /dev/vol2/LV2 250M
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/vol2/LV2 to 256000 (1k) blocks.
The filesystem on /dev/vol2/LV2 is now 256000 blocks long.
[root@server27 ~]# lvreduce -L 250M /dev/vol2/LV2
Rounding up size to full physical extent 252.00 MB
WARNING: Reducing active logical volume to 252.00 MB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce LV2? [y/n]: Y
Reducing logical volume LV2 to 252.00 MB
Logical volume LV2 successfully resized
[root@server27 ~]#
5.然後重新掛載查看:
[root@server27 ~]# mount /dev/vol2/LV2 /lvm2
[root@server27 ~]# df -lh
/dev/mapper/vol2-LV2 242M 19M 214M 8% /lvm2
[root@server27 ~]#
可以看到LV2的大小已經變爲214M。
提示:lvextend和lvreduce的步驟剛好相反,一定不要混淆了他們的步驟。