Advertisement
opexxx

mkcard.sh

Aug 8th, 2013
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.58 KB | None | 0 0
  1. #! /bin/sh
  2. # mkcard.sh v0.5
  3. # (c) Copyright 2009 Graeme Gregory <dp@xora.org.uk>
  4. # Licensed under terms of GPLv2
  5. #
  6. # Parts of the procudure base on the work of Denys Dmytriyenko
  7. # http://wiki.omap.com/index.php/MMC_Boot_Format
  8.  
  9. export LC_ALL=C
  10.  
  11. if [ $# -ne 1 ]; then
  12.     echo "Usage: $0 <drive>"
  13.     exit 1;
  14. fi
  15.  
  16. DRIVE=$1
  17.  
  18. dd if=/dev/zero of=$DRIVE bs=1024 count=1024
  19.  
  20. SIZE=`fdisk -l $DRIVE | grep Disk | grep bytes | awk '{print $5}'`
  21.  
  22. echo DISK SIZE - $SIZE bytes
  23.  
  24. CYLINDERS=`echo $SIZE/255/63/512 | bc`
  25.  
  26. echo CYLINDERS - $CYLINDERS
  27.  
  28. {
  29. echo ,9,0x0C,*
  30. echo ,,,-
  31. } | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE
  32.  
  33. sleep 1
  34.  
  35.  
  36. if [ -x `which kpartx` ]; then
  37.     kpartx -a ${DRIVE}
  38. fi
  39.  
  40. # handle various device names.
  41. # note something like fdisk -l /dev/loop0 | egrep -E '^/dev' | cut -d' ' -f1
  42. # won't work due to https://bugzilla.redhat.com/show_bug.cgi?id=649572
  43.  
  44. PARTITION1=${DRIVE}1
  45. if [ ! -b ${PARTITION1} ]; then
  46.     PARTITION1=${DRIVE}p1
  47. fi
  48.  
  49. DRIVE_NAME=`basename $DRIVE`
  50. DEV_DIR=`dirname $DRIVE`
  51.  
  52. if [ ! -b ${PARTITION1} ]; then
  53.     PARTITION1=$DEV_DIR/mapper/${DRIVE_NAME}p1
  54. fi
  55.  
  56. PARTITION2=${DRIVE}2
  57. if [ ! -b ${PARTITION2} ]; then
  58.     PARTITION2=${DRIVE}p2
  59. fi
  60. if [ ! -b ${PARTITION2} ]; then
  61.     PARTITION2=$DEV_DIR/mapper/${DRIVE_NAME}p2
  62. fi
  63.  
  64.  
  65. # now make partitions.
  66. if [ -b ${PARTITION1} ]; then
  67.     umount ${PARTITION1}
  68.     mkfs.vfat -F 32 -n "boot" ${PARTITION1}
  69. else
  70.     echo "Cant find boot partition in /dev"
  71. fi
  72.  
  73. if [ -b ${PARITION2} ]; then
  74.     umount ${PARTITION2}
  75.     mke2fs -j -L "Angstrom" ${PARTITION2}
  76. else
  77.     echo "Cant find rootfs partition in /dev"
  78. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement