Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Prepare empty space on the card to be used as /app partition.
#!/bin/bash -e
# Goal:
# Prepare empty space on the card to be used as /app partition.
# Notes:
# After this script, first time the Raspberry is powered on, you will see an error:
# "Could not expand filesystem, please try raspi-config or rc_gui."
# This error can be safely ignored, or it can be turned off using the sed command from line 132 in
# file: $ROOT_PARTITION/usr/lib/raspi-config/
# Prerequisites:
# 1. Run 01-write_image_to_card.
# 2. Set the following variables:
echo "Are we superuser?"
[[ $EUID -eq 0 ]]
echo "OK"
echo "Is card $SD_CARD plugged in?"
[[ -e "$SD_CARD" ]]
echo "OK"
echo "Does partition $APP_PARTITION not exist?"
# partprobe is not 100% reliable;
partprobe $SD_CARD
[[ ! -e "$APP_PARTITION" ]]
echo "OK"
echo "Create new partition $APP_PARTITION."
# Find the start and end offsets. There are 2 blocks of "Free Space" and we only care about the last one.
OFFSETS=$(parted --script "$SD_CARD" print free | awk '/Free Space/ {print $1 " " $2}' | tail -1)
# do not quote OFFSETS - it holds two parameters
parted --script "$SD_CARD" mkpart primary $OFFSETS
echo "OK"
echo "Format partition $APP_PARTITION."
mkfs.ext2 -L "app" "$APP_PARTITION"
echo "OK"
echo "Update fstab."
if df | grep --quiet "$ROOT_PARTITION"
# mount the ROOT_PARTITION to a known place
mkdir --parents "$ROOT_MOUNT"
printf "$APP_PARTITION\t/app\text2\tdefaults,noatime,nodiratime\t0\t2\n" >> "$ROOT_MOUNT/etc/fstab"
umount "$ROOT_MOUNT"
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.