lvm的一些操作
首先就是创建PV了,有了PV才能组建VG嘛。创建PV用 pvcreate 命令。
# pvcreate /dev/hda6
Physical volume "/dev/hda6">
# pvdisplay
PV Name               /dev/hda6
VG Name
PV Size               9.77 GB
Allocatable           NO
PE Size (KByte)       0
Total PE              0
Free PE               0
Allocated PE          0
PV UUID               jGIjyo-lukG-LdRg-tmwe-Mgxf-09ZW-loquUZ
这样可以看到,创建了一个PV。同样操作可以创建多个。下面创建VG。 # vgcreate wd /dev/hda6
Volume group "wd">
# vgdisplay
VG Name               wd
System ID
Format                lvm2
Metadata Areas        1
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                1
Act PV                1
VG Size               9.77 GB
PE Size               4.00 MB
Total PE              2500
Alloc PE / Size       0 / 0
Free  PE / Size       2500 / 9.77 GB
VG UUID               NwUlxW-AmAi-LyqA-h39E-zS7q-YRj3-scZucL
再看刚才创建的pv。 # pvdisplay
PV Name               /dev/hda6
VG Name               wd
PV Size               9.77 GB / not usable 0
Allocatable           yes
PE Size (KByte)       4096
Total PE              2500
Free PE               2500
Allocated PE          0
PV UUID               jGIjyo-lukG-LdRg-tmwe-Mgxf-09ZW-loquUZ
可以看到多了一些信息,他已经属于叫做wd的VG了。同时可以看到PE的大小是4096K,也就是4M。下面创建真正可用的LV。 # lvcreate -L 200M -n test wd
Logical volume "test">
# lvdisplay
LV Name                /dev/wd/test
VG Name                wd
LV UUID                sPy1bM-Nz13-v0x7-bk0V-BKSH-Udzl-7ov5jM
LV Write Access        read/write
LV Status              available
# open                 0
LV Size                200.00 MB
Current LE             50
Segments               1
Allocation             inherit
Read ahead sectors     0
Block device           253:0
可以看到,已经创建了一个叫做test的LV,也可以不使用-n参数指定LV的名称,这样系统会给取一个名字。 再来看看VG和PV的信息。 # vgdisplay
VG Name               wd
System ID
Format                lvm2
Metadata Areas        1
Metadata Sequence No  4
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                1
Open LV               0
Max PV                0
Cur PV                1
Act PV                1
VG Size               9.77 GB
PE Size               4.00 MB
Total PE              2500
Alloc PE / Size       50 / 200.00 MB
Free  PE / Size       2450 / 9.57 GB
VG UUID               NwUlxW-AmAi-LyqA-h39E-zS7q-YRj3-scZucL
# pvdisplay
PV Name               /dev/hda6
VG Name               wd
PV Size               9.77 GB / not usable 0
Allocatable           yes
PE Size (KByte)       4096
Total PE              2500
Free PE               2450
Allocated PE          50
PV UUID               jGIjyo-lukG-LdRg-tmwe-Mgxf-09ZW-loquUZ
可以看到VG已经使用了50个PE,也就是200M空间。PV上面也是,使用了50个PE。 这样LV已经有了,怎么使用他呢?其实和普通分区的使用方法一样。先格式化,创建文件系统,然后挂载。 # mkfs.ext3 /dev/wd/test
max_blocks 209715200, rsv_groups = 25600, rsv_gdb = 256
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
51200 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
25 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729

