Created
November 17, 2014 05:26
-
-
Save sirdlx/f19e42e9baa37d46b3bf to your computer and use it in GitHub Desktop.
Automatically Resizing a Compute Engine Disk script, http://sookocheff.com/posts/2014-11-11-automatically-resizing-a-compute-engine-disk/
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
STARTUP_VERSION=1 | |
PARTITION_MARK=/var/startup.partition.$STARTUP_VERSION | |
RESIZE_MARK=/var/startup.resize.$STARTUP_VERSION | |
# Repartition the disk to full size | |
function partition() { | |
start_sector=$(sudo fdisk -l | grep ^/dev/sda1 | awk -F" " '{ print $3 }') | |
cat <<EOF | sudo fdisk -c -u /dev/sda | |
d | |
n | |
p | |
1 | |
$start_sector | |
w | |
EOF | |
# We've made the changes to the partition table, they haven't taken effect; we need to reboot. | |
touch $PARTITION_MARK | |
sudo reboot | |
exit | |
} | |
# Resize the filesystem | |
function resize() { | |
resize2fs /dev/sda1 | |
touch $RESIZE_MARK | |
} | |
if [ ! -f $PARTITION_MARK ]; then | |
partition | |
fi | |
if [ ! -f $RESIZE_MARK ]; then | |
resize | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment