|
一、在RHEL 4 中建有名为rhcevg的VG,名为rhcelv的LV,输出如下:
------------------------------------------------------------------
[root@rhce tmp]# pvscan |grep 'rhcevg';lvdisplay rhcevg/rhcelv
/dev/cdrom: open failed: No medium found
PV /dev/hdb1 VG rhcevg lvm2 [92.00 MB / 0 free]
PV /dev/hdb2 VG rhcevg lvm2 [132.00 MB / 124.00 MB free]
PV /dev/hdb3 VG rhcevg lvm2 [100.00 MB / 100.00 MB free]
PV /dev/hdb5 VG rhcevg lvm2 [3.16 GB / 3.16 GB free]
--- Logical volume ---
LV Name /dev/rhcevg/rhcelv
VG Name rhcevg
LV UUID QIuXvv-32p1-prEZ-F4jn-CBxM-gp7r-6vrb0M
LV Write Access read/write
LV Status available
# open 0
LV Size 100.00 MB
Current LE 25
Segments 2
Allocation inherit
Read ahead sectors 0
Block device 253:0
---------------------------------------------------------------------
可以看出rhcelv的大小为100M,VG还有很多未分配空间;
二、增加rhcelv大小至3.26G,即增加3.16G
[root@rhce tmp]# lvresize -L +3.16G rhcevg/rhcelv
Rounding up size to full physical extent 3.16 GB
Extending logical volume rhcelv to 3.26 GB
Logical volume rhcelv successfully resized
[root@rhce tmp]# lvdisplay rhcevg/rhcelv
--- Logical volume ---
LV Name /dev/rhcevg/rhcelv
VG Name rhcevg
LV UUID QIuXvv-32p1-prEZ-F4jn-CBxM-gp7r-6vrb0M
LV Write Access read/write
LV Status available
# open 0
LV Size 3.26 GB
Current LE 834
Segments 4
Allocation inherit
Read ahead sectors 0
Block device 253:0
[root@rhce tmp]# mount /dev/rhcevg/rhcelv /mnt/rhcelv/;df -h |grep 'rhcelv'
/dev/mapper/rhcevg-rhcelv
97M 5.6M 87M 7% /mnt/rhcelv
# 增加后大小容量未更变,执行ext2online命令
[root@rhce tmp]# ext2online /dev/rhcevg/rhcelv
ext2online v1.1.18 - 2001/03/18 for EXT2FS 0.5b
[root@rhce tmp]# df -h |grep 'rhcelv'
/dev/mapper/rhcevg-rhcelv
3.2G 7.2M 3.0G 1% /mnt/rhcelv
[root@rhce tmp]# lvdisplay rhcevg/rhcelv
--- Logical volume ---
LV Name /dev/rhcevg/rhcelv
VG Name rhcevg
LV UUID QIuXvv-32p1-prEZ-F4jn-CBxM-gp7r-6vrb0M
LV Write Access read/write
LV Status available
# open 1
LV Size 3.26 GB
Current LE 834
Segments 4
Allocation inherit
Read ahead sectors 0
Block device 253:0
# 可以看到容量已增加
三、在减小LV大小,如下:
[root@rhce tmp]# umount /mnt/rhcelv/;lvresize -L -2G rhcevg/rhcelv
WARNING: Reducing active logical volume to 1.26 GB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce rhcelv? [y/n]: y
Reducing logical volume rhcelv to 1.26 GB
Logical volume rhcelv successfully resized
# 可以看到大小已减小2G,rhcelv现大小为1.26G,查看
[root@rhce tmp]# pvscan |grep 'rhcevg';lvdisplay rhcevg/rhcelv
/dev/cdrom: open failed: No medium found
PV /dev/hdb1 VG rhcevg lvm2 [92.00 MB / 0 free]
PV /dev/hdb2 VG rhcevg lvm2 [132.00 MB / 0 free]
PV /dev/hdb3 VG rhcevg lvm2 [100.00 MB / 0 free]
PV /dev/hdb5 VG rhcevg lvm2 [3.16 GB / 2.22 GB free]
--- Logical volume ---
LV Name /dev/rhcevg/rhcelv
VG Name rhcevg
LV UUID QIuXvv-32p1-prEZ-F4jn-CBxM-gp7r-6vrb0M
LV Write Access read/write
LV Status available
# open 0
LV Size 1.26 GB
Current LE 322
Segments 4
Allocation inherit
Read ahead sectors 0
Block device 253:0
----------------------------------
# 可以看出大小在pvdisplay中已显示为1.26G,
[root@rhce tmp]# mount /dev/rhcevg/rhcelv /mnt/rhcelv/
[root@rhce tmp]# df -h|grep 'rhcelv'
/dev/mapper/rhcevg-rhcelv
3.2G 7.2M 3.0G 1% /mnt/rhcelv
# 可以看出,容量未改;
[root@rhce tmp]# umount /mnt/rhcelv/
[root@rhce tmp]# fsck.ext3 /dev/rhcevg/rhcelv
e2fsck 1.35 (28-Feb-2004)
The filesystem size (according to the superblock) is 3416064 blocks
The physical size of the device is 1318912 blocks
Either the superblock or the partition table is likely to be corrupt!
Abort<y>?
# 卸载后fsck发现报错,重新格式化
[root@rhce tmp]# mkfs.ext3 /dev/rhcevg/rhcelv
mke2fs 1.35 (28-Feb-2004)
max_blocks 337641472, rsv_groups = 10304, rsv_gdb = 80
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
165088 inodes, 329728 blocks
16486 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=339738624
11 block groups
32768 blocks per group, 32768 fragments per group
15008 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables: done
inode.i_blocks = 3848, i_size = 4243456
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@rhce tmp]# fsck.ext3 /dev/rhcevg/rhcelv
e2fsck 1.35 (28-Feb-2004)
/dev/rhcevg/rhcelv: clean, 11/165088 files, 13881/329728 blocks
-----------------------------------------------------------------
重新格式化后,fsck无误,挂载
[root@rhce tmp]# mount /dev/rhcevg/rhcelv /mnt/rhcelv/;df -h |grep 'rhcelv'
/dev/mapper/rhcevg-rhcelv
1.3G 34M 1.2G 3% /mnt/rhcelv
# 容量改变
#BTW,说实在的,搞了很多次再明白;
# 增加容量只需挂载的状态下ext2online ,(man ext2online发现这一句话,It is only possible to enlarge a mounted filesystem.)
# 减小容量却需重建文件系统,不知可否有其它操作方式? |
|