Created
May 10, 2015 07:07
-
-
Save Akkiesoft/af72826ae5e856acfd6f to your computer and use it in GitHub Desktop.
Raspberry PiのDD用イメージファイルをNOOBSで使えるようなtar.xzにするスクリプト。
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 | |
if [ $# -ne 1 ]; then | |
echo "USAGE: $0 <imagefile>" | |
exit 1 | |
fi | |
if [ ${EUID:-${UID}} != 0 ]; then | |
echo 'You must run as root user.' | |
exit 1 | |
fi | |
IMGNAME=$1 | |
WORK=`pwd` | |
LOOPPATH=`losetup -f` | |
LOOPID=`echo ${LOOPPATH} | awk -F/ '{print $3}'` | |
IMGFILE=`echo ${IMGNAME} | awk -F. '{print $1}'` | |
echo Mounting image file | |
losetup -f ${IMGNAME} | |
kpartx -a ${LOOPPATH} | |
mount /dev/mapper/${LOOPID}p2 /mnt | |
mount /dev/mapper/${LOOPID}p1 /mnt/boot | |
echo Creating archive [root partition] | |
cd /mnt | |
tar -cpf ${WORK}/${IMGFILE}-root.tar * --exclude=proc/* --exclude=sys/* --exclude=dev/pts/* --exclude=boot/* | |
echo Creating archive [boot partition] | |
cd /mnt/boot | |
tar -cpf ${WORK}/${IMGFILE}-boot.tar . | |
cd ${WORK} | |
echo Unounting image file | |
umount /mnt/boot | |
umount /mnt | |
kpartx -d ${LOOPPATH} | |
losetup -d ${LOOPPATH} | |
echo Modifing partition information. | |
tar xf ${IMGFILE}-root.tar etc/fstab | |
sed -i -e 's/mmcblk0p1/mmcblk0p5/g' etc/fstab cmdline.txt | |
sed -i -e 's/mmcblk0p2/mmcblk0p6/g' etc/fstab cmdline.txt | |
tar uf ${IMGFILE}-root.tar etc/fstab | |
tar uf ${IMGFILE}-boot.tar ./cmdline.txt | |
ls -lh ${IMGFILE}-*.tar | |
xz -e -9 ${IMGFILE}-boot.tar | |
xz -e -9 ${IMGFILE}-root.tar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment