试验逻辑卷管理,环境redhat6.0 32bit
过程:先分区,由逻辑分区制作物理卷(pv),由两个pv创建卷组(vg),然后由卷组创建逻辑卷(lv),最后动态扩展lv,vg。
[root@localhost ~]# ls /dev/sda* #有三个主分区
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3
[root@localhost ~]# fdisk /dev/sda #先分区
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e #选择扩展分区
Selected partition 4
First cylinder (1593-2610, default 1593):
Using default value 1593
Last cylinder, +cylinders or +size{K,M,G} (1593-2610, default 2610): #剩余的空间全给扩展分区,否则剩下来的就浪费了,呵呵。。
Using default value 2610
Command (m for help): p
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cf610
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 287 2097152 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 287 1593 10485760 83 Linux
/dev/sda4 1593 2610 8176089 5 Extended
Command (m for help): n
First cylinder (1593-2610, default 1593):
Using default value 1593
Last cylinder, +cylinders or +size{K,M,G} (1593-2610, default 2610): +50M #分一个50M的逻辑分区sda5
Command (m for help): n
First cylinder (1600-2610, default 1600):
Using default value 1600
Last cylinder, +cylinders or +size{K,M,G} (1600-2610, default 2610): +50M #sda6,使用sda5,sda6创建vg
Command (m for help): n
First cylinder (1607-2610, default 1607):
Using default value 1607
Last cylinder, +cylinders or +size{K,M,G} (1607-2610, default 2610): +50M #sda7,用作扩展vg
Command (m for help): p
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cf610
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 287 2097152 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 287 1593 10485760 83 Linux
/dev/sda4 1593 2610 8176089 5 Extended
/dev/sda5 1593 1599 55200 83 Linux
/dev/sda6 1600 1606 56196 83 Linux
/dev/sda7 1607 1613 56196 83 Linux
Command (m for help): t #分别选择sda5,6,7的分区类型,8e是LVM类型
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): w #保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@localhost ~]# ls /dev/sda* #这时/dev/下面还没有这几个分区
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3
[root@localhost ~]# partx -a /dev/sda #刷新一下分区表就可以了
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
[root@localhost ~]# ls /dev/sda* #现在有这几个分区了,可以创建pv了
/dev/sda /dev/sda2 /dev/sda4 /dev/sda6
/dev/sda1 /dev/sda3 /dev/sda5 /dev/sda7
[root@localhost ~]# pvcreate /dev/sda{5,6} #使用sda5,6创建两个pv
Physical volume "/dev/sda5" successfully created
Physical volume "/dev/sda6" successfully created
[root@localhost ~]# vgcreate vg1 /dev/sda{5,6} #然后创建卷组vg1
Volume group "vg1" successfully created
[root@localhost ~]# vgdisplay #可以看下卷组的信息。
--- Volume group ---
VG Name vg1
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 MiB #可以看到这个卷组是大概100M的
PE Size 4.00 MiB
Total PE 26
Alloc PE / Size 0 / 0
Free PE / Size 26 / 104.00 MiB
VG UUID unkxce-gUn1-pkB9-dvAe-0gMl-rg8h-C5ESMZ
[root@localhost ~]# lvcreate -L 70M -n lv1 vg1 #在卷组vg1中拿出70M创建一个逻辑卷lv1
Rounding up size to full physical extent 72.00 MiB
Logical volume "lv1" created
[root@localhost ~]# lvdisplay #查看一下lv1的信息
--- Logical volume ---
LV Name /dev/vg1/lv1
VG Name vg1
LV UUID N80PAh-gvXV-1APU-fh2u-I2g6-x4fG-5MuyA1
LV Write Access read/write
LV Status available
# open 0
LV Size 72.00 MiB #可以看到大概为70M左右
Current LE 18
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
[root@localhost ~]# mkfs.ext4 /dev/vg1/lv1 #格式化lv1的文件系统为ext4
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
18432 inodes, 73728 blocks
3686 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=67371008
9 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345
正在写入inode表: 完成
Creating journal (4096 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.
[root@localhost ~]# mkdir /lvm1 #创建lv1的挂载点
[root@localhost ~]# mount /dev/vg1/lv1 /lvm1/ #挂载
[root@localhost ~]# df -hT #查看系统挂载情况
文件系统 类型 容量 已用 可用 已用%% 挂载点
/dev/sda3 ext4 9.9G 2.4G 7.0G 26% /
tmpfs tmpfs 504M 424K 504M 1% /dev/shm
/dev/sda1 ext4 194M 24M 161M 13% /boot
/dev/sr0 iso9660 2.8G 2.8G 0 100% /media/RHEL_6.0 i386 Disc 1
/dev/mapper/vg1-lv1
ext4 70M 5.3M 61M 8% /lvm1 #可以看到lv1的文件系统为ext4,大小为70M
[root@localhost ~]# lvextend -L +20M /dev/vg1/lv1 #扩展逻辑卷lv1,增加20M
Extending logical volume lv1 to 92.00 MiB
Logical volume lv1 successfully resized
[root@localhost ~]# df -hT #但是此时查看挂载情况还是显示70M
文件系统 类型 容量 已用 可用 已用%% 挂载点
/dev/sda3 ext4 9.9G 2.4G 7.0G 26% /
tmpfs tmpfs 504M 424K 504M 1% /dev/shm
/dev/sda1 ext4 194M 24M 161M 13% /boot
/dev/sr0 iso9660 2.8G 2.8G 0 100% /media/RHEL_6.0 i386 Disc 1
/dev/mapper/vg1-lv1
ext4 70M 5.3M 61M 8% /lvm1
[root@localhost ~]# resize2fs /dev/vg1/lv1 #需要通过resize2fs刷新lv1
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg1/lv1 is mounted on /lvm1; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/vg1/lv1 to 94208 (1k) blocks.
The filesystem on /dev/vg1/lv1 is now 94208 blocks long.
[root@localhost ~]# df -hT #再次查看,lv1显示为90M左右
文件系统 类型 容量 已用 可用 已用%% 挂载点
/dev/sda3 ext4 9.9G 2.4G 7.0G 26% /
tmpfs tmpfs 504M 424K 504M 1% /dev/shm
/dev/sda1 ext4 194M 24M 161M 13% /boot
/dev/sr0 iso9660 2.8G 2.8G 0 100% /media/RHEL_6.0 i386 Disc 1
/dev/mapper/vg1-lv1
ext4 89M 5.6M 79M 7% /lvm1
[root@localhost ~]# vgextend /dev/vg1 /dev/sda7 #通过sda7扩展卷组vg1的容量
No physical volume label read from /dev/sda7
Physical volume "/dev/sda7" successfully created
Volume group "vg1" successfully extended
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name vg1
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 3
Act PV 3
VG Size 156.00 MiB #扩展后看以看到vg1的容量变为150M左右
PE Size 4.00 MiB
Total PE 39
Alloc PE / Size 23 / 92.00 MiB
Free PE / Size 16 / 64.00 MiB
VG UUID unkxce-gUn1-pkB9-dvAe-0gMl-rg8h-C5ESMZ
[root@localhost ~]# lvextend -L +30M /dev/vg1/lv1 #现在可以扩展lv1的容量到100M以上了,这里再加上30M,lv1的容量应该在120M左右
Rounding up size to full physical extent 32.00 MiB
Extending logical volume lv1 to 124.00 MiB
Logical volume lv1 successfully resized
[root@localhost ~]# resize2fs /dev/vg1/lv1 #刷新
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg1/lv1 is mounted on /lvm1; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/vg1/lv1 to 126976 (1k) blocks.
The filesystem on /dev/vg1/lv1 is now 126976 blocks long.
[root@localhost ~]# df -hT
文件系统 类型 容量 已用 可用 已用%% 挂载点
/dev/sda3 ext4 9.9G 2.4G 7.0G 26% /
tmpfs tmpfs 504M 424K 504M 1% /dev/shm
/dev/sda1 ext4 194M 24M 161M 13% /boot
/dev/sr0 iso9660 2.8G 2.8G 0 100% /media/RHEL_6.0 i386 Disc 1
/dev/mapper/vg1-lv1
ext4 120M 5.6M 109M 5% /lvm1 #可以看到lv1的容量的确扩展到了120M,试验成功。
[root@localhost ~]#