Difference between revisions of "Pidora-2014-Reformating-Boot-Script"

From CDOT Wiki
Jump to: navigation, search
(Pidora 2014 Reformating Boot Partition Script)
(Pidora 2014 Reformating Boot Partition Script)
Line 3: Line 3:
 
<pre>
 
<pre>
  
#!/bin/bash
+
#!/usr/bin/env 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 a ext4 boot partition and reformat it vfat.  
+
# 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 17:
 
# kpartx (kpartx)
 
# kpartx (kpartx)
 
#
 
#
# Version 1.0 2013-04-05
+
# 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)
  
# partition
+
if [ $(id -u) -ne 0 ]; then
loopdev=$(kpartx -av "$1" | awk  'NR==1 {print $3}')
+
    echo "Root privileges are required for running $0."
echo -e "$loopdev"
+
    exit 1
 +
elif [ -z $1 ]; then
 +
    echo "Usage: $0 [image]"
 +
    exit 1
 +
fi
  
# You
+
loopdev=$(kpartx -avs "$1" | awk 'NR==1 {print $3}')
sleep 3
+
echo "$loopdev"
  
#create temp dirs
+
mkdir   "$MY_DIR"/temp/
mkdir ./temp
+
mkdir -p "$MY_DIR"/tmp/boot/
mkdir -p ./tmp/boot
 
  
 +
# mount boot partition
 +
mount -o rw /dev/mapper/$loopdev "$MY_DIR"/temp/
  
## mount boot partition
+
cp -r "$MY_DIR"/temp/* "$MY_DIR"/tmp/boot/
mount -o rw /dev/mapper/$loopdev ./temp
 
  
## copy boot data to temp dir
+
# Rename kernel.img workaround for boot
cp -r ./temp/* ./tmp/boot
+
cp "$MY_DIR"/tmp/boot/kernel-3.* "$MY_DIR"/tmp/boot/kernel.img
  
#rename kernel.img work around for boot
+
umount "$MY_DIR"/temp/
cp ./tmp/boot/kernel-3.* ./tmp/boot/kernel.img
 
  
#unmount temp boot dir
+
# format boot parttion to vfat
umount ./temp
 
 
 
#reformat boot parttions to vfat
 
 
mkfs -t vfat -n boot /dev/mapper/$loopdev
 
mkfs -t vfat -n boot /dev/mapper/$loopdev
sleep 3
 
  
 
# update partition fs info
 
# update partition fs info
Line 60: Line 62:
 
3
 
3
 
w
 
w
" | fdisk /dev/${loopdev::5}
+
" | fdisk "$1"
  
sleep 3
+
# re-mount boot partition
## re-mount boot partition
+
mount -o rw /dev/mapper/$loopdev "$MY_DIR"/temp
mount -o rw /dev/mapper/$loopdev ./temp
 
  
#cp orginal boot data to new vfat partition
+
# copy original boot data to new vfat partition
cp -r ./tmp/boot/* ./temp
+
cp -r "$MY_DIR"/tmp/boot/* "$MY_DIR"/temp
sleep 10
 
# umount tmp boot again
 
umount ./temp
 
  
sync
+
umount "$MY_DIR"/temp
 
 
# remove partions and loopback devs
 
 
kpartx -dv "$1"
 
kpartx -dv "$1"
  
sleep 3
+
rmdir  "$MY_DIR"/temp/
 
+
rm -rf "$MY_DIR"/tmp/</pre>
# cleanup
 
dmsetup remove $loopdev
 
sleep 2
 
  
rm -rf ./temp
+
Source: https://github.com/Markieta/raspberrypi-reformat/blob/master/revfat
rm -rf ./tmp</pre>
 

Revision as of 13:29, 27 August 2014

Pidora 2014 Reformating Boot Partition Script


#!/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/

Source: https://github.com/Markieta/raspberrypi-reformat/blob/master/revfat