daily pastebin goal
92%
SHARE
TWEET

grow_partition.sh

osteth Apr 7th, 2016 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh -e
  2. #
  3. # Copyright (c) 2014 Robert Nelson <robertcnelson@gmail.com>
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy
  6. # of this software and associated documentation files (the "Software"), to deal
  7. # in the Software without restriction, including without limitation the rights
  8. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the Software is
  10. # furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. # THE SOFTWARE.
  22.  
  23. if ! id | grep -q root; then
  24.     echo "must be run as root"
  25.     exit
  26. fi
  27.  
  28. if [ ! -f /etc/ssh/ssh_host_ecdsa_key.pub ] ; then
  29.     echo "Please wait a few more seconds as ssh keys are still being generated..."
  30.     exit 1
  31. fi
  32.  
  33. unset root_drive
  34. root_drive="$(cat /proc/cmdline | sed 's/ /\n/g' | grep root=UUID= | awk -F 'root=' '{print $2}' || true)"
  35. if [ ! "x${root_drive}" = "x" ] ; then
  36.     root_drive="$(/sbin/findfs ${root_drive} || true)"
  37. else
  38.     root_drive="$(cat /proc/cmdline | sed 's/ /\n/g' | grep root= | awk -F 'root=' '{print $2}' || true)"
  39. fi
  40.  
  41. if [ ! "x${root_drive}" = "x" ] ; then
  42.     boot_drive="${root_drive%?}1"
  43. else
  44.     echo "Error: script halting, could detect drive..."
  45.     exit 1
  46. fi
  47.  
  48. single_partition () {
  49.     echo "${drive}p1" > /resizerootfs
  50.     conf_boot_startmb=${conf_boot_startmb:-"1"}
  51.     sfdisk_fstype=${sfdisk_fstype:-"0x83"}
  52.  
  53.     LC_ALL=C sfdisk --force --no-reread --in-order --Linux --unit M ${drive} <<-__EOF__
  54.         ${conf_boot_startmb},,${sfdisk_fstype},*
  55.     __EOF__
  56. }
  57.  
  58. dual_partition () {
  59.     echo "${drive}p2" > /resizerootfs
  60.     conf_boot_startmb=${conf_boot_startmb:-"1"}
  61.     conf_boot_endmb=${conf_boot_endmb:-"96"}
  62.     sfdisk_fstype=${sfdisk_fstype:-"0xE"}
  63.  
  64.     LC_ALL=C sfdisk --force --no-reread --in-order --Linux --unit M ${drive} <<-__EOF__
  65.         ${conf_boot_startmb},${conf_boot_endmb},${sfdisk_fstype},*
  66.         ,,,-
  67.     __EOF__
  68. }
  69.  
  70. expand_partition () {
  71.     if [ -f /boot/SOC.sh ] ; then
  72.         . /boot/SOC.sh
  73.     fi
  74.  
  75.     if [ "x${boot_drive}" = "x/dev/mmcblk0p1" ] ; then
  76.         drive="/dev/mmcblk0"
  77.     elif [ "x${boot_drive}" = "x/dev/mmcblk1p1" ] ; then
  78.         drive="/dev/mmcblk1"
  79.     else
  80.         echo "Error: script halting, could detect drive..."
  81.         exit 1
  82.     fi
  83.  
  84.     echo "Media: [${drive}]"
  85.  
  86.     if [ "x${boot_drive}" = "x${root_drive}" ] ; then
  87.         single_partition
  88.     else
  89.         dual_partition
  90.     fi
  91. }
  92.  
  93. expand_partition
  94. echo "reboot"
  95. #
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top