Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Tune the root filesystem.
#!/bin/bash -e
# Goal:
# Tune the root filesystem.
# Notes:
# Not needed if building the RAID system.
# 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 $ROOT_PARTITION exist?"
[[ -e "$ROOT_PARTITION" ]]
echo "OK"
echo "Is card $SD_CARD not mounted?"
if df | grep --quiet "$SD_CARD"
echo "Yes: umount all partitions that belong to $SD_CARD."
df --exclude-type=tmpfs | awk --assign=PATTERN="$SD_CARD" '$1 ~ PATTERN {system("umount " $1)}'
# --exclude-type to shorten list
# --assign to pass SD_CARD from bash into awk script
# $1 ~ PATTERN act only on lines that contain SD_CARD, i.e. use awk to simulate grep
echo "OK"
echo "Delete journal on partition $ROOT_PARTITION."
tune2fs -L "root" -O ^has_journal "$ROOT_PARTITION"
e2fsck -f -y "$ROOT_PARTITION"
echo "OK"
echo "Update fstab."
# mount the ROOT_PARTITION to a known place
mkdir --parents "$ROOT_MOUNT"
# the extra spece in the pattern below is very relevant!
sed --in-place 's/noatime /noatime,nodiratime /' "$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.