- 论坛徽章:
- 0
|
一个不完整的逻辑卷操作
物理卷->卷组->逻辑卷
1,准备工作,分区,改分区
[root@lab ~]# fdisk -l
Disk /dev/hda: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 395 3068415 83 Linux
/dev/hda3 396 460 522112+ 82 Linux swap / Solaris
/dev/hda4 461 783 2594497+ 5 Extended
[root@lab ~]# fdisk /dev/hda
Command (m for help): n
First cylinder (461-783, default 461):
Using default value 461
Last cylinder or +size or +sizeM or +sizeK (461-783, default 783): +50M
Command (m for help): n
First cylinder (468-783, default 468):
Using default value 468
Last cylinder or +size or +sizeM or +sizeK (468-783, default 783): +50M
Command (m for help): n
First cylinder (475-783, default 475):
Using default value 475
Last cylinder or +size or +sizeM or +sizeK (475-783, default 783): +50M
Command (m for help): p
Disk /dev/hda: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 395 3068415 83 Linux
/dev/hda3 396 460 522112+ 82 Linux swap / Solaris
/dev/hda4 461 783 2594497+ 5 Extended
/dev/hda5 461 467 56196 83 Linux
/dev/hda6 468 474 56196 83 Linux
/dev/hda7 475 481 56196 83 Linux
Command (m for help): t
Partition number (1-7): 5
Hex code (type L to list codes): 8e
Changed system type of partition 5 to 8e (Linux LVM)
Command (m for help): t
Partition number (1-7): 6
Hex code (type L to list codes): 8e
Changed system type of partition 6 to 8e (Linux LVM)
Command (m for help): t
Partition number (1-7): 7
Hex code (type L to list codes): 8e
Changed system type of partition 7 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/hda: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 395 3068415 83 Linux
/dev/hda3 396 460 522112+ 82 Linux swap / Solaris
/dev/hda4 461 783 2594497+ 5 Extended
/dev/hda5 461 467 56196 8e Linux LVM
/dev/hda6 468 474 56196 8e Linux LVM
/dev/hda7 475 481 56196 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.
[root@lab ~]# partprobe
Warning: Unable to open /dev/fd0 read-write (Read-only file system). /dev/fd0 has been opened read-only.
[root@lab ~]#
2,创建物理卷的操作
[root@lab ~]# pvcreate /dev/hda[5-7]
Physical volume "/dev/hda5" successfully created
Physical volume "/dev/hda6" successfully created
Physical volume "/dev/hda7" successfully created
[root@lab ~]# pvdisplay
--- NEW Physical volume ---
PV Name /dev/hda5
VG Name
PV Size 54.88 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 0iXPtr-ZkQp-9PRI-J31I-HL2t-SaBx-Vr2I8H
--- NEW Physical volume ---
PV Name /dev/hda6
VG Name
PV Size 54.88 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 4cjydb-ndfI-R0jh-HF2e-l2vS-hx8r-lGR9di
--- NEW Physical volume ---
PV Name /dev/hda7
VG Name
PV Size 54.88 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 1vhH3I-OwS3-I0IJ-P5Va-alKF-XxCR-EGy22R
[root@lab ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/hda5 lvm2 -- 54.88M 54.88M
/dev/hda6 lvm2 -- 54.88M 54.88M
/dev/hda7 lvm2 -- 54.88M 54.88M
3.将/dev/hda7 移除
[root@lab ~]# pvremove /dev/hda7
Labels on physical volume "/dev/hda7" successfully wiped
[root@lab ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/hda5 lvm2 -- 54.88M 54.88M
/dev/hda6 lvm2 -- 54.88M 54.88M
[root@lab ~]# pvcreate /dev/hda7
Physical volume "/dev/hda7" successfully created
4.改变一个物理卷可用容量的大小,暂时没有发现意义
[root@lab ~]# pvresize --setphysicalvolumesize 20M /dev/hda7
Physical volume "/dev/hda7" changed
1 physical volume(s) resized / 0 physical volume(s) not resized
[root@lab ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/hda5 lvm2 -- 54.88M 54.88M
/dev/hda6 lvm2 -- 54.88M 54.88M
/dev/hda7 lvm2 -- 20.00M 20.00M
[root@lab ~]# pvresize /dev/hda7
Physical volume "/dev/hda7" changed
1 physical volume(s) resized / 0 physical volume(s) not resized
[root@lab ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/hda5 lvm2 -- 54.88M 54.88M
/dev/hda6 lvm2 -- 54.88M 54.88M
/dev/hda7 lvm2 -- 54.88M 54.88M
5.创建卷组
[root@lab ~]# vgcreate vg0 /dev/hda5 /dev/hda6
Volume group "vg0" successfully created
[root@lab ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg0 2 0 0 wz--n- 104.00M 104.00M
[root@lab ~]# vgdisplay
--- Volume group ---
VG Name vg0
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 104.00 MB
PE Size 4.00 MB
Total PE 26
Alloc PE / Size 0 / 0
Free PE / Size 26 / 104.00 MB
VG UUID ulEBV2-l4Af-kOTx-UPSq-vHXa-3dWR-hVFuce
6.扩展卷组
[root@lab ~]# vgextend vg0 /dev/hda7
Volume group "vg0" successfully extended
[root@lab ~]# vgdisplay
--- Volume group ---
VG Name vg0
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 2
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 156.00 MB
PE Size 4.00 MB
Total PE 39
Alloc PE / Size 0 / 0
Free PE / Size 39 / 156.00 MB
VG UUID ulEBV2-l4Af-kOTx-UPSq-vHXa-3dWR-hVFuce
7.去除新加的物理卷/dev/hda7
[root@lab ~]# vgreduce vg0 /dev/hda7
Removed "/dev/hda7" from volume group "vg0"
[root@lab ~]# vgdisplay
--- Volume group ---
VG Name vg0
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 104.00 MB
PE Size 4.00 MB
Total PE 26
Alloc PE / Size 0 / 0
Free PE / Size 26 / 104.00 MB
VG UUID ulEBV2-l4Af-kOTx-UPSq-vHXa-3dWR-hVFuce
8.卷组改名
[root@lab ~]# vgrename vg0 volumegroup0
Volume group "vg0" successfully renamed to "volumegroup0"
9.删除卷组
[root@lab ~]# vgremove vg0
Volume group "vg0" successfully removed
10.创建逻辑卷
[root@lab ~]# lvcreate -n data -L 60M /dev/vg0
Logical volume "data" created
[root@lab ~]# lvs
LV VG Attr LSize Origin Snap% Move Log Copy%
data vg0 -wi-a- 60.00M
[root@lab ~]# lvdisplay
--- Logical volume ---
LV Name /dev/vg0/data
VG Name vg0
LV UUID itASvn-XidW-1MY3-l3tu-mdqX-3VfV-gUZjF7
LV Write Access read/write
LV Status available
# open 0
LV Size 60.00 MB
Current LE 15
Segments 2
Allocation inherit
Read ahead sectors 0
Block device 253:0
11.格式化,挂载
[root@lab ~]# mkfs.ext3 /dev/vg0/data
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
15360 inodes, 61440 blocks
3072 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=62914560
8 block groups
8192 blocks per group, 8192 fragments per group
1920 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@lab ~]# mount /dev/vg0/data /mnt/
[root@lab ~]# ls /mnt/
lost+found
12.增加逻辑卷的尺寸
[root@lab ~]# lvextend -L 80M /dev/vg0/data
Extending logical volume data to 80.00 MB
Logical volume data successfully resized
you can use the additional space-for a standard ext3 filesystem, that requires the
resize2fs
command. If you don't specify a size, it takes all available space.
光扩展了没有用,还需要转化文件系统
[root@lab ~]# resize2fs /dev/vg0/data
13.减少逻辑卷的尺寸
[root@lab ~]# lvreduce -L 20M /dev/vg0/data
WARNING: Reducing active logical volume to 20.00 MB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce data? [y/n]: y
Reducing logical volume data to 20.00 MB
Logical volume data successfully resized
[root@lab ~]# lvrename /dev/vg0/data /dev/vg0/test
Renamed "data" to "test" in volume group "vg0"
[root@lab ~]# lvs
LV VG Attr LSize Origin Snap% Move Log Copy%
test vg0 -wi-a- 20.00M
14.去除逻辑卷
[root@lab ~]# lvremove /dev/vg0/test
Do you really want to remove active logical volume "test"? [y/n]: y
Logical volume "test" successfully removed
[root@lab ~]# lvdisplay
[root@lab ~]# lvs
[root@lab ~]#
确保内存中有如下模块输出
[root@lab ~]# lsmod |grep dm
dm_mirror 29840 0
dm_mod 56665 1 dm_mirror
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/94265/showart_1898173.html |
|