-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add script to automatically expand the root filesystem
- Loading branch information
Showing
2 changed files
with
45 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
#this script automatically expands the root filesystem | ||
|
||
set -e | ||
|
||
if [ "$EUID" -ne 0 ]; then | ||
echo "This needs to be run as root." | ||
exit 1 | ||
fi | ||
|
||
part_dev="$(findmnt -T / -no SOURCE)" | ||
disk_dev="$(lsblk --list --noheadings --paths --output PKNAME "$part_dev")" | ||
part_name="$(echo "$part_dev" | rev | cut -d'/' -f1 | rev)" | ||
part_num="$(cat /proc/partitions | grep "$part_name" | awk '{print $2}')" | ||
|
||
echo "Automatically detected root filesystem:" | ||
echo "Disk: $disk_dev" | ||
echo "Partition: $part_dev" | ||
echo | ||
read -p "Press enter to continue, or ctr+c to cancel. " | ||
|
||
echo | ||
echo "Before:" | ||
df -h / | ||
|
||
echo | ||
echo "Expanding the partition and filesystem..." | ||
growpart "$disk_dev" "$part_num" | ||
resize2fs "$part_dev" | ||
|
||
echo | ||
echo "After:" | ||
df -h / | ||
|
||
echo | ||
echo "Done expanding the root filesystem." |