Skip to content

Instantly share code, notes, and snippets.

@Aaronontheweb
Last active June 12, 2024 16:23
Show Gist options
  • Save Aaronontheweb/509726cff46f213f69332625fee18a70 to your computer and use it in GitHub Desktop.
Save Aaronontheweb/509726cff46f213f69332625fee18a70 to your computer and use it in GitHub Desktop.
Raspberry PI External SSD Scripts
#!/bin/bash
# create the docker data drive
mkdir /mnt/docker-base
# allow the root service account, which docker runs as, to own this directory and have write permissions
chown -R root:root /mnt/docker-base
chmod 701 /mnt/docker-base
# create a `daemon.json` file for the docker runtime
touch /etc/docker/daemon.json
# Define the JSON data
json_data='{
"data-root": "/mnt/docker-base"
}'
# Define the target file
target_file="/etc/docker/daemon.json"
# Create the target file and write the JSON data to it
echo "$json_data" | sudo tee "$target_file" > /dev/null
# Restart Docker
service docker restart
#!/bin/bash
# mirror the containerd storage paths, assuming these don't exist already
mkdir /mnt/var
mkdir /mnt/var/lib
mkdir /mnt/var/lib/containerd
mkdir /mnt/run
mkdir /mnt/run/containerd
# next, we have to configure microk8s to use these new directories instead of the default ones
# Define the configuration file path
CONFIG_FILE="/var/snap/microk8s/current/args/containerd"
# Backup the original configuration file
cp "$CONFIG_FILE" "${CONFIG_FILE}.bak"
# Replace the root and state paths using sed
sed -i 's|--root ${SNAP_COMMON}/var/lib/containerd|--root /mnt/var/lib/containerd|' "$CONFIG_FILE"
sed -i 's|--state ${SNAP_COMMON}/run/containerd|--state /mnt/run/containerd|' "$CONFIG_FILE"
# Confirm the changes
echo "Configuration file updated. Changes:"
diff "${CONFIG_FILE}.bak" "$CONFIG_FILE"
#!/bin/bash
# Backup your data before running this script!
# Unmount the partitions
umount /dev/sda1
umount /dev/sda2
# Use parted to re-create the partition with proper alignment
parted /dev/sda --script mklabel gpt
parted /dev/sda --script mkpart primary ext4 0% 100%
parted /dev/sda --script align-check optimal 1
# Format the new partition as EXT4
mkfs.ext4 /dev/sda1
# Mount the new partition
mount /dev/sda1 /mnt
# Optionally, update /etc/fstab
echo "/dev/sda1 /mnt ext4 defaults 0 2" >> /etc/fstab
# Set write permissions on the new mount
chmod 775 /mnt
@Aaronontheweb
Copy link
Author

Important

umount /dev/sda1 and umount /dev/sda2 are necessary because the Crucial SSDs we use ship with two NTFS partitions out of the box. This allows me to condense both of them into a single ext4 partition. Please check what the status of your drives looks like using sudo fdisk -l before executing these scripts and BACK UP ANY DATA YOU HAVE on these drives before running this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment