就问一句,怎么破~
找到了,如果是跟分区,就看这个 http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/storage_expand_partition.html , 如果是其他分区不是根分区的就简单了。
#!/bin/sh
# Copyright (C) 2011 Canonical Ltd.
# Copyright (C) 2013 Hewlett-Packard Development Company, L.P.
#
# Authors: Scott Moser
# Juerg Haefliger
#
# 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
FUDGE=${GROWPART_FUDGE:-$((20*1024))}
TEMP_D=""
RESTORE_FUNC=""
RESTORE_HUMAN=""
VERBOSITY=0
DISK=""
PART=""
PT_UPDATE=false
DRY_RUN=0MBR_CHS=""
MBR_BACKUP=""
GPT_BACKUP=""
_capture=""error() {echo "$@" 1>&2
}fail() {[ $# -eq 0 ] || echo "FAILED:" "$@"exit 2
}nochange() {echo "NOCHANGE:" "$@"exit 1
}changed() {echo "CHANGED:" "$@"exit 0
}change() {echo "CHANGE:" "$@"exit 0
}cleanup() {if [ -n "${RESTORE_FUNC}" ]; thenerror "***** WARNING: Resize failed, attempting to revert ******"if ${RESTORE_FUNC} ; thenerror "***** Appears to have gone OK ****"elseerror "***** FAILED! or original partition table" \"looked like: ****"cat "${RESTORE_HUMAN}" 1>&2fifi[ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"
}debug() {local level=${1}shift[ "${level}" -gt "${VERBOSITY}" ] && returnif [ "${DEBUG_LOG}" ]; thenecho "$@" >>"${DEBUG_LOG}"elseerror "$@"fi
}debugcat() {local level="$1"shift;[ "${level}" -gt "$VERBOSITY" ] && returnif [ "${DEBUG_LOG}" ]; thencat "$@" >>"${DEBUG_LOG}"elsecat "$@" 1>&2fi
}mktemp_d() {# just a mktemp -d that doens't need mktemp if its not there._RET=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXX" 2>/dev/null) &&return_RET=$(umask 077 && t="${TMPDIR:-/tmp}/${0##*/}.$$" &&mkdir "${t}" && echo "${t}")return
}Usage() {cat <
EOF
}bad_Usage() {Usage 1>&2error "$&#64;"exit 2
}mbr_restore() {sfdisk --no-reread "${DISK}" ${MBR_CHS} -I "${MBR_BACKUP}"
}sfdisk_worked_but_blkrrpart_failed() {local ret&#61;"$1" output&#61;"$2"# exit code found was just 1, but dont insist on that#[ $ret -eq 1 ] || return 1# Successfully wrote the new partition tablegrep -qi "Success.* wrote.* new.* partition" "$output" &&grep -qi "BLKRRPART: Device or resource busy" "$output"return
}mbr_resize() {RESTORE_HUMAN&#61;"${TEMP_D}/recovery"MBR_BACKUP&#61;"${TEMP_D}/orig.save"local change_out&#61;${TEMP_D}/change.outlocal dump_out&#61;${TEMP_D}/dump.outlocal new_out&#61;${TEMP_D}/new.outlocal dump_mod&#61;${TEMP_D}/dump.modlocal tmp&#61;"${TEMP_D}/tmp.out"local err&#61;"${TEMP_D}/err.out"local _devc cyl _w1 heads _w2 sectors _w3 tot dpartlocal pt_start pt_size pt_end max_end new_size change_info# --show-pt-geometry outputs something like# /dev/sda: 164352 cylinders, 4 heads, 32 sectors/trackrqe sfd_geom sfdisk "${DISK}" --show-pt-geometry >"${tmp}" &&read _devc cyl _w1 heads _w2 sectors _w3 <"${tmp}" &&MBR_CHS&#61;"-C ${cyl} -H ${heads} -S ${sectors}" ||fail "failed to get CHS from ${DISK}"tot&#61;$((${cyl}*${heads}*${sectors}))debug 1 "geometry is ${MBR_CHS}. total size&#61;${tot}"rqe sfd_dump sfdisk ${MBR_CHS} --unit&#61;S --dump "${DISK}" \>"${dump_out}" ||fail "failed to dump sfdisk info for ${DISK}"{echo "## sfdisk ${MBR_CHS} --unit&#61;S --dump ${DISK}"cat "${dump_out}"} >"${RESTORE_HUMAN}"[ $? -eq 0 ] || fail "failed to save sfdisk -d output"debugcat 1 "${RESTORE_HUMAN}"sed -e &#39;s/,//g; s/start&#61;/start /; s/size&#61;/size /&#39; "${dump_out}" \>"${dump_mod}" ||fail "sed failed on dump output"dpart&#61;"${DISK}${PART}" # disk and partition numberif [ -b "${DISK}p${PART}" -a "${DISK%[0-9]}" !&#61; "${DISK}" ]; then# for block devices that end in a number (/dev/nbd0)# the partition is "
}gpt_restore() {sgdisk -l "${GPT_BACKUP}" "${DISK}"
}gpt_resize() {GPT_BACKUP&#61;"${TEMP_D}/pt.backup"local pt_info&#61;"${TEMP_D}/pt.info"local pt_pretend&#61;"${TEMP_D}/pt.pretend"local pt_data&#61;"${TEMP_D}/pt.data"local out&#61;"${TEMP_D}/out"local dev&#61;"disk&#61;${DISK} partition&#61;${PART}"local pt_start pt_end pt_size last pt_max code guid name new_sizelocal old new change_info# Dump the original partition information and details to disk. This is# used in case something goes wrong and human interaction is required# to revert any changes.rqe sgd_info sgdisk "--info&#61;${PART}" --print "${DISK}" >"${pt_info}" ||RESTORE_HUMAN&#61;"${pt_info}"debug 1 "$dev: original sgdisk info:"debugcat 1 "${pt_info}"# Pretend to move the backup GPT header to the end of the disk and dump# the resulting partition information. We use this info to determine if# we have to resize the partition.rqe sgd_pretend sgdisk --pretend --move-second-header \--print "${DISK}" >"${pt_pretend}" ||fail "${dev}: failed to dump pretend sgdisk info"debug 1 "$dev: pretend sgdisk info"debugcat 1 "${pt_pretend}"# Extract the partition data from the pretend dumpawk &#39;found { print } ; $1 &#61;&#61; "Number" { found &#61; 1 }&#39; \"${pt_pretend}" >"${pt_data}" ||fail "${dev}: failed to parse pretend sgdisk info"# Get the start and end sectors of the partition to be grownpt_start&#61;$(awk &#39;$1 &#61;&#61; &#39;"${PART}"&#39; { print $2 }&#39; "${pt_data}") &&[ -n "${pt_start}" ] ||fail "${dev}: failed to get start sector"pt_end&#61;$(awk &#39;$1 &#61;&#61; &#39;"${PART}"&#39; { print $3 }&#39; "${pt_data}") &&[ -n "${pt_end}" ] ||fail "${dev}: failed to get end sector"pt_size&#61;"$((${pt_end} - ${pt_start}))"# Get the last usable sectorlast&#61;$(awk &#39;/last usable sector is/ { print $NF }&#39; \"${pt_pretend}") && [ -n "${last}" ] ||fail "${dev}: failed to get last usable sector"# Find the minimal start sector that is >&#61; pt_end pt_max&#61;$(awk &#39;{ if ($2 >&#61; pt_end && $2
}kver_to_num() {local kver&#61;"$1" maj&#61;"" min&#61;"" mic&#61;"0"kver&#61;${kver%%-*}maj&#61;${kver%%.*}min&#61;${kver#${maj}.}min&#61;${min%%.*}mic&#61;${kver#${maj}.${min}.}[ "$kver" &#61; "$mic" ] && mic&#61;0_RET&#61;$(($maj*1000*1000&#43;$min*1000&#43;$mic))
}kver_cmp() {local op&#61;"$2" n1&#61;"" n2&#61;""kver_to_num "$1"n1&#61;"$_RET"kver_to_num "$3"n2&#61;"$_RET"[ $n1 $op $n2 ]
}rq() {# runquieterror(label, command)# gobble stderr of a command unless it errorslocal label&#61;"$1" ret&#61;"" efile&#61;""efile&#61;"$TEMP_D/$label.err"shift;debug 2 "running[$label][$_capture]" "$&#64;"if [ "${_capture}" &#61; "erronly" ]; then"$&#64;" 2>"$TEMP_D/$label.err"ret&#61;$?else"$&#64;" >"$TEMP_D/$label.err" 2>&1ret&#61;$?fiif [ $ret -ne 0 ]; thenerror "failed [$label:$ret]" "$&#64;"cat "$efile" 1>&2fireturn $ret
}rqe() {local _capture&#61;"erronly"rq "$&#64;"
}verify_ptupdate() {local input&#61;"$1" found&#61;"" reason&#61;"" kver&#61;""# we can always satisfy &#39;off&#39;if [ "$input" &#61; "off" ]; then_RET&#61;"false";return 0;fiif command -v partx >/dev/null 2>&1; thenpartx --help 2>/dev/null | grep -q -- --update || {reason&#61;"partx has no &#39;--update&#39; flag in usage."found&#61;"off"}elsereason&#61;"no &#39;partx&#39; command"found&#61;"off"fiif [ -z "$found" ]; thenif [ "$(uname)" !&#61; "Linux" ]; thenreason&#61;"Kernel is not Linux per uname."found&#61;"off"fifiif [ -z "$found" ]; thenkver&#61;$(uname -r) || debug 1 "uname -r failed!"if ! kver_cmp "${kver-0.0.0}" -ge 3.8.0; thenreason&#61;"Kernel &#39;$kver&#39; <3.8.0."found&#61;"off"fifiif [ -z "$found" ]; then_RET&#61;"true"return 0ficase "$input" inon) error "$reason"; return 1;;auto)_RET&#61;"false";debug 1 "partition update disabled: $reason"return 0;;force)_RET&#61;"true"error "WARNING: ptupdate forced on even though: $reason"return 0;;esacerror "unknown input &#39;$input&#39;";return 1;
}pt_update() {local dev&#61;"$1" part&#61;"$2" update&#61;"${3:-$PT_UPDATE}"if ! $update; thenreturn 0fipartx --update "$part" "$dev"
}has_cmd() {command -v "${1}" >/dev/null 2>&1
}pt_update&#61;"auto"
while [ $# -ne 0 ]; docur&#61;${1}next&#61;${2}case "$cur" in-h|--help)Usageexit 0;;--fudge)FUDGE&#61;${next}shift;;-N|--dry-run)DRY_RUN&#61;1;;-u|--update|--update&#61;*)if [ "${cur#--update&#61;}" !&#61; "$cur" ]; thennext&#61;"${cur#--update&#61;}"elseshiftficase "$next" inoff|auto|force|on) pt_update&#61;$next;;*) fail "unknown --update option: $next";;esac;;-v|--verbose)VERBOSITY&#61;$(($VERBOSITY&#43;1));;--)shiftbreak;;-*)fail "unknown option ${cur}";;*)if [ -z "${DISK}" ]; thenDISK&#61;${cur}else[ -z "${PART}" ] || fail "confused by arg ${cur}"PART&#61;${cur}fi;;esacshift
done[ -n "${DISK}" ] || bad_Usage "must supply disk and partition-number"
[ -n "${PART}" ] || bad_Usage "must supply partition-number"has_cmd "sfdisk" || fail "sfdisk not found"[ -e "${DISK}" ] || fail "${DISK}: does not exist"[ "${PART#*[!0-9]}" &#61; "${PART}" ] || fail "partition-number must be a number"verify_ptupdate "$pt_update" || fail
PT_UPDATE&#61;$_RETdebug 1 "update-partition set to $PT_UPDATE"mktemp_d && TEMP_D&#61;"${_RET}" || fail "failed to make temp dir"
trap cleanup EXIT# get the ID of the first partition to determine if it&#39;s MBR or GPT
id&#61;$(sfdisk --id --force "${DISK}" 1 2>/dev/null) ||fail "unable to determine partition type"if [ "${id}" &#61; "ee" ] ; thenhas_cmd "sgdisk" || fail "GPT partition found but no sgdisk"debug 1 "found GPT partition table (id &#61; ${id})"gpt_resize
elsedebug 1 "found MBR partition table (id &#61; ${id})"mbr_resize
fi# vi: ts&#61;4 noexpandtab
也可以从 http://ojv12llai.bkt.clouddn.com/uploads/20170217171332.sh 这里进行下载
执行命令
bash xx.sh /dev/xvda 1
yum install -y parted
partprobe # 如果不行&#xff0c;只能重启了