=======================
一:linux下的逻辑卷管理
试验环境
软件工具:vmware
系统平台:linux9.0
硬件配置:两块独立硬盘
=============
二:试验步骤:
1.在linux下安装第二块硬盘;
2.对第二块硬盘进行分区;
3.将分区类型转换为linux lvm类型;
4.建立物理卷;
5.建立卷组;
6.建立逻辑卷;
7.格式化逻辑卷,挂载逻辑卷,并对挂载点进行读取;
8.动态追加或减小逻辑卷的大小,验证数据的完整性和安全性;
9.lvm管理操作;
=============
三:试验过程
1.对第二块硬盘分区,并将其类型转换为linux lvm
[root@www root]# fdisk /dev/sdb //对sdb进行分区;
Command (m for help): p //打印分区表,没有任何分区
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Command (m for help): n //新建分区;
Command action
e extended
p primary partition (1-4)
p //选择主分区;
Partition number (1-4): 1
First cylinder (1-522, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-522, default 522): +200M //设置分区大小;
//按照同样的方法建立第二、第三个分区;再查看分区表,确认没有错误;
Command (m for help): p
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 25 200781 83 Linux
/dev/sdb2 26 50 200812+ 83 Linux
/dev/sdb3 51 75 200812+ 83 Linux
Command (m for help): t //改变分区的类型;
Partition number (1-4): 1 //输入要改变分区的标号;
Hex code (type L to list codes): L //查看分区类型代码表;
0 Empty 1c Hidden Win95 FA 70 DiskSecure Mult bb Boot Wizard hid
1 FAT12 1e Hidden Win95 FA 75 PC/IX be Solaris boot
2 XENIX root 24 NEC DOS 80 Old Minix c1 DRDOS/sec (FAT-
3 XENIX usr 39 Plan 9 81 Minix / old Lin c4 DRDOS/sec (FAT-
4 FAT16 <32M 3c PartitionMagic 82 Linux swap c6 DRDOS/sec (FAT-
5 Extended 40 Venix 80286 83 Linux c7 Syrinx
6 FAT16 41 PPC PReP Boot 84 OS/2 hidden C: da Non-FS data
7 HPFS/NTFS 42 SFS 85 Linux extended db CP/M / CTOS / .
8 AIX 4d QNX4.x 86 NTFS volume set de Dell Utility
9 AIX bootable 4e QNX4.x 2nd part 87 NTFS volume set df BootIt
a OS/2 Boot Manag 4f QNX4.x 3rd part 8e Linux LVM e1 DOS access
b Win95 FAT32 50 OnTrack DM 93 Amoeba e3 DOS R/O
c Win95 FAT32 (LB 51 OnTrack DM6 Aux 94 Amoeba BBT e4 SpeedStor
e Win95 FAT16 (LB 52 CP/M 9f BSD/OS eb BeOS fs
f Win95 Ext'd (LB 53 OnTrack DM6 Aux a0 IBM Thinkpad hi ee EFI GPT
10 OPUS 54 OnTrackDM6 a5 FreeBSD ef EFI (FAT-12/16/
11 Hidden FAT12 55 EZ-Drive a6 OpenBSD f0 Linux/PA-RISC b
12 Compaq diagnost 56 Golden Bow a7 NeXTSTEP f1 SpeedStor
14 Hidden FAT16 <3 5c Priam Edisk a8 Darwin UFS f4 SpeedStor
16 Hidden FAT16 61 SpeedStor a9 NetBSD f2 DOS secondary
17 Hidden HPFS/NTF 63 GNU HURD or Sys ab Darwin boot fd Linux raid auto
18 AST SmartSleep 64 Novell Netware b7 BSDI fs fe LANstep
1b Hidden Win95 FA 65 Novell Netware b8 BSDI swap ff BBT
Hex code (type L to list codes): 8e //选择8e,即linux lvm类型;
Changed system type of partition 1 to 8e (Linux LVM)
//按照同样的方法设置其它分区;最终结果如下显示;
Command (m for help): p
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 25 200781 8e Linux LVM
/dev/sdb2 26 50 200812+ 8e Linux LVM
/dev/sdb3 51 75 200812+ 8e Linux LVM
Command (m for help): w //保存分区表;
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@www root]#reboot //重起计算机;
2.建立物理卷、卷组和逻辑卷,并扫描查看卷信息;
[root@www root]# pvcreate /dev/sdb1 /dev/sdb2 /dev/sdb3 //将分区初始化为物理卷;
pvcreate -- physical volume "/dev/sdb1" successfully created
pvcreate -- physical volume "/dev/sdb2" successfully created
pvcreate -- physical volume "/dev/sdb3" successfully created
[root@www root]# pvscan //扫描物理卷,信息显示物理卷不属于任何卷组;
pvscan -- reading all physical volumes (this may take a while...)
pvscan -- inactive PV "/dev/sdb1" is in no VG [196.08 MB]
pvscan -- inactive PV "/dev/sdb2" is in no VG [196.11 MB]
pvscan -- inactive PV "/dev/sdb3" is in no VG [196.11 MB]
pvscan -- total: 3 [588.29 MB] / in use: 0 [0] / in no VG: 3 [588.29 MB]
[root@www root]# vgscan //扫描卷组,建立lvmtab文件和lvmtab.d目录
vgscan -- reading all physical volumes (this may take a while...)
vgscan -- "/etc/lvmtab" and "/etc/lvmtab.d" successfully created
vgscan -- WARNING: This program does not do a VGDA backup of your volume group
[root@www root]# vgcreate hdqh /dev/sdb1 /dev/sdb2 /dev/sdb3 //建立卷组hdqh;
vgcreate -- INFO: using default physical extent size 4 MB
vgcreate -- INFO: maximum logical volume size is 255.99 Gigabyte
vgcreate -- doing automatic backup of volume group "hdqh"
vgcreate -- volume group "hdqh" successfully created and activated
[root@www root]# vgscan //再次扫描,有活动卷组hdqh出现;
vgscan -- reading all physical volumes (this may take a while...)
vgscan -- found active volume group "hdqh"
vgscan -- "/etc/lvmtab" and "/etc/lvmtab.d" successfully created
vgscan -- WARNING: This program does not do a VGDA backup of your volume group
[root@www root]# pvscan //再次查看物理卷,其属于卷组hdqh;
pvscan -- reading all physical volumes (this may take a while...)
pvscan -- ACTIVE PV "/dev/sdb1" of VG "hdqh" [188 MB / 188 MB free]
pvscan -- ACTIVE PV "/dev/sdb2" of VG "hdqh" [188 MB / 188 MB free]
pvscan -- ACTIVE PV "/dev/sdb3" of VG "hdqh" [188 MB / 188 MB free]
pvscan -- total: 3 [588.29 MB] / in use: 3 [588.29 MB] / in no VG: 0 [0]
root]# lvscan //扫描逻辑卷,没有发现逻辑卷信息;
lvscan -- no logical volumes found
[root@www root]# lvcreate -n data -L 200 hdqh //在卷组hdqh中建立逻辑卷data,-n表示name;-L表示大小;
lvcreate -- doing automatic backup of "hdqh"
lvcreate -- logical volume "/dev/hdqh/data" successfully created
[root@www root]# lvscan //再次扫描逻辑卷,发现/dev/hdqh/data逻辑卷;
lvscan -- ACTIVE "/dev/hdqh/data" [200 MB]
lvscan -- 1 logical volumes with 200 MB total in 1 volume group
lvscan -- 1 active logical volumes
3.格式化逻辑卷、挂载逻辑卷,并对其挂载点进行存取;
[root@www root]# mkfs -t ext3 /dev/hdqh/data //将逻辑卷data采用ext3文件系统格式化;
mke2fs 1.32 (09-Nov-2002)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
76912 inodes, 307200 blocks
15360 blocks (5.00%) reserved for the super user
First data block=1
38 block groups
8192 blocks per group, 8192 fragments per group
2024 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@www root]# mkdir /mnt/lvm //建立挂载点;
[root@www root]# mount /dev/hdqh/data /mnt/lvm //挂载逻辑卷data到挂载点;
[root@www root]# cd /mnt/lvm
[root@www lvm]# ls //以下是存取操作及卸载;
lost+found
[root@www lvm]# touch aa
[root@www lvm]# cp /etc/passwd ./
[root@www lvm]# ll
总用量 14
-rw-r--r-- 1 root root 0 5月 25 17:04 aa
drwx------ 2 root root 12288 5月 25 17:03 lost+found
-rw-r--r-- 1 root root 1430 5月 25 17:04 passwd
[root@www lvm]# cd
[root@www root]# umount /mnt/lvm
4.对lv、vg和pv管理
----逻辑卷管理
//向逻辑卷追加200M空间,并验证其里面以前的数据;
[root@www root]# umount /mnt/lvm //确保逻辑卷未被挂载使用;
[root@www root]# e2fsadm -L +100 /dev/hdqh/data //或者使用命令lvextent,功能一样;
e2fsck 1.32 (09-Nov-2002)
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/hdqh/data: 13/63488 files (0.0% non-contiguous), 12144/253952 blocks
lvextend -- extending logical volume "/dev/hdqh/data" to 400 MB
lvextend -- doing automatic backup of volume group "hdqh"
lvextend -- logical volume "/dev/hdqh/data" successfully extended
resize2fs 1.32 (09-Nov-2002)
Begin pass 1 (max = 19)
Extending the inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 2 (max = 1)
Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 31)
Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 5 (max = 23)
Moving inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/hdqh/data is now 409600 blocks long.
e2fsadm -- ext2fs in logical volume /dev/hdqh/data successfully extended to 400 MB
[root@www root]# mount /dev/hdqh/data /mnt/lvm //挂载逻辑卷,并查看里内容;
[root@www root]# ll /mnt/lvm
总用量 14
-rw-r--r-- 1 root root 0 5月 25 17:04 aa
drwx------ 2 root root 12288 5月 25 17:03 lost+found
-rw-r--r-- 1 root root 1430 5月 25 17:04 passwd
[root@www root]# umount /mnt/lvm
//向逻辑卷减去50M空间,并验证其里面以前的数据;
[root@www root]# e2fsadm -L -50 /dev/hdqh/data
e2fsadm -- rounding size up to physical extent boundary
e2fsck 1.32 (09-Nov-2002)
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/hdqh/data: 13/102400 files (0.0% non-contiguous), 17057/409600 blocks
resize2fs 1.32 (09-Nov-2002)
Begin pass 3 (max = 50)
Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/hdqh/data is now 356352 blocks long.
lvreduce -- WARNING: reducing active logical volume to 348 MB
lvreduce -- THIS MAY DESTROY YOUR DATA (filesystem etc.)
lvreduce -- doing automatic backup of volume group "hdqh"
lvreduce -- logical volume "/dev/hdqh/data" successfully reduced
e2fsadm -- ext2fs in logical volume /dev/hdqh/data successfully reduced to 348 MB
[root@www root]# mount /dev/hdqh/data /mnt/lvm
[root@www root]# ll /mnt/lvm
总用量 14
-rw-r--r-- 1 root root 0 5月 25 17:04 aa
drwx------ 2 root root 12288 5月 25 17:03 lost+found
-rw-r--r-- 1 root root 1430 5月 25 17:04 passwd
[root@www root]# umount /mnt/lvm
[root@www root]# lvremove /dev/hdqh/data //从卷组中移除逻辑卷;
lvremove -- do you really want to remove "/dev/hdqh/data"? [y/n]: y
lvremove -- doing automatic backup of volume group "hdqh"
lvremove -- logical volume "/dev/hdqh/data" successfully removed
[root@www root]# lvscan //再次扫描逻辑卷;
lvscan -- no logical volumes found
----物理卷和卷组管理
//将物理卷sdb2从卷组hdqh中移去;但在移去前向将其数据移动到其它物理卷上;
[root@www root]# pvmove /dev/sdb2 //移动sdb2内的数据到其它物路卷;
pvmove -- moving physical extents in active volume group "hdqh"
pvmove -- WARNING: if you lose power during the move you may need
to restore your LVM metadata from backup!
pvmove -- do you want to continue? [y/n] y //确认你的操作;
/dev/hdqh/group::/dev/hdqh/data: 0812 8576, 0811 8576
/dev/hdqh/group::/dev/hdqh/data: 0812 16768, 0811 16768
/dev/hdqh/group::/dev/hdqh/data: 0812 24960, 0811 24960
...... ...... ...... ......
/dev/hdqh/group::/dev/hdqh/data: 0812 369024, 0811 369024
/dev/hdqh/group::/dev/hdqh/data: 0812 377216, 0811 377216
/dev/hdqh/group::/dev/hdqh/data: 0812 385408, 0811 385408
pvmove -- doing automatic backup of volume group "hdqh"
pvmove -- 47 extents of physical volume "/dev/sdb2" successfully moved
[root@www root]# vgreduce hdqh /dev/hdqh/sdb2 //从卷组hdqh中移除物理卷sdb2
[root@www root]# vgextent hdqh /dev/hdqh/sdb2 //将物理卷添加到卷组hdqh
[root@www root]# vgchange -a n /dev/hdqh
[root@www root]# vgremove /dev/hdqh
详细的过程:
http://hi.baidu.com/rain_at_dna/blog/item/4836063d37102004bba167a7.html