LVM:
1.创建pv(物理卷)
[root@localhost dev]# pvcreate /dev/sdd /dev/sde /dev/sdf
Writing physical volume data todisk "/dev/sdd"
Physical volume"/dev/sdd" successfully created
Writing physical volume data todisk "/dev/sde"
Physical volume"/dev/sde" successfully created
Writing physical volume data todisk "/dev/sdf"
Physical volume"/dev/sdf" successfully created
查看物理卷:
[root@localhost dev]# pvdisplay -v /dev/sdd
Using physical volume(s) oncommand line
--- Physical volume ---
PV Name /dev/sdd
VG Name vg01
PV Size 8.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2047
Free PE 2047
Allocated PE 0
PV UUID lTSpmW-BmZj-vuXj-Ouxx-v6H9-bV3k-f5xaZg
2.创建一个VG
VG名字为“vg01”,设备位置放在“/dev/vg01”,其中包含“/dev/sdd /dev/sde /dev/sdf”三个PV
[root@localhost dev]# vgcreate /dev/vg01 /dev/sdd /dev/sde /dev/sdf
Volume group "vg01"successfully created
查看VG:
[root@localhost dev]# vgdisplay -v vg01
Using volume group(s) on commandline
Finding volume group"vg01"
--- Volume group ---
VG Name vg01
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 23.99 GiB
PE Size 4.00 MiB
Total PE 6141
Alloc PE / Size 0 / 0
Free PE / Size 6141 / 23.99 GiB
VG UUID HvmwcQ-yUmr-71HP-RSaS-kQLs-T1gg-KTlGzb
--- Physical volumes ---
PV Name /dev/sdd
PV UUID lTSpmW-BmZj-vuXj-Ouxx-v6H9-bV3k-f5xaZg
PV Status allocatable
Total PE / Free PE 2047 / 2047
PV Name /dev/sde
PV UUID y69gjf-x4oe-2hpt-iHR2-rt4Z-IpV4-AQvlhd
PV Status allocatable
Total PE / Free PE 2047 / 2047
PV Name /dev/sdf
PV UUID shvndV-Xo73-4BcO-ogDE-bMFm-YS0Y-P339Lq
PV Status allocatable
Total PE / Free PE 2047 / 2047
3.创建LV
[root@localhost dev]# lvcreate -L 2G -n test_lv001 vg01
Logical volume"test_lv001" created
[root@localhost dev]# lvcreate -L 2G -n test_lv002 vg01
Logical volume"test_lv002" created
[root@localhost dev]# lvcreate -L 3G -n test_lv003 vg01
Logical volume"test_lv003" created
查看LV设备所在位置:
[root@localhost dev]# lvdisplay
--- Logical volume ---
LV Path /dev/vg01/test_lv001
LV Name test_lv001
VG Name vg01
LV UUID 6Vw4p8-0EeJ-PcWC-lHMg-hRYp-X2xI-PCTJM2
LV Write Access read/write
LV Creation host, timelocalhost.localdomain, 2013-03-22 13:02:22 +0800
LV Status available
# open 0
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
[root@localhost /]# ls -l /dev/vg01/
总用量 0
lrwxrwxrwx. 1 root root 7 3月 22 13:02test_lv001 -> ../dm-2
lrwxrwxrwx. 1 root root 7 3月 22 13:02test_lv002 -> ../dm-3
lrwxrwxrwx. 1 root root 7 3月 22 13:02test_lv003 -> ../dm-4
4.格式化LV
[root@localhost ~]# mkfs.ext3 /dev/vg01/test_lv001
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376,294912
正在写入inode表: 完成
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
依次格式化test_lv002、test_lv003
5.创建挂载目录,并挂载LV
[root@localhost /]# mkdir test001
[root@localhost /]# mkdir test002
[root@localhost /]# mkdir test003
[root@localhost /]# ls
bin etc lost+found mnt proc selinux test001 tmp
boot home media net root srv test002 usr
dev lib misc opt sbin sys test003 var
[root@localhost /]# df
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/mapper/VolGroup-lv_root
22230908 3594416 17507228 18% /
tmpfs 514488 420 514068 1% /dev/shm
/dev/sda1 495844 31565 438679 7% /boot
[root@localhost /]# mount /dev/vg01/test_lv001 /test001
[root@localhost /]# mount /dev/vg01/test_lv002 /test002
[root@localhost /]# mount /dev/vg01/test_lv003 /test003
[root@localhost /]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/VolGroup-lv_root
22G 3.5G 17G 18% /
tmpfs 503M 420K 503M 1% /dev/shm
/dev/sda1 485M 31M 429M 7% /boot
/dev/mapper/vg01-test_lv001
2.0G 68M 1.9G 4% /test001
/dev/mapper/vg01-test_lv002
2.0G 68M 1.9G 4% /test002
/dev/mapper/vg01-test_lv003
3.0G 69M 2.8G 3% /test003
[root@localhost test001]# vi /etc/fstab
在线扩容:
vg中有剩余空间,可直接拓展,如果无剩余空间,需添加新的PV到vg01中。
此处将sdc作为一个PV后,拓展到vg01。
创建PV
[root@localhost test001]# pvcreate /dev/sdc
Writing physical volume data todisk "/dev/sdc"
Physical volume"/dev/sdc" successfully created
添加PV到vg01中:
[root@localhost test001]# vgextend vg01 /dev/sdc
Volume group "vg01"successfully extended
查看vg01详细信息:
[root@localhost test001]# vgdisplay -v vg01
Using volume group(s) on commandline
Finding volume group"vg01"
--- Volume group ---
VG Name vg01
System ID
Format lvm2
Metadata Areas 4
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 4
Act PV 4
VG Size 31.98 GiB
PE Size 4.00 MiB
Total PE 8188
Alloc PE / Size 1792 / 7.00 GiB
Free PE / Size 6396 / 24.98 GiB
VG UUID HvmwcQ-yUmr-71HP-RSaS-kQLs-T1gg-KTlGzb
--- Logical volume ---
LV Path /dev/vg01/test_lv001
LV Name test_lv001
VG Name vg01
LV UUID 6Vw4p8-0EeJ-PcWC-lHMg-hRYp-X2xI-PCTJM2
LV Write Access read/write
LV Creation host, timelocalhost.localdomain, 2013-03-22 13:02:22 +0800
LV Status available
# open 1
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
--- Logical volume ---
LV Path /dev/vg01/test_lv002
LV Name test_lv002
VG Name vg01
LV UUID a7Xqm1-FLMp-RW5u-xjTr-4q3D-tjuk-P8g776
LV Write Access read/write
LV Creation host, timelocalhost.localdomain, 2013-03-22 13:02:36 +0800
LV Status available
# open 1
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:3
--- Logical volume ---
LV Path /dev/vg01/test_lv003
LV Name test_lv003
VG Name vg01
LV UUID Uh6tFl-dXzA-kSaf-IHAE-OXNA-bxNj-1FYZhZ
LV Write Access read/write
LV Creation host, timelocalhost.localdomain, 2013-03-22 13:02:48 +0800
LV Status available
# open 1
LV Size 3.00 GiB
Current LE 768
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:4
--- Physical volumes ---
PV Name /dev/sdd
PV UUID lTSpmW-BmZj-vuXj-Ouxx-v6H9-bV3k-f5xaZg
PV Status allocatable
Total PE / Free PE 2047 / 255
PV Name /dev/sde
PV UUID y69gjf-x4oe-2hpt-iHR2-rt4Z-IpV4-AQvlhd
PV Status allocatable
Total PE / Free PE 2047 / 2047
PV Name /dev/sdf
PV UUID shvndV-Xo73-4BcO-ogDE-bMFm-YS0Y-P339Lq
PV Status allocatable
Total PE / Free PE 2047 / 2047
PV Name /dev/sdc
PV UUID PLdMOW-9lm3-9Lph-eJ3H-h3Rb-cd3q-x888gY
PV Status allocatable
Total PE / Free PE 2047 / 2047
给test_lv001增加2G空间
[root@localhost /]# lvresize -L +2G /dev/vg01/test_lv001
Extending logical volumetest_lv001 to 4.00 GiB
Logical volume test_lv001successfully resized
[root@localhost /]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/VolGroup-lv_root
22G 3.5G 17G 18% /
tmpfs 503M 420K 503M 1% /dev/shm
/dev/sda1 485M 31M 429M 7% /boot
/dev/mapper/vg01-test_lv002
2.0G 68M 1.9G 4% /test002
/dev/mapper/vg01-test_lv003
3.0G 69M 2.8G 3% /test003
/dev/mapper/vg01-test_lv001
2.0G 68M 1.9G 4% /test001
使用resize2fs命令,令新增空间在线生效
[root@localhost /]# resize2fs /dev/vg01/test_lv001
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg01/test_lv001 is mounted on /test001; on-lineresizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/vg01/test_lv001 to 1048576 (4k)blocks.
The filesystem on /dev/vg01/test_lv001 is now 1048576 blocks long.
[root@localhost /]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/VolGroup-lv_root
22G 3.5G 17G 18% /
tmpfs 503M 420K 503M 1% /dev/shm
/dev/sda1 485M 31M 429M 7% /boot
/dev/mapper/vg01-test_lv002
2.0G 68M 1.9G 4% /test002
/dev/mapper/vg01-test_lv003
3.0G 69M 2.8G 3% /test003
/dev/mapper/vg01-test_lv001
4.0G 69M 3.7G 2% /test001
[root@localhost /]# lvdisplay -v /dev/vg01/test_lv001
Using logical volume(s) oncommand line
--- Logical volume ---
LV Path /dev/vg01/test_lv001
LV Name test_lv001
VG Name vg01
LV UUID 6Vw4p8-0EeJ-PcWC-lHMg-hRYp-X2xI-PCTJM2
LV Write Access read/write
LV Creation host, timelocalhost.localdomain, 2013-03-22 13:02:22 +0800
LV Status available
# open 1
LV Size 4.00 GiB
Current LE 1024
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2