Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # S90stage1-partition: Create and format new volumes
- # Copyright (C) 2011 Brian McKenzie, All Rights Reserved.
- # For any questions, email me at <mckenzba@gmail.com>
- # You may redistribute and modify this file under the GPL license.
- # Set up environment path variables
- export LVM_SYSTEM_DIR=/boot/etc/lvm
- # Set up operation variables
- CREATE_VOLUMES_FLAG=1
- PARTITIONED=0
- # Format the volumes
- format_volumes() {
- echo "Formatting volumes..."
- /mnt/webos/sbin/mkfs.ext4 /dev/store/ubuntu-system
- /mnt/webos/sbin/mkswap /dev/store/ubuntu-swap
- }
- # Create the volumes
- create_volumes() {
- echo "Editing volume layout..."
- # Begin by shrinking media volume size
- echo "Shrinking media volume by 4 GBs..."
- /mnt/webos/usr/sbin/fsck.vfat -a -v /dev/mapper/store-media
- NEW_VOLUME_SIZE=$(((`/boot/usr/sbin/lvm.static lvdisplay -c store/media | awk -F: '{print $7/2048}'`) - 4096))
- echo "New calculated media volume size: ${NEW_VOLUME_SIZE} MBs"
- LD_LIBRARY_PATH=/mnt/webos/usr/lib /mnt/webos/bin/resizefat /dev/store/media ${NEW_VOLUME_SIZE}M
- if [ $? -ne 0 ]; then
- fuser -m /boot -k; umount /boot
- echo "ERROR: Unable to resize filesystem on media volume!, rebooting in 30 seconds..."
- sleep 30; reboot
- fi
- /boot/usr/sbin/lvm.static lvreduce -f -L ${NEW_VOLUME_SIZE}M /dev/mapper/store-media
- if [ $? -ne 0 ]; then
- fuser -m /boot -k; umount /boot
- echo "ERROR: Unable to resize media volume!, rebooting in 30 seconds..."
- sleep 30; reboot
- fi
- # Set up the new volumes
- echo "Creating new volumes..."
- /boot/usr/sbin/lvm.static lvcreate -L 3584M --name ubuntu-system store
- /boot/usr/sbin/lvm.static lvcreate -L 512M --name ubuntu-swap store
- # Proceed to format newley created volumes
- format_volumes
- }
- setup_system() {
- # If we don't have /boot, make one
- if [ ! -d /boot ]; then
- mkdir /boot
- fi
- # Check filesystem and mount /boot
- fsck -fy /dev/mmcblk0p13
- mount -t ext3 /dev/mmcblk0p13 /boot
- # Initiate LVM
- /boot/usr/sbin/lvm.static vgchange -ay
- if [ $? -ne 0 -o ! -d /dev/store ]; then
- fuser -m /boot -k; umount /boot
- echo "ERROR: Unable to start LVM!, rebooting in 30 seconds..."
- sleep 30; reboot
- fi
- # Check to see if we are just re-installing. If so, save some time and don't recreate the volumes.
- if [ -e /dev/store/ubuntu-system -a -e /dev/store/ubuntu-swap ]; then
- echo "Previous installation detected - skipping volume creation"
- CREATE_VOLUMES_FLAG=0
- format_volumes
- else
- # Check to see if this is a first-time installation, or if we have a broken setup
- if [ ! -e /dev/store/ubuntu-system -a ! -e /dev/store/ubuntu-swap ]; then
- break;
- else
- if [ ! -e /dev/store/ubuntu-system -o ! -e /dev/store/ubuntu-swap ]; then
- fuser -m /boot -k; umount /boot
- echo "ERROR: Damaged installation with broken LVM volumes detected!, rebooting in 30 seconds..."
- sleep 30; reboot
- fi
- fi
- fi
- # If we don't have /mnt/webos, make one
- if [ ! -d /mnt/webos ]; then
- mkdir -p /mnt/webos
- fi
- # Check filesystem and mount /mnt/webos
- fsck -fy /dev/store/root
- mount -t ext3 -o ro /dev/store/root /mnt/webos
- if [ ${CREATE_VOLUMES_FLAG} -eq 1 ]; then
- create_volumes
- fi
- }
- setup_system
- # Set flag for stage 2
- export PARTITIONED=1
Add Comment
Please, Sign In to add comment