LVM系统的创建及应用在这里把我做的实验记录一下,以备时间久了不知道如何进行操作,以下大多数为下达命令后系统的显示,可以略过。思路如下:添加硬盘在硬盘上创建LVM分区在LVM分区上创建物理卷将物理卷添加到一个卷组中在卷组中创建逻辑卷其它操作....实验环境:操作系统Fedora10,新加入一块硬盘1,准备阶段新加入一块硬盘,对其进行分区# fdisk -lDisk /dev/sda: 80.0 GB, 80026361856 bytes255 heads, 63 sectors/track, 9729 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk identifier: 0xd274d274 Device Boot Start End Blocks Id System/dev/sda1 * 1 1275 10241406 7 HPFS/NTFS/dev/sda2 1276 9729 67906755 f W95 Ext'd (LBA)/dev/sda5 1276 5100 30724281 7 HPFS/NTFS/dev/sda6 5101 5113 104391 83 Linux/dev/sda7 5114 9729 37077988+ 8e Linux LVMDisk /dev/sdb: 60.0 GB, 60022480896 bytes255 heads, 63 sectors/track, 7297 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk identifier: 0x008a1bef Device Boot Start End Blocks Id System分出两个区来做实验,大小都为10G,分成主分区还是扩展分区对LVM系统没有影响。# fdisk /dev/sdb The number of cylinders for this disk is set to 7297.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-7297, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-7297, default 7297): +10G
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (1307-7297, default 1307):
Using default value 1307
Last cylinder, +cylinders or +size{K,M,G} (1307-7297, default 7297): +10G
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
当前硬盘分区状态# fdisk -lDisk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xd274d274
Device Boot Start End Blocks Id System
/dev/sda1 * 1 1275 10241406 7 HPFS/NTFS
/dev/sda2 1276 9729 67906755 f W95 Ext'd (LBA)
/dev/sda5 1276 5100 30724281 7 HPFS/NTFS
/dev/sda6 5101 5113 104391 83 Linux
/dev/sda7 5114 9729 37077988+
8e Linux LVMDisk /dev/sdb: 60.0 GB, 60022480896 bytes
255 heads, 63 sectors/track, 7297 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x008a1bef
Device Boot Start End Blocks Id System
/dev/sdb1 1 1306 10490413+ 83 Linux
/dev/sdb2 1307 2612 10490445 83 Linux
当前分出来的两个区还不是LVM系统# fdisk /dev/sdb The number of cylinders for this disk is set to 7297.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes):
8eChanged system type of partition 1 to 8e (Linux LVM)
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes):
8eChanged system type of partition 2 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sdb: 60.0 GB, 60022480896 bytes
255 heads, 63 sectors/track, 7297 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x008a1bef
Device Boot Start End Blocks Id System
/dev/sdb1 1 1306 10490413+ 8e Linux LVM
/dev/sdb2 1307 2612 10490445 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
系统类型改完后可以创建物理卷2,创建物理卷# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created
# pvcreate /dev/sdb2 Physical volume "/dev/sdb2" successfully created
查看物理卷所对应的名称# pvscan PV /dev/sda7 VG VolGroup00 lvm2 [35.34 GB / 448.00 MB free]
PV /dev/sdb1 lvm2 [10.00 GB]
PV /dev/sdb2 lvm2 [10.00 GB]
Total: 3 [55.35 GB] / in use: 1 [35.34 GB] / in no VG: 2 [20.01 GB]
或者用# pvdisplay --- Physical volume ---
PV Name /dev/sda7
VG Name VolGroup00
PV Size 35.36 GB / not usable 16.97 MB
Allocatable yes
PE Size (KByte) 32768
Total PE 1131
Free PE 14
Allocated PE 1117
PV UUID KIpgJ5-5vCi-AEgS-6DLp-XWWJ-V2R2-h66UJu
"/dev/sdb1" is a new physical volume of "10.00 GB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 10.00 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 1eiM0Y-cv62-TweF-3Sf1-vhYe-qOcP-3mh5Yg
"/dev/sdb2" is a new physical volume of "10.00 GB"
--- NEW Physical volume ---
PV Name /dev/sdb2
VG Name
PV Size 10.00 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID wECdq4-NEhL-YA9W-04EY-NzJK-j2aH-Zy0nB0
按下来用刚创建完的物理卷创建卷组3,创建卷组# vgcreate homeVG /dev/sdb1 Volume group "homeVG" successfully created
查看一下当前的卷组状态# vgdisplay homeVG --- Volume group ---
VG Name homeVG
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 10.00 GB
PE Size 4.00 MB
Total PE 2561
Alloc PE / Size 0 / 0
Free PE / Size 2561 / 10.00 GB VG UUID zreRv4-4DKm-fsjY-d9bz-6b7D-apDn-ADNeCP
下一步要在减缓VG中创建逻辑卷LV4,创建逻辑卷LV在卷组中创建大小为8GB,名字为homeLV的逻辑卷。# lvcreate -L 8G -n homeLV homeVG Logical volume "homeLV" created
5,在逻辑卷上创建文件系统# mkfs -t ext3 /dev/homeVG/homeLV mke2fs 1.41.3 (12-Oct-2008)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
524288 inodes, 2097152 blocks
104857 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2147483648
64 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
6,编辑/etc/fstab,在文件中加入如下行,以使每次启动自动挂载此文件系统/dev/homeVG/homeLV /home/mnt ext3 defaults 0 0# mount -a# df -h文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVolRoot
7.7G 6.5G 865M 89% /
/dev/mapper/VolGroup00-LogVolVar
20G 407M 18G 3% /var
/dev/mapper/VolGroup00-LogVolHome
2.9G 985M 1.8G 36% /home
/dev/sda6 99M 14M 81M 14% /boot
tmpfs 505M 1.7M 504M 1% /dev/shm
/dev/mapper/homeVG-homeLV
7.9G 147M 7.4G 2% /home/mnt
7,扩展卷组当前卷组# vgscan Reading all physical volumes. This may take a while...
Found volume group "homeVG" using metadata type lvm2
Found volume group "VolGroup00" using metadata type lvm2
homeVG是上面新加的卷组VolGroup00是系统的卷组因为上面建立了物理卷/dev/sdb2,此处用它来进行扩展实验。# vgextend VolGroup00 /dev/sdb2 Volume group "VolGroup00" successfully extended
来查看一下当前的卷组状态# vgdisplay VolGroup00 --- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 8
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 4
Open LV 4
Max PV 0
Cur PV 2
Act PV 2
VG Size 45.34 GB
PE Size 32.00 MB
Total PE 1451
Alloc PE / Size 1117 / 34.91 GB
Free PE / Size 334 / 10.44 GB
VG UUID zcb0mm-M8lK-Aqi3-pL9K-oWjC-cD1D-MQC7aj
8,扩展卷组中的逻辑卷以笔者的硬盘来说,原来建立的/home分区只有3G,太小了,考了一些东西后就不够用了,所以扩展9G来用。# lvextend -L +9G /dev/VolGroup00/LogVolHome Extending logical volume LogVolHome to 16.06 GB
Logical volume LogVolHome successfully resized
此处16G=3G+4G+9G,其中3G为最初的大小,因为系统所在的卷组有剩余空间,扩展了一次卷组的逻辑卷(4G)来看一下LogVolHome逻辑卷的状态# lvdisplay /dev/VolGroup00/LogVolHome --- Logical volume ---
LV Name /dev/VolGroup00/LogVolHome
VG Name VolGroup00
LV UUID N7wd53-TMTO-CRBw-Lmkq-Znbo-MdoG-qxOHty
LV Write Access read/write
LV Status available
# open 1
LV Size 16.06 GB
Current LE 514
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
9,扩展文件系统容量# df -h /home/文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVolHome
2.9G 985M 1.8G 36% /home
# resize2fs -f /dev/VolGroup00/LogVolHome resize2fs 1.41.3 (12-Oct-2008)
Filesystem at /dev/VolGroup00/LogVolHome is mounted on /home; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/VolGroup00/LogVolHome to 4210688 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVolHome is now 4210688 blocks long.
再来看一下/home# df -h /home/文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVolHome
16G 983M 15G 7% /home
此处resize2fs把之前加入的那4G一起放到LogVolHome中了。最后再看一次卷组# vgdisplay
--- Volume group ---
VG Name homeVG
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 10.00 GB
PE Size 4.00 MB
Total PE 2561
Alloc PE / Size 2048 / 8.00 GB
Free PE / Size 513 / 2.00 GB VG UUID zreRv4-4DKm-fsjY-d9bz-6b7D-apDn-ADNeCP
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 9
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 4
Open LV 4
Max PV 0
Cur PV 2
Act PV 2
VG Size 45.34 GB
PE Size 32.00 MB
Total PE 1451
Alloc PE / Size 1405 / 43.91 GB
Free PE / Size 46 / 1.44 GB VG UUID zcb0mm-M8lK-Aqi3-pL9K-oWjC-cD1D-MQC7aj
10,删除卷组删除前卷组状态# vgdisplay --- Volume group ---
VG Name homeVG
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 10.00 GB
PE Size 4.00 MB
Total PE 2561
Alloc PE / Size 2048 / 8.00 GB
Free PE / Size 513 / 2.00 GB
VG UUID zreRv4-4DKm-fsjY-d9bz-6b7D-apDn-ADNeCP
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 9
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 4
Open LV 4
Max PV 0
Cur PV 2
Act PV 2
VG Size 45.34 GB
PE Size 32.00 MB
Total PE 1451
Alloc PE / Size 1405 / 43.91 GB
Free PE / Size 46 / 1.44 GB VG UUID zcb0mm-M8lK-Aqi3-pL9K-oWjC-cD1D-MQC7aj
删除前要先卸载掉# umount /dev/homeVG/homeLV删除卷组# vgremove homeVGDo you really want to remove volume group "homeVG" containing 1 logical volumes? [y/n]: y
Do you really want to remove active logical volume "homeLV"? [y/n]: y
Logical volume "homeLV" successfully removed
Volume group "homeVG" successfully removed
删除后卷组状态# vgdisplay --- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 9
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 4
Open LV 4
Max PV 0
Cur PV 2
Act PV 2
VG Size 45.34 GB
PE Size 32.00 MB
Total PE 1451
Alloc PE / Size 1405 / 43.91 GB
Free PE / Size 46 / 1.44 GB
VG UUID zcb0mm-M8lK-Aqi3-pL9K-oWjC-cD1D-MQC7aj
删除物理卷
删除前的物理卷状态
# pvdisplay
--- Physical volume ---
PV Name /dev/sda7
VG Name VolGroup00
PV Size 35.36 GB / not usable 16.97 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 1131
Free PE 0
Allocated PE 1131
PV UUID KIpgJ5-5vCi-AEgS-6DLp-XWWJ-V2R2-h66UJu
--- Physical volume ---
PV Name /dev/sdb2
VG Name VolGroup00
PV Size 10.00 GB / not usable 4.58 MB
Allocatable yes
PE Size (KByte) 32768
Total PE 320
Free PE 46
Allocated PE 274
PV UUID wECdq4-NEhL-YA9W-04EY-NzJK-j2aH-Zy0nB0
"/dev/sdb1" is a new physical volume of "10.00 GB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 10.00 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 1eiM0Y-cv62-TweF-3Sf1-vhYe-qOcP-3mh5Yg
删除操作# pvremove /dev/sdb1 Labels on physical volume "/dev/sdb1" successfully wiped
删除后的物理卷状态# pvdisplay --- Physical volume ---
PV Name /dev/sda7
VG Name VolGroup00
PV Size 35.36 GB / not usable 16.97 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 1131
Free PE 0
Allocated PE 1131
PV UUID KIpgJ5-5vCi-AEgS-6DLp-XWWJ-V2R2-h66UJu
--- Physical volume ---
PV Name /dev/sdb2
VG Name VolGroup00
PV Size 10.00 GB / not usable 4.58 MB
Allocatable yes
PE Size (KByte) 32768
Total PE 320
Free PE 46
Allocated PE 274
PV UUID wECdq4-NEhL-YA9W-04EY-NzJK-j2aH-Zy0nB0
别忘记了把/etc/fstab中加入的那一行给删除掉11,其它一些操作删除逻辑卷# lvresize -L -10G /dev/VolGroup00/LogVolHome WARNING: Reducing active and open logical volume to 6.06 GB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce LogVolHome? [y/n]: y
Reducing logical volume LogVolHome to 6.06 GB
Logical volume LogVolHome successfully resized
# lvdisplay --- Logical volume ---
LV Name /dev/VolGroup00/LogVolRoot
VG Name VolGroup00
LV UUID 0v7dHP-DHh0-Ercb-9DnF-nl
块的黑色字体0d-OmLi-3JUl5K
LV Write Access read/write
LV Status available
# open 1
LV Size 7.81 GB
Current LE 250
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Name /dev/VolGroup00/LogVolHome
VG Name VolGroup00
LV UUID N7wd53-TMTO-CRBw-Lmkq-Znbo-MdoG-qxOHty
LV Write Access read/write
LV Status available
# open 1
LV Size 6.06 GB
Current LE 194
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Name /dev/VolGroup00/LogVolVar
VG Name VolGroup00
LV UUID 0Xqkx0-YboV-sJjp-wxnD-Ig1P-eBVE-lnEbZ3
LV Write Access read/write
LV Status available
# open 1
LV Size 19.53 GB
Current LE 625
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
--- Logical volume ---
LV Name /dev/VolGroup00/LogVolSwap
VG Name VolGroup00
LV UUID DyX4sQ-Ju5E-fuXW-egfO-EOMy-qPhk-5nxfo9
LV Write Access read/write
LV Status available
# open 1
LV Size 512.00 MB
Current LE 16
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:3