Last active
April 19, 2022 20:08
-
-
Save julianxhokaxhiu/0d73be0de6a5024258c060ee2c98c981 to your computer and use it in GitHub Desktop.
Easy bash script to install ArchLinuxARM for RPi3 on an SD Card
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Pre-requisite: move this script next to the .tar.gz image file | |
# you can download at http://os.archlinuxarm.org/os/ArchLinuxARM-rpi-3-latest.tar.gz | |
# | |
# Usage: ./prepare_sdcard.sh /dev/sdb | |
# | |
##################################### | |
DRIVE_PATH=$1 | |
DRIVE_BOOT=`${DRIVE_PATH}1` | |
DRIVE_ROOT=`${DRIVE_PATH}2` | |
echo ">> Clearing SDCard from previous state..." | |
wipefs -a $DRIVE_PATH &>/dev/null | |
# to create the partitions programatically (rather than manually) | |
# we're going to simulate the manual input to fdisk | |
# The sed script strips off all the comments so that we can | |
# document what we're doing in-line with the actual commands | |
# Note that a blank line (commented as "default" will send a empty | |
# line terminated with a newline to take the fdisk default. | |
echo ">> Preparing partitions..." | |
sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | fdisk $DRIVE_PATH &>/dev/null | |
o # clear the in memory partition table | |
n # new partition | |
p # primary partition | |
1 # partition number 1 | |
# default - start at beginning of disk | |
+100M # 100 MB boot parttion | |
t # change type | |
c # to FAT | |
n # new partition | |
p # primary partition | |
2 # partion number 2 | |
# default, start immediately after preceding partition | |
# default, extend partition to end of disk | |
w # write the partition table | |
q # and we're done | |
EOF | |
# Format FAT partition | |
echo ">> Formatting 100MB partition to vfat..." | |
mkfs.vfat -F $DRIVE_BOOT &>/dev/null | |
# Format EXT4 partition | |
echo ">> Formatting the remaining partition to ext4..." | |
mkfs.ext4 -F $DRIVE_ROOT &>/dev/null | |
# Prepare required folders | |
echo ">> Preparing mount folders..." | |
mkdir -p sd-boot | |
mkdir -p sd-root | |
# Mount partitions | |
echo ">> Mounting partitions..." | |
mount $DRIVE_BOOT sd-boot &>/dev/null | |
mount $DRIVE_ROOT sd-root &>/dev/null | |
# Cleaning | |
echo ">> Removing previous files inside partitions..." | |
rm -Rf sd-boot/* | |
rm -Rf sd-root/* | |
# Extract files | |
echo ">> Extracting root filesystem to your SDCard..." | |
bsdtar -xpf ArchLinuxARM-rpi-3-latest.tar.gz -C sd-root &>/dev/null | |
# Flush | |
echo ">> Flushing..." | |
sync | |
# Move boot files to the relative partition | |
echo ">> Moving boot files to the relative boot partition..." | |
mv sd-root/boot/* sd-boot | |
# Unmount partitions | |
echo ">> Unmounting partitions..." | |
umount sd-boot sd-root &>/dev/null | |
# Cleaning | |
echo ">> Cleaning..." | |
rm -R sd-boot sd-root | |
# Done! | |
echo ">> Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment