1
0
mirror of https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud.git synced 2025-12-15 11:22:43 +03:00

Expand root to all available volume space when it's a partition

This commit is contained in:
Jake Buchholz 2020-11-14 18:12:21 -08:00 committed by Mike Crute
parent 7838c22ea6
commit c1d9d27785
3 changed files with 20 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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 $?