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

From CDOT Wiki
Jump to: navigation, search
(Created page with '== Pidora 2014 Reformating Boot Partition Script == #!/bin/bash # # Script to take an SD card image created by Livemedia-Creator (such as for a # Raspberry Pi) with a ext4 boot …')
 
(Fixed boot label)
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Pidora 2014 Reformating Boot Partition Script ==
+
<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 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 15: Line 14:
 
# 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
kpartx -av "$1"
+
    echo "Root privileges are required for running $0."
 +
    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 /media/temp
+
mkdir -p "$MY_DIR"/tmp/boot/
mkdir /tmp/boot
 
  
## mount boot partition
+
# mount boot partition
mount -o rw /dev/mapper/loop0p1 /media/temp/
+
mount -o rw /dev/mapper/$loopdev "$MY_DIR"/temp/
  
## copy boot data to temp dir
+
cp -r "$MY_DIR"/temp/* "$MY_DIR"/tmp/boot/
cp -r /media/temp/* /tmp/boot
 
  
#rename kernel.img work around for boot  
+
# Rename kernel.img workaround for boot
cp /tmp/boot/kernel-3.* /tmp/boot/kernel.img
+
cp "$MY_DIR"/tmp/boot/kernel-3.* "$MY_DIR"/tmp/boot/kernel.img
  
#unmount temp boot dir
+
umount "$MY_DIR"/temp/
umount /media/temp
 
  
#reformat boot parttions to vfat
+
# format boot parttion to vfat
mkfs -t vfat -n boot /dev/mapper/loop0p1
+
mkfs -t vfat -n BOOT /dev/mapper/$loopdev
sleep 3
 
  
 
# update partition fs info
 
# update partition fs info
Line 56: Line 59:
 
3
 
3
 
w
 
w
" | fdisk /dev/loop0
+
" | fdisk "$1"
 
 
sleep 3
 
## re-mount boot partition
 
mount -o rw /dev/mapper/loop0p1 /media/temp
 
  
#cp orginal boot data to new vfat partition
+
# re-mount boot partition
cp -r /tmp/boot/* /media/temp/
+
mount -o rw /dev/mapper/$loopdev "$MY_DIR"/temp/
sleep 10
 
# umount tmp boot again
 
umount /media/temp
 
  
sync
+
# copy original boot data to new vfat partition
 +
cp -r "$MY_DIR"/tmp/boot/* "$MY_DIR"/temp/
  
# remove partions and loopback devs
+
umount "$MY_DIR"/temp/
 
kpartx -dv "$1"
 
kpartx -dv "$1"
  
sleep 3
+
rmdir  "$MY_DIR"/temp/
 +
rm -rf "$MY_DIR"/tmp/
 +
</pre>
  
# cleanup
+
Source: https://github.com/Markieta/raspberrypi-reformat
dmsetup remove loop0p3
 
sleep 2
 
rm -rf /media/temp
 
rm -rf /tmp/boot
 

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/

Source: https://github.com/Markieta/raspberrypi-reformat