Writing inode tables: done
inode.i_blocks = 3074, i_size = 67383296
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
# mount /dev/wd/test /opt ]# df -h
/dev/hda9             4.0G  148M  3.6G   4% /
/dev/hda1              99M  8.3M   86M   9% /boot
/dev/hda3              29G  1.1G   27G   4% /data
none                  252M     0  252M   0% /dev/shm
/dev/hda7             9.7G   55M  9.1G   1% /home
/dev/hda10            3.9G   40M  3.7G   2% /tmp
/dev/hda5             9.7G  1.9G  7.4G  20% /usr
/dev/hda8             7.7G   90M  7.3G   2% /var
/dev/mapper/wd-test   194M  5.6M  179M   4% /opt
最后这行就是挂载的LV。下面调整LV的大小。先umount挂载的LV。 # umount /opt # lvresize -L +100M /dev/wd/test
Logical volume test successfully resized
# lvdisplay
LV Name                /dev/wd/test
VG Name                wd
LV UUID                sPy1bM-Nz13-v0x7-bk0V-BKSH-Udzl-7ov5jM
LV Write Access        read/write
LV Status              available
# open                 0
LV Size                300.00 MB
Current LE             75
Segments               1
Allocation             inherit
Read ahead sectors     0
Block device           253:0
然后需要使用resize2fs命令调整LV分区大小。我这里用的是rh el4,没有这个命令。rh el3里面有这个命令。el4里面用ext2online命令调整,用ext2online命令调整的话,需要把要调整的分区挂载上去。 # mount /dev/wd/test /opt # ext2online /dev/wd/test
# df -h
/dev/hda9             4.0G  148M  3.6G   4% /
/dev/hda1              99M  8.3M   86M   9% /boot
/dev/hda3              29G  1.1G   27G   4% /data
none                  252M     0  252M   0% /dev/shm
/dev/hda7             9.7G   55M  9.1G   1% /home
/dev/hda10            3.9G   40M  3.7G   2% /tmp
/dev/hda5             9.7G  1.9G  7.4G  20% /usr
/dev/hda8             7.7G   90M  7.3G   2% /var
/dev/mapper/wd-test   291M  6.1M  270M   3% /opt
lvm的恢复 姑且就叫做恢复吧,因为我其实没有实际测试过。不过是假设我的这台电脑启动不了了,然后用knoppix尝试恢复其中的数据。 # lvmdiskscan
/dev/wd/test [      332.00 MB]
/dev/ram1    [       97.66 MB]
/dev/hda1    [      101.94 MB]
/dev/ram2    [       97.66 MB]
/dev/hda2    [        1.95 GB]
/dev/ram3    [       97.66 MB]
/dev/hda3    [       29.29 GB]
/dev/ram4    [       97.66 MB]
/dev/ram5    [       97.66 MB]
/dev/hda5    [        9.77 GB]
/dev/ram6    [       97.66 MB]
/dev/hda6    [        9.77 GB] LVM physical volume
/dev/ram7    [       97.66 MB]
/dev/hda7    [        9.77 GB]
/dev/ram8    [       97.66 MB]
/dev/hda8    [        7.81 GB]
/dev/ram9    [       97.66 MB]
/dev/hda9    [        3.97 GB]
/dev/ram10   [       97.66 MB]
/dev/hda10   [        3.91 GB]
/dev/ram11   [       97.66 MB]
/dev/ram12   [       97.66 MB]
/dev/ram13   [       97.66 MB]
/dev/ram14   [       97.66 MB]
/dev/ram15   [       97.66 MB]
1 disk
24 partitions
0 LVM physical volume whole disks
1 LVM physical volume
# vgdisplay -v
Finding volume group "wd"
--- Volume group ---
VG Name               wd
System ID
Format                lvm2
Metadata Areas        1
Metadata Sequence No  9
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                1
Open LV               0
Max PV                0
Cur PV                1
Act PV                1
VG Size               9.77 GB
PE Size               4.00 MB
Total PE              2500
Alloc PE / Size       83 / 332.00 MB
Free  PE / Size       2417 / 9.44 GB
VG UUID               NwUlxW-AmAi-LyqA-h39E-zS7q-YRj3-scZucL

--- Logical volume ---
LV Name                /dev/wd/test
VG Name                wd
LV UUID                sPy1bM-Nz13-v0x7-bk0V-BKSH-Udzl-7ov5jM
LV Write Access        read/write
LV Status              available
# open                 0
LV Size                332.00 MB
Current LE             83
Segments               1
Allocation             inherit
Read ahead sectors     0
Block device           254:0

--- Physical volumes ---
PV Name               /dev/hda6
PV UUID               jGIjyo-lukG-LdRg-tmwe-Mgxf-09ZW-loquUZ
PV Status             allocatable
Total PE / Free PE    2500 / 2417
# vgchange -a y wd
1 logical volume(s) in volume group "wd">

这样之后就可以使用mount命令挂载/dev/wd下面的设备了。

lvm的配置在 /etc/lvm/backup 下面。
参考自 这里