diff --git a/LICENSE.txt b/LICENSE.txt index 736d3fe..9304e54 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2017 Michael Crute +Copyright (c) 2017-2020 Michael Crute Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/README.md b/README.md index a202f9b..7ddea38 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,14 @@ and cloud platform support for small size and limited external dependencies. ## Requirements The most important feature of this bootstrapper is the very limited set of -dependencies. In-fact, this works with just busybox -- provided the wget applet -is built-in -- and resize2fs. The only required dependencies are: +dependencies. In-fact, this works with just BusyBox (provided ash and wget +are built in) and a couple utilities for expanding the root filesystem. +The full list of required dependencies are: - bash-like shell (e.g. bash, dash, ash) - wget +- sfdisk +- partx - resize2fs ## Supported Features and Environments @@ -33,7 +36,7 @@ those things. Instead it supports: - installing the instance's SSH keys in the EC2 user's authorized_keys file - running any script-like user data (must start with #!) - disabling root and the EC2 user's password -- resizing root partition to available disk space +- expanding root partition to available disk space These steps only run once. After the initial bootstrap the bootstrapper script is a no-op. To force the script to run again at boot time remove the file diff --git a/tiny-ec2-bootstrap b/tiny-ec2-bootstrap index 944446d..70a9f83 100644 --- a/tiny-ec2-bootstrap +++ b/tiny-ec2-bootstrap @@ -66,11 +66,22 @@ _run_userdata() { ec=$(cat "$ec_file") echo "User Data Script Exit Status: $ec" - return $ec + return "$ec" fi } _resize_root_partition() { + local mountpoint="$(mountpoint -n / | cut -d' ' -f1)" + + # mountpoint is the second partition... + if echo "$mountpoint" | cut -d' ' -f1 | grep -qE '/(nvme\d+n\d+p|xvd[a-z]+)2$'; then + local volume="$(echo "$mountpoint" | sed -Ee 's/(nvme\d+n\d+|xvd[a-z]+)p?2/\1/')" + einfo "Expanding root partition to volume size..." + echo ", +" | sfdisk -q --no-reread -N 2 "$volume" + einfo "Updating kernel with new partition table..." + partx -u "$volume" + fi + einfo "Resizing..." resize2fs "$(mountpoint -n / | cut -d' ' -f1)" } @@ -86,7 +97,7 @@ start() { ebegin "Disabling root password"; _disable_password root; eend $? ebegin "Disabling $EC2_USER password"; _disable_password "$EC2_USER"; eend $? - ebegin "Resizing root partition"; _resize_root_partition; eend $? + ebegin "Expanding root partition"; _resize_root_partition; eend $? ebegin "Setting ec2 hostname"; _update_hostname; eend $? ebegin "Setting ec2 user ssh keys"; _set_ssh_keys "$EC2_USER"; eend $? ebegin "Running ec2 user data script"; _run_userdata; eend $?