mirror of
https://github.com/brain-hackers/brain-config.git
synced 2025-01-03 10:00:07 +09:00
Fix up resize scripts
This commit is contained in:
parent
04ec68ab5c
commit
0e776cc153
6
debian/changelog
vendored
6
debian/changelog
vendored
@ -1,10 +1,10 @@
|
|||||||
raspi-config (20200514) buster; urgency=medium
|
raspi-config (20200515) buster; urgency=medium
|
||||||
|
|
||||||
* Update initial resize script
|
* Update initial resize script
|
||||||
- Change disk ID to avoid clashes
|
- Change disk ID to avoid clashes
|
||||||
* Add boot order selector
|
* Add support for USB resize
|
||||||
|
|
||||||
-- Serge Schneider <serge@raspberrypi.org> Thu, 14 May 2020 06:33:23 +0100
|
-- Serge Schneider <serge@raspberrypi.com> Fri, 15 May 2020 08:47:17 +0100
|
||||||
|
|
||||||
raspi-config (20200504) buster; urgency=medium
|
raspi-config (20200504) buster; urgency=medium
|
||||||
|
|
||||||
|
30
raspi-config
30
raspi-config
@ -122,21 +122,18 @@ you have heavily customised your installation.\
|
|||||||
}
|
}
|
||||||
|
|
||||||
get_can_expand() {
|
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}
|
PART_NUM="$(echo "$ROOT_PART" | grep -o "[[:digit:]]*$")"
|
||||||
if [ "$PART_NUM" = "$ROOT_PART" ]; then
|
|
||||||
echo 1
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$PART_NUM" -ne 2 ]; then
|
if [ "$PART_NUM" -ne 2 ]; then
|
||||||
echo 1
|
echo 1
|
||||||
exit
|
exit
|
||||||
fi
|
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
|
if [ "$LAST_PART_NUM" -ne "$PART_NUM" ]; then
|
||||||
echo 1
|
echo 1
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
@ -144,13 +141,10 @@ get_can_expand() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
do_expand_rootfs() {
|
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}
|
PART_NUM="$(echo "$ROOT_PART" | grep -o "[[:digit:]]*$")"
|
||||||
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
|
|
||||||
|
|
||||||
# NOTE: the NOOBS partition layout confuses parted. For now, let's only
|
# NOTE: the NOOBS partition layout confuses parted. For now, let's only
|
||||||
# agree to work with a sufficiently simple partition layout
|
# agree to work with a sufficiently simple partition layout
|
||||||
@ -159,18 +153,18 @@ do_expand_rootfs() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
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
|
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
|
whiptail --msgbox "$ROOT_PART is not the last partition. Don't know how to expand" 20 60 2
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 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 "^${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
|
[ "$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 "$ROOT_DEV" <<EOF
|
||||||
p
|
p
|
||||||
d
|
d
|
||||||
$PART_NUM
|
$PART_NUM
|
||||||
@ -202,7 +196,7 @@ cat <<EOF > /etc/init.d/resize2fs_once &&
|
|||||||
case "\$1" in
|
case "\$1" in
|
||||||
start)
|
start)
|
||||||
log_daemon_msg "Starting resize2fs_once" &&
|
log_daemon_msg "Starting resize2fs_once" &&
|
||||||
resize2fs /dev/$ROOT_PART &&
|
resize2fs "$ROOT_PART" &&
|
||||||
update-rc.d resize2fs_once remove &&
|
update-rc.d resize2fs_once remove &&
|
||||||
rm /etc/init.d/resize2fs_once &&
|
rm /etc/init.d/resize2fs_once &&
|
||||||
log_end_msg \$?
|
log_end_msg \$?
|
||||||
|
@ -22,7 +22,7 @@ check_commands () {
|
|||||||
sleep 5
|
sleep 5
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
for COMMAND in grep cut sed parted fdisk findmnt partprobe; do
|
for COMMAND in grep cut sed parted fdisk findmnt; do
|
||||||
if ! command -v $COMMAND > /dev/null; then
|
if ! command -v $COMMAND > /dev/null; then
|
||||||
FAIL_REASON="$COMMAND not found"
|
FAIL_REASON="$COMMAND not found"
|
||||||
return 1
|
return 1
|
||||||
@ -78,18 +78,21 @@ fix_partuuid() {
|
|||||||
mount -o remount,rw "$ROOT_PART_DEV"
|
mount -o remount,rw "$ROOT_PART_DEV"
|
||||||
mount -o remount,rw "$BOOT_PART_DEV"
|
mount -o remount,rw "$BOOT_PART_DEV"
|
||||||
DISKID="$(tr -dc 'a-f0-9' < /dev/hwrng | dd bs=1 count=8 2>/dev/null)"
|
DISKID="$(tr -dc 'a-f0-9' < /dev/hwrng | dd bs=1 count=8 2>/dev/null)"
|
||||||
fdisk "$ROOT_DEV" <<EOF
|
fdisk "$ROOT_DEV" > /dev/null <<EOF
|
||||||
x
|
x
|
||||||
i
|
i
|
||||||
0x$DISKID
|
0x$DISKID
|
||||||
r
|
r
|
||||||
w
|
w
|
||||||
EOF
|
EOF
|
||||||
sed -i "s/${OLD_DISKID}/${DISKID}/g" /etc/fstab
|
if [ "$?" -eq 0 ]; then
|
||||||
sed -i "s/${OLD_DISKID}/${DISKID}/" /boot/cmdline.txt
|
sed -i "s/${OLD_DISKID}/${DISKID}/g" /etc/fstab
|
||||||
|
sed -i "s/${OLD_DISKID}/${DISKID}/" /boot/cmdline.txt
|
||||||
|
sync
|
||||||
|
fi
|
||||||
|
|
||||||
mount -o remount,ro "$ROOT_PART_DEV"
|
mount -o remount,ro "$ROOT_PART_DEV"
|
||||||
mount -o remount,ro "$BOOT_PART_DEV"
|
mount -o remount,ro "$BOOT_PART_DEV"
|
||||||
sync
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_variables () {
|
check_variables () {
|
||||||
|
Loading…
Reference in New Issue
Block a user