Difference between revisions of "Pidora-2014-Reformating-Boot-Script"
(→Pidora 2014 Reformating Boot Partition Script) |
(Fixed boot label) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | |||
− | |||
<pre> | <pre> | ||
− | + | #!/usr/bin/env bash | |
− | #!/bin/bash | ||
# | # | ||
# Script to take an SD card image created by Livemedia-Creator (such as for a | # Script to take an SD card image created by Livemedia-Creator (such as for a | ||
− | # Raspberry Pi) with | + | # Raspberry Pi) with an ext4 boot partition and reformat it to vfat. |
# | # | ||
# To use this script, provide the image name as | # To use this script, provide the image name as | ||
Line 17: | Line 14: | ||
# kpartx (kpartx) | # kpartx (kpartx) | ||
# | # | ||
− | # Version 1. | + | # Version 1.1 2014-08-27 |
# | # | ||
# Authors: | # Authors: | ||
− | # Andrew Greene, Seneca College 2013-04-05 | + | # Andrew Greene, Seneca College 2013-04-05 |
+ | # Christopher Markieta, Seneca College 2014-08-27 | ||
# | # | ||
+ | set -e | ||
+ | MY_DIR=$(dirname $0) | ||
− | + | if [ $(id -u) -ne 0 ]; then | |
− | + | echo "Root privileges are required for running $0." | |
− | echo | + | exit 1 |
+ | elif [ -z $1 ]; then | ||
+ | echo "Usage: $0 [image]" | ||
+ | exit 1 | ||
+ | fi | ||
− | + | loopdev=$(kpartx -avs "$1" | awk 'NR==1 {print $3}') | |
− | + | echo "$loopdev" | |
− | + | mkdir "$MY_DIR"/temp/ | |
− | mkdir | + | mkdir -p "$MY_DIR"/tmp/boot/ |
− | mkdir -p | ||
+ | # mount boot partition | ||
+ | mount -o rw /dev/mapper/$loopdev "$MY_DIR"/temp/ | ||
− | + | cp -r "$MY_DIR"/temp/* "$MY_DIR"/tmp/boot/ | |
− | |||
− | # | + | # Rename kernel.img workaround for boot |
− | cp - | + | cp "$MY_DIR"/tmp/boot/kernel-3.* "$MY_DIR"/tmp/boot/kernel.img |
− | + | umount "$MY_DIR"/temp/ | |
− | |||
− | # | + | # format boot parttion to vfat |
− | + | mkfs -t vfat -n BOOT /dev/mapper/$loopdev | |
− | |||
− | |||
− | mkfs -t vfat -n | ||
− | |||
# update partition fs info | # update partition fs info | ||
Line 60: | Line 59: | ||
3 | 3 | ||
w | w | ||
− | " | fdisk | + | " | fdisk "$1" |
− | + | # re-mount boot partition | |
− | + | mount -o rw /dev/mapper/$loopdev "$MY_DIR"/temp/ | |
− | mount -o rw /dev/mapper/$loopdev | ||
− | # | + | # copy original boot data to new vfat partition |
− | cp -r | + | cp -r "$MY_DIR"/tmp/boot/* "$MY_DIR"/temp/ |
− | |||
− | |||
− | |||
− | + | umount "$MY_DIR"/temp/ | |
− | |||
− | |||
kpartx -dv "$1" | kpartx -dv "$1" | ||
− | + | rmdir "$MY_DIR"/temp/ | |
− | + | rm -rf "$MY_DIR"/tmp/ | |
− | + | </pre> | |
− | |||
− | |||
− | + | Source: https://github.com/Markieta/raspberrypi-reformat | |
− |
Latest revision as of 15:16, 2 September 2014
#!/usr/bin/env bash # # Script to take an SD card image created by Livemedia-Creator (such as for a # Raspberry Pi) with an ext4 boot partition and reformat it to vfat. # # To use this script, provide the image name as # the first argument. # Example "./revfat image-name.img" # # Requirements (Fedora 17 package): # bash (bash) # fdisk (util-linux) # kpartx (kpartx) # # Version 1.1 2014-08-27 # # Authors: # Andrew Greene, Seneca College 2013-04-05 # Christopher Markieta, Seneca College 2014-08-27 # set -e MY_DIR=$(dirname $0) if [ $(id -u) -ne 0 ]; then echo "Root privileges are required for running $0." exit 1 elif [ -z $1 ]; then echo "Usage: $0 [image]" exit 1 fi loopdev=$(kpartx -avs "$1" | awk 'NR==1 {print $3}') echo "$loopdev" mkdir "$MY_DIR"/temp/ mkdir -p "$MY_DIR"/tmp/boot/ # mount boot partition mount -o rw /dev/mapper/$loopdev "$MY_DIR"/temp/ cp -r "$MY_DIR"/temp/* "$MY_DIR"/tmp/boot/ # Rename kernel.img workaround for boot cp "$MY_DIR"/tmp/boot/kernel-3.* "$MY_DIR"/tmp/boot/kernel.img umount "$MY_DIR"/temp/ # format boot parttion to vfat mkfs -t vfat -n BOOT /dev/mapper/$loopdev # update partition fs info echo "t 1 c d 3 w " | fdisk "$1" # re-mount boot partition mount -o rw /dev/mapper/$loopdev "$MY_DIR"/temp/ # copy original boot data to new vfat partition cp -r "$MY_DIR"/tmp/boot/* "$MY_DIR"/temp/ umount "$MY_DIR"/temp/ kpartx -dv "$1" rmdir "$MY_DIR"/temp/ rm -rf "$MY_DIR"/tmp/