312013
 

1.查看磁盘信息:


[root@lg-centos ~]# df -h
Filesystem                       Size Used Avail Use% Mounted on
/dev/mapper/vg_lgcentos-lv_root  16G  9.8G 5.4G  65% /
tmpfs                            948M 72K  948M  1% /dev/shm
/dev/sda1                        485M 61M  399M  14% /boot

[root@lg-centos ~]# fdisk -l

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: 0x000402bd

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM

Disk /dev/sdb: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x00000000

Disk /dev/mapper/vg_lgcentos-lv_root: 16.7 GB, 16684941312 bytes
255 heads, 63 sectors/track, 2028 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: 0x00000000
Disk /dev/mapper/vg_lgcentos-lv_swap: 4261 MB, 4261412864 bytes
255 heads, 63 sectors/track, 518 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: 0x00000000

2.给/dev/sdb添加分区/dev/sdb1


$fdisk /dev/sdb
	m 查看帮助
	n 添加新分区
	t 修改分区类型为:8e==>Linux LVM
	p 查看分区
	w 写入分区表并退出
	q 不保存分区表并退出

3.扩展逻辑卷/dev/mapper/vg_lgcentos-lv_root的大小

3.1输入lvm,进入LVM管理器(此步骤可省略,直接进行下面的操作,效果完全一样)

3.2将分区转换为物理卷,此步骤可省略:当将分区直接添加到卷组时,LVM会自动将分区转换为物理卷组。这里跳过这一步


lvm> pvcreate /dev/sdb1
     Physical volume "/dev/sdb1" successfully created

相反过程:将物理卷还原为普通分区

lvm> pvremove /dev/sdb1
     Labels on physical volume "/dev/sdb1" successfully wiped

3.3将物理卷添加到现有卷组

lvm> vgextend vg_lgcentos /dev/sdb1
     No physical volume label read from /dev/sdb1
     Physical volume "/dev/sdb1" successfully created
     Volume group "vg_lgcentos" successfully extended

相反过程,将物理卷移除卷组

lvm> vgreduce vg_lgcentos /dev/sdb1
     Removed "/dev/sdb1" from volume group "vg_lgcentos"

3.4使用pvscan命令查看所有物理卷及所属分组

lvm> pvscan
     PV /dev/sda2 VG vg_lgcentos lvm2 [19.51 GiB / 0 free]
     PV /dev/sdb1 VG vg_lgcentos lvm2 [30.00 GiB / 30.00 GiB free]
     Total: 2 [49.50 GiB] / in use: 2 [49.50 GiB] / in no VG: 0 [0 ]

3.5查看所有逻辑卷

lvm> lvscan
ACTIVE '/dev/vg_lgcentos/lv_root' [15.54 GiB] inherit
ACTIVE '/dev/vg_lgcentos/lv_swap' [3.97 GiB] inherit

3.6扩展逻辑卷大小

lvm> lvextend -L +30G /dev/vg_lgcentos/lv_root
     Extending logical volume lv_root to 45.54 GiB
     Insufficient free space: 7680 extents needed, but only 7679 available

注意:上面虽然显示物理卷/dev/sdb1有30.00 GiB空闲,但是这里不能全部使用,29.99G是可以的.

lvm> lvextend -L +29.99G /dev/vg_lgcentos/lv_root
     Rounding size to boundary between physical extents: 29.99 GiB
     Extending logical volume lv_root to 45.54 GiB
     Logical volume lv_root successfully resized

相反过程:减小逻辑卷的大小

lvm> lvreduce -L -7697 /dev/vg_lgcentos/lv_root
     Rounding size to boundary between physical extents: 7.52 GiB
     WARNING: Reducing active and open logical volume to 15.54 GiB
     THIS MAY DESTROY YOUR DATA (filesystem etc.)
     Do you really want to reduce lv_root? [y/n]: y
     Reducing logical volume lv_root to 15.54 GiB
     Logical volume lv_root successfully resized

3.7查看物理卷和逻辑卷


lvm> lvscan
     ACTIVE '/dev/vg_lgcentos/lv_root' [45.54 GiB] inherit
     ACTIVE '/dev/vg_lgcentos/lv_swap' [3.97 GiB] inherit
lvm> pvscan
     PV /dev/sda2 VG vg_lgcentos lvm2 [19.51 GiB / 0 free]
     PV /dev/sdb1 VG vg_lgcentos lvm2 [30.00 GiB / 0 free]
     Total: 2 [49.50 GiB] / in use: 2 [49.50 GiB] / in no VG: 0 [0 ]

3.8虽然这里显示已经将物理卷的空间添加到了逻辑卷上,但是使用df -h命令查看逻辑卷还是没有变化,fdisk -l缺已经生效了,因为还差最后一步激活


[root@lg-centos ~]# df -h
Filesystem                      Size Used Avail Use% Mounted on
/dev/mapper/vg_lgcentos-lv_root 16G  9.8G 5.4G  65% /
tmpfs                           948M 72K  948M  1% /dev/shm
/dev/sda1                       485M 61M  399M  14% /boot

[root@lg-centos ~]# fdisk -l

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: 0x000402bd

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM

Disk /dev/sdb: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x302c030c

Device Boot Start End Blocks Id System
/dev/sdb1 1 3916 31455238+ 8e Linux LVM

Disk /dev/mapper/vg_lgcentos-lv_root: 48.9 GB, 48893001728 bytes
255 heads, 63 sectors/track, 5944 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: 0x00000000
Disk /dev/mapper/vg_lgcentos-lv_swap: 4261 MB, 4261412864 bytes
255 heads, 63 sectors/track, 518 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: 0x00000000

3.9激活即从新读取磁盘信息。


[root@lg-centos ~]# resize2fs -p /dev/vg_lgcentos/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_lgcentos/lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 3
Performing an on-line resize of /dev/vg_lgcentos/lv_root to 11936768 (4k) blocks.
The filesystem on /dev/vg_lgcentos/lv_root is now 11936768 blocks long.

4.执行df -h查看,激活成功


[root@lg-centos ~]# df -h
Filesystem                      Size Used Avail Use% Mounted on
/dev/mapper/vg_lgcentos-lv_root 45G  9.8G 35G   22% /
tmpfs                           948M 72K  948M  1% /dev/shm
/dev/sda1                       485M 61M  399M  14% /boot

对不起,评论功能目前被关闭。