Note: XFS, ResierFS等其他文件系统的resize步骤各有不同。做resize之前,请阅读相关文件系统文档 。如果操作有误可能导致文件系统损坏,请在进行resize之前备份数据!!

LV可以根据需求增大或减小,但是LV改变大小以后,在LV中的文件系统也需要相应的改变大小。这个概念非常重要,如果没有相应的调整LV中文件系统的大小,那么可能导致数据误用!

在下面内容中,我们将指导你增大和缩小LV,并相应处理相关的文件系统,Let's get to it!

增大文件系统


增大LVM中的文件系统可以在线操作(文件系统处于mount状态),为了增大LV 和文件系统:

  • 检查包含文件系统的LV中是否有剩余空间
  • 如果LV中没有剩余空间,则需要扩展LV(可能需要扩展VG,如果没有剩余空间)
  • 使用LV中的所有可用空间增大文件系统

Lets get started!

  1. 首先检查文件系统大小,确认是否需要扩展

    [root@Linux01 ~]# pwd
    /TCPDumpLV

    [root@Linux01 TCPDumpLV]# df -kh .

    Filesystem                                             Size  Used  Avail  Use%  Mounted on
    /dev/mapper/TCPDumpVolGRP-TCPDumpLV  3.1G  2.9G  69M   98%    /TCPDumpLV

    Note: df命令显示系统可用磁盘空间69M,使用率98%,如果不增加空间很快该目录就会被占满。

  2. 让我们确认哪个VG包含LV-> /dev/mapper/TCPDumpVolGRP-TCPDumpLV

    [root@Linux01 ~]# lvdisplay /dev/TCPDumpVolGRP/TCPDumpLV

    --- Logical volume ---

    LV Name                   /dev/TCPDumpVolGRP/TCPDumpLV
    VG Name                  TCPDumpVolGRP
    LV UUID                    hYQs4t-YtY7-51hl-c4ps-4N6d-2W7h-IidcxF
    LV Write Access         read/write
    LV Status                  available
    # open                      1
    LV Size                      3.12 GB
    Current LE                  100
    Segments                   1
    Allocation                    inherit
    Read ahead sectors       auto
    - currently set to          256
    Block device                 253:5

    Note: 从上边输出可以看到对应的VG是TCPDumpVolGRP

  3. 我们检查一下VG->TCPDumpVolGRP是否有足够的可用空间分配给LV

    [root@Linux01 ~]# vgdisplay TCPDumpVolGRP

    --- Volume group ---

    VG Name                           TCPDumpVolGRP
    System ID
    Format                               lvm2
    Metadata Areas  3
    Metadata Sequence No         5
    VG Access                          read/write
    VG Status                           resizable
    MAX LV                              0
    Cur LV                               2
    Open LV                             2
    Max PV                              0
    Cur PV                               3
    Act PV                               3
    VG Size                              11.91 GB
    PE Size                               32.00 MB
    Total PE                             381
    Alloc PE / Size                     228 / 7.12 GB
    Free PE / Size                     153 / 4.78 GB
    VG UUID                             9fWFIS-vDlg-xOW6-Xmb8-Tkrg-GPZw-ZnUZwh

    Note: 由输出可以看出此VG有4.78G可用空间。如果这个可用空间还是不够使用,那么我们就需要先向VG中增加PV才能进行下面步骤。

  4. 此处,我们假设给LV->TCPDumpLV增加3GB

    [root@Linux01 TCPDumpLV]# lvresize -L +3GB /dev/TCPDumpVolGRP/TCPDumpLV
    Extending logical volume TCPDumpLV to 6.12 GB
    Logical volume TCPDumpLV successfully resized
    [root@Linux01 TCPDumpLV]#

  5. 确认LV的新大小

    [root@Linux01 ~]# lvdisplay /dev/TCPDumpVolGRP/TCPDumpLV

    --- Logical volume ---

    LV Name                      /dev/TCPDumpVolGRP/TCPDumpLV
    VG Name                     TCPDumpVolGRP
    LV UUID                       hYQs4t-YtY7-51hl-c4ps-4N6d-2W7h-IidcxF
    LV Write Access            read/write
    LV Status                    available
    # open                        1
    LV Size                        6.12 GB
    Current LE                   196
    Segments                     2
    Allocation                     inherit
    Read ahead sectors        auto
    - currently set to           256
    Block device                  253:5

    [root@Linux01 ~]# pwd

    /TCPDumpLV

    [root@Linux01 TCPDumpLV]# df -kh .

    Filesystem                                                 Size     Used       Avail       Use%       Mounted on
    /dev/mapper/TCPDumpVolGRP-TCPDumpLV      3.1G     2.9G        69M        98%        /TCPDumpLV

    Note: 可以看到 LV已经增大到 6.12GB,但是文件系统仍然是 3.1G没有改变。

  6. 现在需要resize相应的ext3文件系统来利用LV中的可用空间。

    [root@Linux01 TCPDumpLV]# resize2fs -p /dev/mapper/TCPDumpVolGRP-TCPDumpLV
    resize2fs 1.39 (29-May-2006)
    Filesystem at /dev/mapper/TCPDumpVolGRP-TCPDumpLV is mounted on /TCPDumpLV; on-line resizing required
    Performing an on-line resize of /dev/mapper/TCPDumpVolGRP-TCPDumpLV to 1605632 (4k) blocks.
    The filesystem on /dev/mapper/TCPDumpVolGRP-TCPDumpLV is now 1605632 blocks long.

    [root@Linux01 TCPDumpLV]# df -kh .

    Filesystem                                              Size  Used  Avail Use% Mounted on
    /dev/mapper/TCPDumpVolGRP-TCPDumpLV   6.1G  2.9G  2.9G  50%  /TCPDumpLV

