mirror of
https://github.com/brain-hackers/brain-config.git
synced 2025-10-15 04:38:41 +09:00
Fix up resize scripts
This commit is contained in:
30
raspi-config
30
raspi-config
@@ -122,21 +122,18 @@ you have heavily customised your installation.\
|
||||
}
|
||||
|
||||
get_can_expand() {
|
||||
ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p')
|
||||
ROOT_PART="$(findmnt / -o source -n)"
|
||||
ROOT_DEV="/dev/$(lsblk -no pkname "$ROOT_PART")"
|
||||
|
||||
PART_NUM=${ROOT_PART#mmcblk0p}
|
||||
if [ "$PART_NUM" = "$ROOT_PART" ]; then
|
||||
echo 1
|
||||
exit
|
||||
fi
|
||||
PART_NUM="$(echo "$ROOT_PART" | grep -o "[[:digit:]]*$")"
|
||||
|
||||
if [ "$PART_NUM" -ne 2 ]; then
|
||||
echo 1
|
||||
exit
|
||||
fi
|
||||
|
||||
LAST_PART_NUM=$(parted /dev/mmcblk0 -ms unit s p | tail -n 1 | cut -f 1 -d:)
|
||||
if [ $LAST_PART_NUM -ne $PART_NUM ]; then
|
||||
LAST_PART_NUM=$(parted "ROOT_DEV" -ms unit s p | tail -n 1 | cut -f 1 -d:)
|
||||
if [ "$LAST_PART_NUM" -ne "$PART_NUM" ]; then
|
||||
echo 1
|
||||
exit
|
||||
fi
|
||||
@@ -144,13 +141,10 @@ get_can_expand() {
|
||||
}
|
||||
|
||||
do_expand_rootfs() {
|
||||
ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p')
|
||||
ROOT_PART="$(findmnt / -o source -n)"
|
||||
ROOT_DEV="/dev/$(lsblk -no pkname "$ROOT_PART")"
|
||||
|
||||
PART_NUM=${ROOT_PART#mmcblk0p}
|
||||
if [ "$PART_NUM" = "$ROOT_PART" ]; then
|
||||
whiptail --msgbox "$ROOT_PART is not an SD card. Don't know how to expand" 20 60 2
|
||||
return 0
|
||||
fi
|
||||
PART_NUM="$(echo "$ROOT_PART" | grep -o "[[:digit:]]*$")"
|
||||
|
||||
# NOTE: the NOOBS partition layout confuses parted. For now, let's only
|
||||
# agree to work with a sufficiently simple partition layout
|
||||
@@ -159,18 +153,18 @@ do_expand_rootfs() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
LAST_PART_NUM=$(parted /dev/mmcblk0 -ms unit s p | tail -n 1 | cut -f 1 -d:)
|
||||
LAST_PART_NUM=$(parted "$ROOT_DEV" -ms unit s p | tail -n 1 | cut -f 1 -d:)
|
||||
if [ $LAST_PART_NUM -ne $PART_NUM ]; then
|
||||
whiptail --msgbox "$ROOT_PART is not the last partition. Don't know how to expand" 20 60 2
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Get the starting offset of the root partition
|
||||
PART_START=$(parted /dev/mmcblk0 -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d: | sed 's/[^0-9]//g')
|
||||
PART_START=$(parted "$ROOT_DEV" -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d: | sed 's/[^0-9]//g')
|
||||
[ "$PART_START" ] || return 1
|
||||
# Return value will likely be error for fdisk as it fails to reload the
|
||||
# partition table because the root fs is mounted
|
||||
fdisk /dev/mmcblk0 <<EOF
|
||||
fdisk "$ROOT_DEV" <<EOF
|
||||
p
|
||||
d
|
||||
$PART_NUM
|
||||
@@ -202,7 +196,7 @@ cat <<EOF > /etc/init.d/resize2fs_once &&
|
||||
case "\$1" in
|
||||
start)
|
||||
log_daemon_msg "Starting resize2fs_once" &&
|
||||
resize2fs /dev/$ROOT_PART &&
|
||||
resize2fs "$ROOT_PART" &&
|
||||
update-rc.d resize2fs_once remove &&
|
||||
rm /etc/init.d/resize2fs_once &&
|
||||
log_end_msg \$?
|
||||
|
Reference in New Issue
Block a user