Some initial partitioning
This commit is contained in:
@@ -2,16 +2,19 @@
|
||||
set -eu
|
||||
|
||||
MNT=/mnt
|
||||
ROOT_MNT=/mnt-root
|
||||
CONFIG_MNT=/mnt-config
|
||||
USB_DEV=/dev/sda
|
||||
EMMC_DEV=/dev/mmcblk0
|
||||
EMMC_ROOT_PART=/dev/mmcblk0p1
|
||||
CONFIG_DIR=/opt/monok8s/config
|
||||
|
||||
EMMC_CONFIG_PART=/dev/mmcblk0p1
|
||||
EMMC_ROOTFS_A_PART=/dev/mmcblk0p2
|
||||
EMMC_ROOTFS_B_PART=/dev/mmcblk0p3
|
||||
EMMC_DATA_PART=/dev/mmcblk0p4
|
||||
|
||||
DEFAULT_GLOB="${MNT}/${BUILD_TAG}_RELEASE_IMAGE"
|
||||
|
||||
cleanup() {
|
||||
umount "$ROOT_MNT" 2>/dev/null || true
|
||||
umount "$CONFIG_MNT" 2>/dev/null || true
|
||||
umount "$MNT" 2>/dev/null || true
|
||||
}
|
||||
|
||||
@@ -61,7 +64,7 @@ wait_for_partition_ready() {
|
||||
return 1
|
||||
}
|
||||
|
||||
mkdir -p "$MNT" "$ROOT_MNT"
|
||||
mkdir -p "$MNT" "$CONFIG_MNT"
|
||||
trap cleanup EXIT
|
||||
|
||||
log "Mounting USB..."
|
||||
@@ -108,7 +111,6 @@ echo
|
||||
|
||||
printf "Type 'YES' to continue: "
|
||||
read -r CONFIRM
|
||||
|
||||
[ "$CONFIRM" = "YES" ] || die "Aborted."
|
||||
|
||||
log "Flashing image to eMMC..."
|
||||
@@ -120,40 +122,45 @@ sync
|
||||
reread_partitions
|
||||
|
||||
log "Waiting for partition nodes..."
|
||||
if ! wait_for_partition_ready "$EMMC_ROOT_PART" 15; then
|
||||
if ! wait_for_partition_ready "$EMMC_CONFIG_PART" 15; then
|
||||
warn "Initial partition scan did not settle; retrying after another reread..."
|
||||
reread_partitions
|
||||
sleep 2
|
||||
wait_for_partition_ready "$EMMC_ROOT_PART" 15 || die "root partition not ready: $EMMC_ROOT_PART"
|
||||
wait_for_partition_ready "$EMMC_CONFIG_PART" 15 || die "config partition not ready: $EMMC_CONFIG_PART"
|
||||
fi
|
||||
|
||||
# These are useful sanity checks, but not strictly required for copying config.
|
||||
wait_for_partition_ready "$EMMC_ROOTFS_A_PART" 5 || warn "rootfsA partition not ready yet: $EMMC_ROOTFS_A_PART"
|
||||
wait_for_partition_ready "$EMMC_ROOTFS_B_PART" 5 || warn "rootfsB partition not ready yet: $EMMC_ROOTFS_B_PART"
|
||||
wait_for_partition_ready "$EMMC_DATA_PART" 5 || warn "data partition not ready yet: $EMMC_DATA_PART"
|
||||
|
||||
log "Partition sizes:"
|
||||
echo " $(basename "$EMMC_DEV"): $(get_sectors "$EMMC_DEV") sectors"
|
||||
echo " $(basename "$EMMC_ROOT_PART"): $(get_sectors "$EMMC_ROOT_PART") sectors"
|
||||
echo " $(basename "$EMMC_DEV"): $(get_sectors "$EMMC_DEV") sectors"
|
||||
echo " $(basename "$EMMC_CONFIG_PART"): $(get_sectors "$EMMC_CONFIG_PART") sectors"
|
||||
echo " $(basename "$EMMC_ROOTFS_A_PART"): $(get_sectors "$EMMC_ROOTFS_A_PART") sectors"
|
||||
echo " $(basename "$EMMC_ROOTFS_B_PART"): $(get_sectors "$EMMC_ROOTFS_B_PART") sectors"
|
||||
echo " $(basename "$EMMC_DATA_PART"): $(get_sectors "$EMMC_DATA_PART") sectors"
|
||||
|
||||
if [ -n "$ENV_FILES" ]; then
|
||||
log "Mounting flashed root partition..."
|
||||
mount "$EMMC_ROOT_PART" "$ROOT_MNT" || {
|
||||
log "Mounting flashed config partition..."
|
||||
mount -t vfat "$EMMC_CONFIG_PART" "$CONFIG_MNT" || {
|
||||
warn "Mount failed; retrying once after partition reread..."
|
||||
reread_partitions
|
||||
sleep 2
|
||||
mount "$EMMC_ROOT_PART" "$ROOT_MNT"
|
||||
mount -t vfat "$EMMC_CONFIG_PART" "$CONFIG_MNT"
|
||||
}
|
||||
|
||||
log "Creating config dir: $CONFIG_DIR"
|
||||
mkdir -p "$ROOT_MNT$CONFIG_DIR"
|
||||
|
||||
log "Copying env files..."
|
||||
log "Copying env files to config partition..."
|
||||
for f in $ENV_FILES; do
|
||||
base="$(basename "$f")"
|
||||
cp "$f" "$ROOT_MNT$CONFIG_DIR/$base"
|
||||
cp "$f" "$CONFIG_MNT/$base"
|
||||
echo " copied: $base"
|
||||
done
|
||||
|
||||
log "Syncing copied config..."
|
||||
sync
|
||||
|
||||
umount "$ROOT_MNT"
|
||||
umount "$CONFIG_MNT"
|
||||
fi
|
||||
|
||||
log "Done."
|
||||
|
||||
Reference in New Issue
Block a user