OK,我们在线增加了你的文件系统大小!接下来讲解如何减小文件系统大小。

减小文件系统


减小LVM中的文件系统必须离线操作(处于umount装态),要减小文件系统和LV:

  • Unmount相应的文件系统
  • 运行磁盘检查确保卷的完整
  • 减小文件系统
  • 减小LV

Note: You cannot shrink the file system beyond the amount of free space that is available on it.  So if the file system you want to shrink has 1GB of free space, you will only be able to shrink the volume by 1GB.  However, logical volumes are not as forgiving.  If you are not careful, you can shrink the LV to a size less than what is required by the file system.  If the LV is resized smaller than what the file system has been resized to, things will go very badly for you.  Did we mention you should backup your data before hand?

Let's get started!

  1. First, check to see how much space is available

    [root@Linux01 ~]# pwd
    /TCPDumpLV

    [root@Linux01 TCPDumpLV]# df -kh .
    Filesystem                                                 Size     Used      Avail       Use%         Mounted on
    /dev/mapper/TCPDumpVolGRP-TCPDumpLV       6.1G    922M     4.9G        16%          /TCPDumpLV
    Note: The disk free command shows that we are using 922MB and have 4.9G available on our file system.  Therefore, we can safely shrink the volume to 1.5G (leaving a little bit for overhead) without any issue.

  2. 卸载文件系统

    [root@Linux01 TCPDumpLV]# cd /
    [root@Linux01 /]# umount /TCPDumpLV

  3. 检查文件系统是否有错误

    [root@Linux01 /]# e2fsck -f /dev/mapper/TCPDumpVolGRP-TCPDumpLV
    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/mapper/TCPDumpVolGRP-TCPDumpLV: 13/802816 files (7.7% non-contiguous), 261017/1605632 blocks
    [root@Linux01 /]#

  4. 减小文件系统到1.5GB

    [root@Linux01 /]# resize2fs /dev/mapper/TCPDumpVolGRP-TCPDumpLV 1500M
    resize2fs 1.39 (29-May-2006)
    Resizing the filesystem on /dev/mapper/TCPDumpVolGRP-TCPDumpLV to 384000 (4k) blocks.
    The filesystem on /dev/mapper/TCPDumpVolGRP-TCPDumpLV is now 384000 blocks long.
    [root@Linux01 /]#

  5. 减小LV到1.5GB

    [root@Linux01 /]# lvresize -L 1.5G /dev/TCPDumpVolGRP/TCPDumpLV
    WARNING: Reducing active logical volume to 1.50 GB
    THIS MAY DESTROY YOUR DATA (filesystem etc.)
    Do you really want to reduce TCPDumpLV? [y/n]: y
    Reducing logical volume TCPDumpLV to 1.50 GB
    Logical volume TCPDumpLV successfully resized
    [root@Linux01 /]#

    Note: Special precaution should be taken with this step.  It's possible to reduce the logical volume size by more than the size of the file system.  If you do reduce the LV size by more than what you resized the file system to (from step #4), this will almost certainly end very badly for you.  Ensure the LV is large enough for the file system and that you make a backup before hand!

  6. 校验LV的新大小

    [root@Linux01 ~]# lvdisplay /dev/TCPDumpVolGRP/TCPDumpLV

    --- Logical volume ---

    LV Name                       /dev/TCPDumpVolGRP/TCPDumpLV
    VG Name                      TCPDumpVolGRP
    LV UUID                        hYQs4t-YtY7-51hl-c4ps-4N6d-2W7h-IidcxF
    LV Write Access             read/write
    LV Status                     available
    # open                          0
    LV Size                         1.50 GB
    Current LE                     48
    Segments                      1
    Allocation                       inherit
    Read ahead sectors          auto
    - currently set to             256
    Block device                    253:5

  7. 重新挂载文件系统,并校验新大小

    [root@Linux01 /]# mount /dev/TCPDumpVolGRP/TCPDumpLV
    [root@Linux01 /]# cd /TCPDumpLV/

    [root@Linux01 TCPDumpLV]# df -kh .

    Filesystem                                               Size    Used      Avail      Use%      Mounted on
    /dev/mapper/TCPDumpVolGRP-TCPDumpLV    1.5G    920M     497M      65%       /TCPDumpLV

