Adds ability to run root-fs expansion non-interactively by passing the argument --expand-rootfs.

This is very useful if you need to implement an automatic disk space expansion.
This commit is contained in:
Viktor Petersson 2013-03-26 22:58:32 +01:00
parent 9199bf25ea
commit 3320564bd2
2 changed files with 17 additions and 8 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.swp

View File

@ -3,13 +3,14 @@
# #
# See LICENSE file for copyright and license details # See LICENSE file for copyright and license details
INTERACTIVE=True
ASK_TO_REBOOT=0 ASK_TO_REBOOT=0
do_info() { do_info() {
whiptail --msgbox "\ whiptail --msgbox "\
This tool provides a straight-forward way of doing initial This tool provides a straight-forward way of doing initial
configuration of the Raspberry Pi. Although it can be run configuration of the Raspberry Pi. Although it can be run
at any time, some of the options may have difficulties if at any time, some of the options may have difficulties if
you have heavily customised your installation.\ you have heavily customised your installation.\
" 20 70 1 " 20 70 1
} }
@ -18,7 +19,7 @@ do_expand_rootfs() {
# Get the starting offset of the root partition # Get the starting offset of the root partition
PART_START=$(parted /dev/mmcblk0 -ms unit s p | grep "^2" | cut -f 2 -d:) PART_START=$(parted /dev/mmcblk0 -ms unit s p | grep "^2" | cut -f 2 -d:)
[ "$PART_START" ] || return 1 [ "$PART_START" ] || return 1
# Return value will likely be error for fdisk as it fails to reload the # Return value will likely be error for fdisk as it fails to reload the
# partition table because the root fs is mounted # partition table because the root fs is mounted
fdisk /dev/mmcblk0 <<EOF fdisk /dev/mmcblk0 <<EOF
p p
@ -65,8 +66,9 @@ esac
EOF EOF
chmod +x /etc/init.d/resize2fs_once && chmod +x /etc/init.d/resize2fs_once &&
update-rc.d resize2fs_once defaults && update-rc.d resize2fs_once defaults &&
whiptail --msgbox "Root partition has been resized.\n\ if [ "$INTERACTIVE" = True ]; then
The filesystem will be enlarged upon the next reboot" 20 60 2 whiptail --msgbox "Root partition has been resized.\nThe filesystem will be enlarged upon the next reboot" 20 60 2
fi
} }
set_config_var() { set_config_var() {
@ -125,7 +127,7 @@ set_overscan() {
do_overscan() { do_overscan() {
whiptail --yesno "What would you like to do with overscan" 20 60 2 \ whiptail --yesno "What would you like to do with overscan" 20 60 2 \
--yes-button Disable --no-button Enable --yes-button Disable --no-button Enable
RET=$? RET=$?
if [ $RET -eq 0 ] || [ $RET -eq 1 ]; then if [ $RET -eq 0 ] || [ $RET -eq 1 ]; then
ASK_TO_REBOOT=1 ASK_TO_REBOOT=1
@ -302,7 +304,7 @@ do_ssh() {
return 1 return 1
fi fi
whiptail --yesno "Would you like the SSH server enabled or disabled?" 20 60 2 \ whiptail --yesno "Would you like the SSH server enabled or disabled?" 20 60 2 \
--yes-button Enable --no-button Disable --yes-button Enable --no-button Disable
RET=$? RET=$?
if [ $RET -eq 0 ]; then if [ $RET -eq 0 ]; then
update-rc.d ssh enable && update-rc.d ssh enable &&
@ -378,6 +380,12 @@ do
printf "Not currently supported\n" printf "Not currently supported\n"
exit 1 exit 1
;; ;;
--expand-rootfs)
INTERACTIVE=False
do_expand_rootfs
printf "Please reboot\n"
exit 0
;;
*) *)
# unknown option # unknown option
;; ;;