InstallToInternal.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. #Install PrawnOS to the internal emmc, this will partition the internal emmc
  3. #and erase ALL data on it
  4. # This file is part of PrawnOS (http://www.prawnos.com)
  5. # Copyright (c) 2018 Hal Emmerich <hal@halemmerich.com>
  6. # PrawnOS is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License version 2
  8. # as published by the Free Software Foundation.
  9. # PrawnOS is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. # You should have received a copy of the GNU General Public License
  14. # along with PrawnOS. If not, see <https://www.gnu.org/licenses/>.
  15. RESOURCES=/InstallResources
  16. read -p "This will ERASE ALL DATA ON THE INTERNAL STORAGE (EMMC) and reboot when finished, do you want to continue? [Y/n]" -n 1 -r
  17. echo
  18. if [[ $REPLY =~ ^[Yy]$ ]]
  19. then
  20. #disable dmesg, writing the partition map tries to write the the first gpt table, which is unmodifiable
  21. dmesg -D
  22. echo Writing partition map
  23. DISK_SZ="$(blockdev --getsz /dev/mmcblk2)"
  24. echo Total disk size is: $DISK_SZ
  25. if [ $DISK_SZ = 30785536 ]
  26. then
  27. echo Detected Emmc Type 1
  28. sfdisk /dev/mmcblk2 < $RESOURCES/mmc.partmap
  29. elif [ $DISK_SZ = 30777344 ]
  30. then
  31. echo Detected Emmc Type 2
  32. sfdisk /dev/mmcblk2 < $RESOURCES/mmc_type2.partmap
  33. else
  34. echo ERROR! Not a known EMMC type, please open an issue on github or send SolidHal an email with the Total disk size reported above
  35. echo Try a fallback value? This will allow installation to continue, at the cost of a very small amoutnt of disk space. This may not work.
  36. read -p "[Y/n]" -n 1 -r
  37. if [[ $REPLY =~ ^[Yy]$ ]]
  38. then
  39. echo Trying Emmc Type 2
  40. sfdisk /dev/mmcblk2 < $RESOURCES/mmc_type2.partmap
  41. else
  42. exit
  43. fi
  44. fi
  45. dmesg -E
  46. echo Writing kernel partition
  47. dd if=/dev/sda1 of=/dev/mmcblk2p1
  48. echo Writing Filesystem, this will take about 4 minutes...
  49. mkfs.ext4 -F -b 1024 -m 0 -O ^has_journal /dev/mmcblk2p2
  50. mkdir -p /mnt/mmc/
  51. mount /dev/mmcblk2p2 /mnt/mmc
  52. rsync -ah --info=progress2 --info=name0 --numeric-ids -x / /mnt/mmc/
  53. #Install a base fstab
  54. echo "/dev/mmcblk2p2 / ext4 defaults,noatime 0 1" > /mnt/mmc/etc/fstab
  55. umount /dev/mmcblk2
  56. echo Running fsck
  57. e2fsck -p -f /dev/mmcblk2p2
  58. echo Rebooting... Please remove the usb drive once shutdown is complete
  59. reboot
  60. fi
  61. echo Exiting