转载于:https://blog.51cto.com/19860827/306625

增大减小LV大小和文件系统相关推荐

  1. linux lv在线缩小大小,Linux使用lvresize扩展或缩减lv大小

    环境:CentOS 6.7 一.新建并挂载目录 /u01 和 /data 1.创建目录挂节点/u01,/data mkdir -p /{u01,data} 2.创建lv,名称是lv_u01,大小10g ...

  2. Android 系统(232)---减小 OTA 大小

    减小 OTA 大小 本页介绍了为减少多次编译之间不必要的文件变更而对 AOSP 编译系统所做的改动.使用专有编译系统的设备实现人员可根据这项信息采取措施,减小无线下载 (OTA) 更新的大小. 有时, ...

  3. 怎么变更linux lv大小,Linux的lvm管理:修改LV大小

    lvm是一种灵活性很强的磁盘空间管理方式,可以方便的增加.减少文件系统的大小,这里说一下增加.减少lv及文件系统大小的操作过程. 修改lv及文件系统的大小,必须先将lv及文件系统卸载(umount), ...

  4. [原]用三行代码实现对音量的控制,实现增大,减小,静音

    用三行代码实现对音量的控制,实现增大,减小,静音,哈哈 增大音量:     keybd_event(VK_VOLUME_UP,MapVirtualKey(VK_VOLUME_UP,0),KEYEVEN ...

  5. gcc参数-Wl,–gc-sections,不链接未用函数,减小可执行文件大小

    背景 在开发一个项目时,使用了非常多的第三方.a静态库文件,导致编译出的可执行文件非常大.这样一是占用ROM空间,二是会导致程序启动加载速度变慢(项目对启动时间非常敏感).其实,这些静态库中的函数,并 ...

  6. 使用gcc参数-Wl,–gc-sections,不链接未用函数,减小可执行文件大小

    背景 在开发一个项目时,使用了非常多的第三方.a静态库文件,导致编译出的可执行文件非常大.这样一是占用ROM空间,二是会导致程序启动加载速度变慢(项目对启动时间非常敏感).其实,这些静态库中的函数,并 ...

  7. 查看lv大小 linux,扩展AIX上的LV大小

    最近由于测试DB2 10.5相关技术,所以有机会搭建一个全新环境,可以自行规划存储.昨天在创建了一些LV,刚刚发现竟然有些LV计算机有误. /db2_src/db2deer$ lsvg datavg1 ...

  8. aix查看lv_(摘抄)AIX下减小lv size

    AIX下减小lv size 1,计算逻辑卷(假设为lvkrnltest)中需要缩小的LP数量 这步不能出错,一旦多删了就麻烦了 这你已经计算好了,是最后20个LP. 2,获取lvkrnltest的LV ...

  9. android 拦截音量键,Android 音量键增大减小捕捉

    Android 音量键增大减小捕捉: @Override public boolean onKeyDown( int keyCode, KeyEvent event) { // TODO Auto-g ...

最新文章

  1. RESTful 规范
  2. 倍福模块通讯协议_认识倍福(Beckhoff)CX5100系列嵌入式控制器
  3. Python学习心得(二) : 更新列表
  4. matplotlib 第二次执行报错在 django web服务中
  5. 01背包怎么不重复_带有重复物品的背包
  6. java.util (Collection接口和Map接口)
  7. Node.js OS 模块
  8. python安装pygame无法找到SDL.h文件
  9. linux里netstat与ps,理解proc目录与linux进程、ps命令、netstat命令的关系
  10. php5.6软件下载,【PHP下载】PHP for Linux 5.6.6-ZOL软件下载
  11. 传感器基础结构与通信原理
  12. 【联想拯救者R7000】安装nvidia驱动Perform MOK management 界面键盘失灵现象(已解决)
  13. 地图定位技术揭秘(二)
  14. mysql grou平by_mysql 中group by怎么样加聚合函数
  15. 密歇根大学新进展:AI+可穿戴设备,20秒检测儿童内化障碍
  16. 【Excel】一、Excel入门指导
  17. 如何u盘安装Linux系统CentOS7.2
  18. 垃圾键盘(bushi) (悲剧文本)
  19. (转)爱剪辑学习记录_快速剪辑视频
  20. AD学习问题记录(四):AD21布线时如何更改线宽

热门文章

  1. Effective Java实作toString() - 就是爱Java
  2. css3 渐变、蒙版
  3. GAC中部署assembly的问题总结
  4. 深入解析Vue组件间通信
  5. 【分析函数】Oracle分析函数之LAG和LEAD
  6. 【zabbix学习笔记之二】部署zabbix-server端
  7. 试用JAVA的免费空间JHOST
  8. 用户界面线程AfxBeginThread的使用
  9. Fedora 从 15.0 开始将修改以太网卡命名规则
  10. c#,winform,验证输入内容,文本框,长度,errorprovider组件,方便,快捷