Difference between revisions of "Pidora-2014-Reformating-Boot-Script"
(→Pidora 2014 Reformating Boot Partition Script) |
(→Pidora 2014 Reformating Boot Partition Script) |
||
Line 2: | Line 2: | ||
<pre> | <pre> | ||
+ | |||
#!/bin/bash | #!/bin/bash | ||
# | # | ||
Line 25: | Line 26: | ||
# partition | # partition | ||
− | kpartx -av "$1" | + | loopdev=$(kpartx -av "$1" | awk 'NR==1 {print $3}') |
+ | echo -e "$loopdev" | ||
# You | # You | ||
Line 31: | Line 33: | ||
#create temp dirs | #create temp dirs | ||
− | mkdir | + | mkdir ./temp |
− | mkdir /tmp/boot | + | mkdir -p ./tmp/boot |
+ | |||
## mount boot partition | ## mount boot partition | ||
− | mount -o rw /dev/mapper/ | + | mount -o rw /dev/mapper/$loopdev ./temp |
## copy boot data to temp dir | ## copy boot data to temp dir | ||
− | cp -r | + | cp -r ./temp/* ./tmp/boot |
#rename kernel.img work around for boot | #rename kernel.img work around for boot | ||
− | cp /tmp/boot/kernel-3.* /tmp/boot/kernel.img | + | cp ./tmp/boot/kernel-3.* ./tmp/boot/kernel.img |
#unmount temp boot dir | #unmount temp boot dir | ||
− | umount | + | umount ./temp |
#reformat boot parttions to vfat | #reformat boot parttions to vfat | ||
− | mkfs -t vfat -n boot /dev/mapper/ | + | mkfs -t vfat -n boot /dev/mapper/$loopdev |
sleep 3 | sleep 3 | ||
Line 57: | Line 60: | ||
3 | 3 | ||
w | w | ||
− | " | fdisk /dev/ | + | " | fdisk /dev/${loopdev::5} |
sleep 3 | sleep 3 | ||
## re-mount boot partition | ## re-mount boot partition | ||
− | mount -o rw /dev/mapper/ | + | mount -o rw /dev/mapper/$loopdev ./temp |
#cp orginal boot data to new vfat partition | #cp orginal boot data to new vfat partition | ||
− | cp -r /tmp/boot/* | + | cp -r ./tmp/boot/* ./temp |
sleep 10 | sleep 10 | ||
# umount tmp boot again | # umount tmp boot again | ||
− | umount | + | umount ./temp |
sync | sync | ||
Line 77: | Line 80: | ||
# cleanup | # cleanup | ||
− | dmsetup remove | + | dmsetup remove $loopdev |
sleep 2 | sleep 2 | ||
− | rm -rf | + | |
− | rm -rf /tmp | + | rm -rf ./temp |
− | </pre> | + | rm -rf ./tmp</pre> |
Revision as of 12:07, 14 August 2014
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 partition and reformat it 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.0 2013-04-05 # # Authors: # Andrew Greene, Seneca College 2013-04-05 # # partition loopdev=$(kpartx -av "$1" | awk 'NR==1 {print $3}') echo -e "$loopdev" # You sleep 3 #create temp dirs mkdir ./temp mkdir -p ./tmp/boot ## mount boot partition mount -o rw /dev/mapper/$loopdev ./temp ## copy boot data to temp dir cp -r ./temp/* ./tmp/boot #rename kernel.img work around for boot cp ./tmp/boot/kernel-3.* ./tmp/boot/kernel.img #unmount temp boot dir umount ./temp #reformat boot parttions to vfat mkfs -t vfat -n boot /dev/mapper/$loopdev sleep 3 # update partition fs info echo "t 1 c d 3 w " | fdisk /dev/${loopdev::5} sleep 3 ## re-mount boot partition mount -o rw /dev/mapper/$loopdev ./temp #cp orginal boot data to new vfat partition cp -r ./tmp/boot/* ./temp sleep 10 # umount tmp boot again umount ./temp sync # remove partions and loopback devs kpartx -dv "$1" sleep 3 # cleanup dmsetup remove $loopdev sleep 2 rm -rf ./temp rm -rf ./tmp