Last active
September 24, 2019 10:53
-
-
Save dguerri/4749098 to your computer and use it in GitHub Desktop.
Growroot with LVM for OpenStack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This file is part of the UniCloud project | |
# | |
# Copyright (C) 2013 Unidata S.p.A. (Davide Guerri - [email protected]) | |
# | |
# 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, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# 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/>. | |
# | |
ROOT_DISK="/dev/vda" | |
ROOT_PARTITION="/dev/vda3" | |
VOLUME_GROUP="VolGroup00" | |
LOGICAL_VOLUME="/dev/$VOLUME_GROUP/LogVol00" | |
exec >> /var/log/cloud-resize.log 2>&1 | |
log() { | |
echo `date` : "$@" | |
} | |
# No need to run if ROOT_PARTITION partition is already present | |
pvs | grep $ROOT_PARTITION | |
if [ $? -eq 0 ]; then | |
log "No need to run" | |
exit 0 | |
fi | |
# Ugly as hell... but parted still can't be used.. | |
read -d '' COMMANDS <<- EOF | |
n | |
p | |
3 | |
t | |
3 | |
8e | |
w | |
EOF | |
echo "$COMMANDS" | fdisk $ROOT_DISK | |
partprobe | |
# Wait for ROOT_PARTITION | |
count=5 | |
while [ ! -b $ROOT_PARTITION -o $count -eq 0 ]; do | |
log "Waiting for partition '$ROOT_PARTITION'" | |
sleep 1 | |
count=$(($count - 1)) | |
done | |
if [ ! -b $ROOT_PARTITION ]; then | |
log "Something went wrong... Can't find partition '$ROOT_PARTITION'" | |
exit 1 | |
fi | |
log "Creating pv" | |
pvcreate $ROOT_PARTITION | |
if [ $? -ne 0 ]; then | |
log "Problem executing pvcreate" | |
# TODO: Rollback | |
exit 1 | |
fi | |
log "extending volume group" | |
vgextend $VOLUME_GROUP $ROOT_PARTITION | |
if [ $? -ne 0 ]; then | |
log "Problem executing vgextend" | |
# TODO: Rollback | |
exit 1 | |
fi | |
log "extending logical volume" | |
lvextend $LOGICAL_VOLUME $ROOT_PARTITION | |
if [ $? -ne 0 ]; then | |
log "Problem executing lvextend" | |
# TODO: Rollback | |
exit 1 | |
fi | |
log "resizing filesystem" | |
resize2fs $LOGICAL_VOLUME | |
if [ $? -ne 0 ]; then | |
log "Problem executing resize2fs" | |
# TODO: Rollback | |
exit 1 | |
fi | |
log "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment