Chinaunix首页 | 论坛 | 博客
  • 博客访问: 208180
  • 博文数量: 54
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 230
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-25 13:58
文章分类

全部博文(54)

文章存档

2014年(12)

2013年(42)

分类: 嵌入式

2013-11-24 22:47:31

扩缩文件系统

一、离线扩展文件系统
二、离线收缩文件系统
三、使用lvresize 进行回缩文件系统
四、在线动态扩展文件系统
五、扩展lv使用vg剩余的所有空间
六、将vg00剩余的所有空间创建为一个lv(yzhqlv)
七、lvextend和lvreduce的小例子说明


测试平台:Red Hat Enterprise Linux Server release 5.2 (Tikanga)


一、离线扩展文件系统
#####################

1. 测试卷/dev/vg00/lv00信息
===========================

[root@rhttt lv00]# lvs
  LV   VG   Attr   LSize  Origin Snap%  Move Log Copy%  Convert
  lv00 vg00 -wi-ao 52.00M                                      
  lv01 vg00 -wi-a- 52.00M                                      
  lv02 vg00 -wi-a- 52.00M                                      

[root@rhttt ~]# mount /dev/vg00/lv00  /lv00
[root@rhttt ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3             3.6G  2.8G  631M  82% /
/dev/sda1              99M   11M   83M  12% /boot
tmpfs                 125M     0  125M   0% /dev/shm
/dev/hdc              2.9G  2.9G     0 100% /mnt
/dev/mapper/vg00-lv00
                       51M  4.9M   43M  11% /lv00
[root@rhttt ~]# 

2. 使用lvextend扩展逻辑卷
==========================
[root@rhttt ~]# umount /lv00
[root@rhttt ~]# lvextend -L +1G /dev/vg00/lv00     /*将逻辑卷lv00加大1G*/
  /dev/cdrom: open failed: Read-only file system
  Extending logical volume lv00 to 1.05 GB
  Logical volume lv00 successfully resized
[root@rhttt ~]# 

[root@rhttt ~]# lvdisplay /dev/vg00/lv00
  --- Logical volume ---
  LV Name                /dev/vg00/lv00
  VG Name                vg00
  LV UUID                cx0Ipu-lZjk-21pY-uTDz-toxm-sWzF-6AL4Mh
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                1.05 GB
  Current LE             269
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
[root@rhttt ~]# 

3. 使用resize2fs扩展文件系统
============================

[root@rhttt ~]# resize2fs  /dev/vg00/lv00
resize2fs 1.39 (29-May-2006)
Please run 'e2fsck -f /dev/vg00/lv00' first.

[root@rhttt ~]# e2fsck -f /dev/vg00/lv00
e2fsck 1.39 (29-May-2006)
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/vg00/lv00: 11/13328 files (9.1% non-contiguous), 6645/53248 blocks
[root@rhttt ~]# resize2fs  /dev/vg00/lv00
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/vg00/lv00 to 1101824 (1k) blocks.
The filesystem on /dev/vg00/lv00 is now 1101824 blocks long.

[root@rhttt ~]# 

4. 挂载该逻辑卷
================

[root@rhttt ~]# mount /dev/vg00/lv00 /lv00
[root@rhttt ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3             3.6G  2.8G  631M  82% /
/dev/sda1              99M   11M   83M  12% /boot
tmpfs                 125M     0  125M   0% /dev/shm
/dev/hdc              2.9G  2.9G     0 100% /mnt
/dev/mapper/vg00-lv00
                      1.1G  6.3M  996M   1% /lv00
[root@rhttt ~]# 

**************************************************************************

二、离线收缩文件系统
#####################

注意:收缩逻辑卷时,收缩后剩余的逻辑卷大小一定不要小于文件系统的大小。

1. 将lv00的文件大小收缩到30M
============================
[root@rhttt ~]# umount /lv00
[root@rhttt ~]# resize2fs   /dev/vg00/lv00  30M
resize2fs 1.39 (29-May-2006)
Please run 'e2fsck -f /dev/vg00/lv00' first.

[root@rhttt ~]# e2fsck -f /dev/vg00/lv00 
e2fsck 1.39 (29-May-2006)
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/vg00/lv00: 13/257040 files (15.4% non-contiguous), 40610/1101824 blocks
[root@rhttt ~]# resize2fs   /dev/vg00/lv00  30M
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/vg00/lv00 to 30720 (1k) blocks.
The filesystem on /dev/vg00/lv00 is now 30720 blocks long.

[root@rhttt ~]# 

2. 将逻辑卷lv00缩小1G
=====================

[root@rhttt ~]# lvreduce -L -1G  /dev/vg00/lv00
  /dev/cdrom: open failed: Read-only file system
  WARNING: Reducing active logical volume to 52.00 MB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv00? [y/n]: y
  Reducing logical volume lv00 to 52.00 MB
  Logical volume lv00 successfully resized
[root@rhttt ~]# 

3. 挂载该逻辑卷
================

[root@rhttt ~]# mount /dev/vg00/lv00 /lv00

**************************************************************************
三、使用lvresize 进行回缩文件系统
==================================

lvresize可以扩展和回缩文件系统

这个例子:在文件系统挂载的情况下,逻辑卷的大大于文件系统的大小,且超过10m时,
对逻辑卷进行回缩10m的实验,回缩后,对该逻辑卷进行了remount。


[root@rhttt lv00]# lvresize  -L -10m  /dev/vg00/lv00
  /dev/cdrom: open failed: Read-only file system
  Rounding up size to full physical extent 8.00 MB
  WARNING: Reducing active and open logical volume to 44.00 MB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv00? [y/n]: y
  Reducing logical volume lv00 to 44.00 MB
  Logical volume lv00 successfully resized
[root@rhttt lv00]#

[root@rhttt lv00]# mount -o remount /lv00
[root@rhttt lv00]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3             3.6G  2.8G  631M  82% /
/dev/sda1              99M   11M   83M  12% /boot
tmpfs                 125M     0  125M   0% /dev/shm
/dev/hdc              2.9G  2.9G     0 100% /mnt
/dev/mapper/vg00-lv00
                       30M  6.4M   22M  23% /lv00
[root@rhttt lv00]# 

**************************************************************************

四、在线动态扩展文件系统
########################

例子:在文件系统挂载的情况下操作,先用lvextend对逻辑卷的容量进行增加1G的大小操作,然后再用
resize2fs直接对文件系统进行在线的扩展,扩展后,可以看到文件系统无需重挂载就已经变成了新的大小。

注意:2.6的内核支持resize2fs的在线扩展,但不支持在线回缩。

The  resize2fs program will resize ext2 or ext3 file systems.  It can be used to enlarge or shrink an unmounted
file system located on device.  If the filesystem is mounted, it can be used to expand the size of the  mounted
filesystem,  assuming the kernel supports on-line resizing.  (As of this writing, the Linux 2.6 kernel supports
on-line resize for filesystems mounted using ext3 only.).

以下是操作示例:

[root@rhttt lv00]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3             3.6G  2.8G  631M  82% /
/dev/sda1              99M   11M   83M  12% /boot
tmpfs                 125M     0  125M   0% /dev/shm
/dev/hdc              2.9G  2.9G     0 100% /mnt
/dev/mapper/vg00-lv00
                       30M  6.4M   22M  23% /lv00
[root@rhttt lv00]# lvextend -L +1G /dev/vg00/lv00
  /dev/cdrom: open failed: Read-only file system
  Extending logical volume lv00 to 1.04 GB
  Logical volume lv00 successfully resized
[root@rhttt lv00]# resize2fs /dev/vg00/lv00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/vg00/lv00 is mounted on /lv00; on-line resizing required
Performing an on-line resize of /dev/vg00/lv00 to 1093632 (1k) blocks.
The filesystem on /dev/vg00/lv00 is now 1093632 blocks long.

[root@rhttt lv00]# 


[root@rhttt lv00]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3             3.6G  2.8G  631M  82% /
/dev/sda1              99M   11M   83M  12% /boot
tmpfs                 125M     0  125M   0% /dev/shm
/dev/hdc              2.9G  2.9G     0 100% /mnt
/dev/mapper/vg00-lv00
                      1.1G  8.0M  997M   1% /lv00
[root@rhttt lv00]# 

在线缩文件系统不支持
=====================

[root@rhttt ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3             3.6G  2.8G  631M  82% /
/dev/sda1              99M   11M   83M  12% /boot
tmpfs                 125M     0  125M   0% /dev/shm
/dev/hdc              2.9G  2.9G     0 100% /mnt
/dev/mapper/vg00-lv00
                      1.1G   28M  978M   3% /lv00
[root@rhttt ~]# resize2fs /dev/vg00/lv00  300m
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/vg00/lv00 is mounted on /lv00; on-line resizing required
On-line shrinking from 1093632 to 307200 not supported.
[root@rhttt ~]# 
[root@rhttt ~]# 

(1)卸载文件系统后,回缩逻辑卷文件系统到300m大小

[root@rhttt ~]# umount /lv00
[root@rhttt ~]# resize2fs /dev/vg00/lv00  300m
resize2fs 1.39 (29-May-2006)
Please run 'e2fsck -f /dev/vg00/lv00' first.

[root@rhttt ~]# e2fsck -f /dev/vg00/lv00
e2fsck 1.39 (29-May-2006)
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/vg00/lv00: 14/255136 files (14.3% non-contiguous), 60318/1093632 blocks
[root@rhttt ~]# resize2fs /dev/vg00/lv00  300m
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/vg00/lv00 to 307200 (1k) blocks.
The filesystem on /dev/vg00/lv00 is now 307200 blocks long.

[root@rhttt ~]# 

(2) 使用lvreduce减小逻辑卷的大小。
注意:减小后的大小不能小于文件的大小,否则会丢失数据。

[root@rhttt ~]# lvs
  LV   VG   Attr   LSize  Origin Snap%  Move Log Copy%  Convert
  lv00 vg00 -wi-a-  1.04G                                      
  lv01 vg00 -wi-a- 52.00M                                      
  lv02 vg00 -wi-a- 52.00M                                      
[root@rhttt ~]# lvreduce -L -600M /dev/vg00/lv00
  /dev/cdrom: open failed: Read-only file system
  WARNING: Reducing active logical volume to 468.00 MB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv00? [y/n]: y
  Reducing logical volume lv00 to 468.00 MB
  Logical volume lv00 successfully resized
[root@rhttt ~]# mount /dev/vg00/lv00  /lv00
[root@rhttt ~]# 

五、扩展lv使用vg剩余的所有空间
##############################

-l, --extents [+]LogicalExtentsNumber[%{VG|LV|PVS|FREE}]
       Extend or set the  logical  volume  size  in  units  of  logical
       extents.   With the + sign the value is added to the actual size
       of the logical volume and without it, the value is taken  as  an
       absolute  one.  The number can also be expressed as a percentage
       of the total space in the Volume Group with the suffix %VG, rel-
       ative to the existing size of the Logical Volume with the suffix
       %LV, of the remaining free space for the specified  PhysicalVol-
       ume(s) with the suffix %PVS, or as a percentage of the remaining
       free space in the Volume Group with the suffix %FREE.

错误的写法:
[root@oradb1 ~]# lvextend -l 100%FREE /dev/vg00/lv06
  New size given (57 extents) not larger than existing size (128 extents)
  Run `lvextend --help' for more information.
[root@oradb1 ~]# 

正确的写法:
[root@oradb1 ~]# lvextend -l +100%FREE /dev/vg00/lv06
  Extending logical volume lv06 to 5.78 GB
  Logical volume lv06 successfully resized
[root@oradb1 ~]# 

正确的写法应为+100%FREE,注意这个加号"+", 同这个不同的是:将vg00剩余的所有空间创建为一个lv,
lvceate 前面不需要加加号,如下一个标题所示:

[root@oradb1 ~]# resize2fs  /dev/vg00/lv06
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/vg00/lv06 is mounted on /u01; on-line resizing required
Performing an on-line resize of /dev/vg00/lv06 to 1515520 (4k) blocks.
The filesystem on /dev/vg00/lv06 is now 1515520 blocks long.

[root@oradb1 ~]# 

六、将vg00剩余的所有空间创建为一个lv(yzhqlv)
###########################################

-l, --extents LogicalExtentsNumber[%{VG|PVS|FREE}]
       Gives the number of logical extents to allocate for the new logical volume.  This can also be  expressed
       as  a percentage of the total space in the Volume Group with the suffix %VG, of the remaining free space
       in the Volume Group with the suffix %FREE, or of the remaining free space for the specified PhysicalVol-
       ume(s) with the suffix %PVS,

[root@rhttt ~]# lvcreate -l 100%FREE -n yzhqlv vg00
  Logical volume "yzhqlv" created
[root@rhttt ~]# 

可以看到创建完后,vg00没有剩余的PE了.

[root@rhttt ~]# vgdisplay  vg00
  --- Volume group ---
  VG Name               vg00
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  26
  VG Access             read/write
  VG Status             resizable
  MAX LV                256
  Cur LV                4
  Open LV               1
  Max PV                256
  Cur PV                2
  Act PV                2
  VG Size               4.05 GB
  PE Size               4.00 MB
  Total PE              1036
  Alloc PE / Size       1036 / 4.05 GB
  Free  PE / Size       0 / 0   
  VG UUID               2IEBLZ-M2pV-Me75-owiW-W3hr-XGEO-n3eYui
   
[root@rhttt ~]# 

**************************************************************************

七、lvextend和lvreduce的小例子说明
###################################

The following command extends the logical volumne /dev/myvg/homevol to 12 gigabytes.
# lvextend -L12G /dev/myvg/homevol
lvextend -- extending logical volume "/dev/myvg/homevol" to 12 GB
lvextend -- doing automatic backup of volume group "myvg"
lvextend -- logical volume "/dev/myvg/homevol" successfully extended

The following command adds another gigabyte to the logical volume /dev/myvg/homevol.
# lvextend -L+1G /dev/myvg/homevol
lvextend -- extending logical volume "/dev/myvg/homevol" to 13 GB
lvextend -- doing automatic backup of volume group "myvg"
lvextend -- logical volume "/dev/myvg/homevol" successfully extended

As with the lvcreate command, you can use the -l argument of the lvextend command to specify
the number of extents by which to increase the size of the logical volume. You can also use
this argument to specify a percentage of the volume group, or a percentage of the remaining
free space in the volume group. The following command extends the logical volume called


Growing Logical Volumes testlv to fill all of the unallocated space in the volume group myvg.
[root@tng3-1 ~]# lvextend -l +100%FREE /dev/myvg/testlv
Extending logical volume testlv to 68.59 GB
Logical volume testlv successfully resized

After you have extended the logical volume it is necessary to increase the file system size to match.
By default, most file system resizing tools will increase the size of the file system to be the size
of the underlying logical volume so you do not need to worry about specifying the same size for
each of the two commands.


"lvextend -L +54 /dev/vg01/lvol10 /dev/sdk3" tries to extend the size of that logical volume by 54MB on  physi-
cal volume /dev/sdk3.  This is only possible if /dev/sdk3 is a member of volume group vg01 and there are enough
free physical extents in it.

"lvextend /dev/vg01/lvol01 /dev/sdk3" tries to extend the size of that logical volume by  the  amount  of  free
space on physical volume /dev/sdk3.  This is equivalent to specifying "-l +100%PVS" on the command line.


"lvreduce -l -3 vg00/lvol1" reduces the size of logical volume lvol1 in volume group vg00 by 3 logical extents.
阅读(2371) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~