Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch/rocko3 #75

Closed
wants to merge 22 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 54 additions & 10 deletions meta-iot2000-example/recipes-example/iot2000setup/files/expandfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,74 @@

set -eu

PART_NUMBER=3
THIS_SCRIPT="$(basename $0)"

log () {
echo ${THIS_SCRIPT}: $1 > /dev/kmsg
}

disable () {
log "Deactivating this automatic resizer"
update-rc.d -f expandfs.sh remove
}

case $(mount | grep "on / ") in
/dev/mmcblk0*)
ROOT_DEVICE="/dev/mmcblk0"
ROOT_PARTITION="/dev/mmcblk0p$PART_NUMBER"
EXPAND_PARTITION="/dev/mmcblk0p"
;;
/dev/sda*)
ROOT_DEVICE="/dev/sda"
ROOT_PARTITION="/dev/sda$PART_NUMBER"
EXPAND_PARTITION="/dev/sda"
;;
*)
echo "Cannot determine boot device."
log "Cannot determine root device."
disable
exit 1
;;
esac

START_BLOCK=$(parted $ROOT_DEVICE -ms unit s p | grep "^$PART_NUMBER" | cut -f 2 -d: | sed "s/s$//")
log "Fixing backup GPT position"
parted ${ROOT_DEVICE} print Fix
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left over debug print? But "Fix" is not a known parameter to parted.


parted -ms $ROOT_DEVICE rm $PART_NUMBER
LAST_PART="$(parted ${ROOT_DEVICE} -ms unit s p | tail -n 1 | cut -d ':' -f 1)"
if [ "x${LAST_PART}" == "x" ]
then
log "Cannot find last partition of root device."
disable
exit 1
fi

parted -ms $ROOT_DEVICE unit s -- mkpart primary ext3 $START_BLOCK -1
EXPAND_PARTITION="${EXPAND_PARTITION}${LAST_PART}"

MAXSIZE="$(parted ${ROOT_DEVICE} -s unit MB print list | grep Disk | cut -d' ' -f 3 | tr -d MB)"
if [ "x${MAXSIZE}" == "x" ]
then
log "Error obtaining maximum partition size"
disable
exit 1
fi

partprobe $ROOT_DEVICE
resize2fs $ROOT_PARTITION
log "Resizing ${EXPAND_PARTITION} to maximum"
parted ${ROOT_DEVICE} -s resizepart ${LAST_PART} ${MAXSIZE}M
res=$?
if [ $res -ne 0 ]
then
log "Error resizing partition"
disable
exit 1
fi

partprobe ${ROOT_DEVICE}

log "Resizing file system on ${EXPAND_PARTITION}"
resize2fs ${EXPAND_PARTITION}
Copy link
Collaborator

@jan-kiszka jan-kiszka Mar 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For whatever reason, this just refused to work:

rc: Resizing /dev/mmcblk0p7 to maximum
rc: Resizing file system on /dev/mmcblk0p7
resize2fs 1.43.5 (04-Aug-2017)
Please run 'e2fsck -f /dev/mmcblk0p7' first.

Adding that check here seems reasonable.

res=$?
if [ $res -ne 0 ]
then
log "Error resizing file system"
disable
exit 1
fi

update-rc.d -f expandfs.sh remove
disable
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, not a regression: parted also gets stuck on lacking entropy. Possibly because it pulls in some uuid lib which first of all wants to initialized some randomness.

I'm checking if we can avoid that. Alternatively, we could send the whole thing into background so that the first boot is not delayed. At least we need to think about the watchdog in case we no longer start it prematurely during early boot.