Guest User

Untitled

a guest
Apr 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. # S90stage1-partition: Create and format new volumes
  2. # Copyright (C) 2011 Brian McKenzie, All Rights Reserved.
  3. # For any questions, email me at <mckenzba@gmail.com>
  4. # You may redistribute and modify this file under the GPL license.
  5.  
  6. # Set up environment path variables
  7. export LVM_SYSTEM_DIR=/boot/etc/lvm
  8.  
  9. # Set up operation variables
  10. CREATE_VOLUMES_FLAG=1
  11. PARTITIONED=0
  12.  
  13. # Format the volumes
  14. format_volumes() {
  15. echo "Formatting volumes..."
  16. /mnt/webos/sbin/mkfs.ext4 /dev/store/ubuntu-system
  17. /mnt/webos/sbin/mkswap /dev/store/ubuntu-swap
  18. }
  19.  
  20. # Create the volumes
  21. create_volumes() {
  22. echo "Editing volume layout..."
  23.  
  24. # Begin by shrinking media volume size
  25. echo "Shrinking media volume by 4 GBs..."
  26. /mnt/webos/usr/sbin/fsck.vfat -a -v /dev/mapper/store-media
  27. NEW_VOLUME_SIZE=$(((`/boot/usr/sbin/lvm.static lvdisplay -c store/media | awk -F: '{print $7/2048}'`) - 4096))
  28. echo "New calculated media volume size: ${NEW_VOLUME_SIZE} MBs"
  29. LD_LIBRARY_PATH=/mnt/webos/usr/lib /mnt/webos/bin/resizefat /dev/store/media ${NEW_VOLUME_SIZE}M
  30.  
  31. if [ $? -ne 0 ]; then
  32. fuser -m /boot -k; umount /boot
  33. echo "ERROR: Unable to resize filesystem on media volume!, rebooting in 30 seconds..."
  34. sleep 30; reboot
  35. fi
  36.  
  37. /boot/usr/sbin/lvm.static lvreduce -f -L ${NEW_VOLUME_SIZE}M /dev/mapper/store-media
  38.  
  39. if [ $? -ne 0 ]; then
  40. fuser -m /boot -k; umount /boot
  41. echo "ERROR: Unable to resize media volume!, rebooting in 30 seconds..."
  42. sleep 30; reboot
  43. fi
  44.  
  45. # Set up the new volumes
  46. echo "Creating new volumes..."
  47. /boot/usr/sbin/lvm.static lvcreate -L 3584M --name ubuntu-system store
  48. /boot/usr/sbin/lvm.static lvcreate -L 512M --name ubuntu-swap store
  49.  
  50. # Proceed to format newley created volumes
  51. format_volumes
  52. }
  53.  
  54. setup_system() {
  55. # If we don't have /boot, make one
  56. if [ ! -d /boot ]; then
  57. mkdir /boot
  58. fi
  59.  
  60. # Check filesystem and mount /boot
  61. fsck -fy /dev/mmcblk0p13
  62. mount -t ext3 /dev/mmcblk0p13 /boot
  63.  
  64. # Initiate LVM
  65. /boot/usr/sbin/lvm.static vgchange -ay
  66.  
  67. if [ $? -ne 0 -o ! -d /dev/store ]; then
  68. fuser -m /boot -k; umount /boot
  69. echo "ERROR: Unable to start LVM!, rebooting in 30 seconds..."
  70. sleep 30; reboot
  71. fi
  72.  
  73. # Check to see if we are just re-installing. If so, save some time and don't recreate the volumes.
  74. if [ -e /dev/store/ubuntu-system -a -e /dev/store/ubuntu-swap ]; then
  75. echo "Previous installation detected - skipping volume creation"
  76. CREATE_VOLUMES_FLAG=0
  77. format_volumes
  78. else
  79. # Check to see if this is a first-time installation, or if we have a broken setup
  80. if [ ! -e /dev/store/ubuntu-system -a ! -e /dev/store/ubuntu-swap ]; then
  81. break;
  82. else
  83. if [ ! -e /dev/store/ubuntu-system -o ! -e /dev/store/ubuntu-swap ]; then
  84. fuser -m /boot -k; umount /boot
  85. echo "ERROR: Damaged installation with broken LVM volumes detected!, rebooting in 30 seconds..."
  86. sleep 30; reboot
  87. fi
  88. fi
  89. fi
  90.  
  91. # If we don't have /mnt/webos, make one
  92. if [ ! -d /mnt/webos ]; then
  93. mkdir -p /mnt/webos
  94. fi
  95.  
  96. # Check filesystem and mount /mnt/webos
  97. fsck -fy /dev/store/root
  98. mount -t ext3 -o ro /dev/store/root /mnt/webos
  99.  
  100. if [ ${CREATE_VOLUMES_FLAG} -eq 1 ]; then
  101. create_volumes
  102. fi
  103. }
  104.  
  105. setup_system
  106.  
  107. # Set flag for stage 2
  108. export PARTITIONED=1
Add Comment
Please, Sign In to add comment