Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2011
988
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.61 KB | None | 0 0
  1. # Generates the sdcard partitions for Raspberry Pi sdcard
  2. # Thomas Bohm <thomas.bohm@cs.upt.ro>
  3.  
  4. # Based on scripts by:
  5. # Graeme Gregory <dp@xora.org.uk>
  6. # Edward Lin <linuxfae@technexion.com>
  7. # This script is GPLv3 licensed!
  8.  
  9. #!/bin/bash
  10.  
  11. SPREF="/sys/class/block"
  12. RBP_DIR="Raspberry Pi"
  13. GPU_DIR="GPU partition"
  14. DRIVE=""
  15.  
  16. devicearray[0]=""
  17.  
  18. if [ "`whoami`" != "root" ]; then
  19.         echo "Must be root"
  20.         exit 1
  21. fi
  22.  
  23. clear
  24. echo "List of removable devices smaller than 10GB : "
  25. echo
  26. devindex=1
  27. for ii in $SPREF/sd?/removable ; do
  28.     if [ `cat $ii` == 1 ]; then
  29.         devfound=`echo $ii | awk -F "/" {'print $5 '}`
  30.         dev_model=`cat $SPREF/$devfound/device/model`
  31.         dev_vendor=`cat $SPREF/$devfound/device/vendor`
  32.         dev_size=$((`cat $SPREF/$devfound/size`/1024/2))
  33.         if [ "$dev_size" -gt "10000" ]; then
  34.             continue;
  35.         fi
  36.         echo "[$devindex]: $dev_vendor -- $dev_model ( $devfound ) size is $dev_size MBytes. "
  37.         devicearray[$devindex]=$devfound
  38.         devindex=$(($devindex+1))
  39.     fi
  40. done
  41. if [ "$devindex" == "1" ] ; then
  42.     echo
  43.     echo "No removable devices found !"
  44.     exit 1
  45. fi
  46.  
  47. echo
  48. while [ "$DRIVE" == "" ]; do
  49.     echo -n "Input device number: "
  50.     read choice
  51.     if [ "${devicearray[${choice}]}" == "" ]; then
  52.         echo
  53.         echo "Invalid number ! "
  54.         echo
  55.     else
  56.         DRIVE=${devicearray[${choice}]}
  57.     fi
  58. done
  59.  
  60. echo
  61. echo "Are you 100 % sure you want to FORMAT [ $DRIVE ] ?. All data will be lost."
  62. echo -n "Enter YES in uppercase to continue: "
  63. read sure
  64. echo
  65.  
  66. if [ "$sure" != "YES" ]; then
  67.     exit 1
  68. fi
  69.  
  70. echo
  71. echo "Umounting all partitions of $DRIVE."
  72.  
  73. for ii in $SPREF/$DRIVE? ; do
  74.     umount /dev/`echo $ii | awk -F "/" {'print $5 '}` 2>/dev/null
  75. done
  76.  
  77. echo "Partitioning"
  78.  
  79. #clear the beginning of the card
  80. dd if=/dev/zero of=/dev/$DRIVE bs=1024 count=1024
  81.  
  82. #install a blank mbr (blank from the partitions point of view)
  83. # dd if=blank_mbr.img of=/dev/$DRIVE bs=512 count=1
  84.  
  85.  
  86. SIZE=`fdisk -l /dev/$DRIVE | grep Disk | awk '{print $5}'`
  87.  
  88. echo DISK SIZE – $SIZE bytes
  89.  
  90. CYLINDERS=`echo $SIZE/255/63/512 | bc`
  91.  
  92. echo CYLINDERS – $CYLINDERS
  93.  
  94. {
  95. #create a new partition table
  96. #ext partition for linux, bootable
  97. #   start, size, type ( default 0x83 - linux , 0x0C FAT32 ), bootable ( * yes, - no )
  98. echo ,19,0x83,*
  99. #FAT 32 partition filling rest of card, maybe for /tmp ?
  100. echo ,,0x0C,-
  101. } | sfdisk -D -H 122 -S 62 -C $CYLINDERS /dev/$DRIVE
  102. ##############################################
  103.  
  104. umount /dev/${DRIVE}1
  105. umount /dev/${DRIVE}2
  106.  
  107. echo "Formatting partition as EXT"
  108. mke2fs -F -L "$MNT_DIR" /dev/${DRIVE}1
  109. mkfs.vfat -F 32 -n "$GPU_DIR" /dev/${DRIVE}2
  110. sync
  111.  
  112. echo "Done. Please remove the card."
  113.  
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement