需求:创建一个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.youkuaiyun.com/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