AWS——扩展linux根目录

需求:创建一个centos6.5镜像,镜像根目录40g

问题描述:

      使用aws社区ami(镜像),创建的镜像根目录只有5g,且不是lvm分区,不符合要求,或者存在30g的镜像,但不是纯净版

解决过程:

1.在aws中新建实例时,将根目录扩展为40g,为后面扩容提供空间


2.进入实例,查看实例状态

         --> 根目录仍为5g

<span style="font-size:12px;">[root@ip-10-10-0-169 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      5.0G  1.6G  3.2G  33% /
tmpfs           498M     0  498M   0% /dev/shm
/dev/xvdf      1008M   34M  924M   4% /opt/</span>

        -->分区仍为5g

<span style="font-size:12px;">[root@ip-10-10-0-169 ~]# lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  40G  0 disk 
+-xvda1 202:1    0   5G  0 part /
xvdf    202:80   0   8G  0 disk /opt/</span>

3.首先扩展分区

          使用growpart脚本,扩展分区,脚本内容见最后。创建growpart脚本,完成分区扩展

<span style="font-size:12px;">sh growpart.sh /dev/xvda 1  </span>

4.运行完成后,需要重启 

      此部分详细步骤可以参照 http://blog.csdn.net/dongdong9223/article/details/48051881

    

 5.运行lsblk,查看分区大小,分区已经扩展

    

<span style="font-size:12px;">[root@centos6 .ssh]# lsblk  
02.NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT  
03.xvda    202:0    0   40G  0 disk   
04.+-xvda1 202:1    0   40G  0 part /  
05.xvdf    202:80   0  100G  0 disk /opt/ 
</span>

    6. 分区扩展完成后,需要对目录进行扩展,使用resize2fs命令,至此,目录扩展成功

 

<span style="font-size:12px;">resize2fs /dev/xvda    </span>


对于LVM卷

    1.lsblk

    2.pvresize

  

pvresize --setphysicalvolumesize 500G /dev/xvdb


    3.lvextend 

lvdisplay
lvextend -L +400G datavg01

  4.resize2fs

resize2fs /dev/mapper/datavg01-data1
<span style="font-size:12px;">
</span>

附:growpart脚本

#!/bin/sh
#    Copyright (C) 2011 Canonical Ltd.
#    Copyright (C) 2013 Hewlett-Packard Development Company, L.P.
#
#    Authors: Scott Moser <smoser@canonical.com>
#             Juerg Haefliger <juerg.haefliger@hp.com>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, version 3 of the License.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

# the fudge factor. if its within this many 512 byte sectors, dont bother
FUDGE=${GROWPART_FUDGE:-$((20*1024))}
TEMP_D=""
RESTORE_FUNC=""
RESTORE_HUMAN=""
VERBOSITY=0
DISK=""
PART=""
PT_UPDATE=false
DRY_RUN=0

MBR_CHS=""
MBR_BACKUP=""
GPT_BACKUP=""
_capture=""

error() {
    echo "$@" 1>&2
}

fail() {
    [ $# -eq 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值