#!/bin/bash #Syn-3 diskinit (C)2005 DatuX #-Combine all the specified partitions into a Syn-3 md1 data device #-lvm stuff, swap etc will also be initialized. #-Partitions should be type FD . dialoglib.sh || exit 1 exec 2>&1 PART_COUNT=0 for PART in $*; do echo -e "\n* Clearing partion $PART:" #remove raid partition superblocks #(may fail) mdadm --misc --zero-superblock --force $PART &>/dev/null #remove other confusing stuff thats in the partition dd if=/dev/zero of=$PART bs=4k count=1 &>/dev/null || exit 1 (( PART_COUNT++ )) done ######################## Combine partitions into one raid array or volume group if [ "$USE_MD" ]; then # Combines all the discs into a RAID1 or RAID5 array: # /dev/md1 will contain LVM partitions # create LVM raid array md1 echo -e "\n* Creating Data RAID ARRAY (md1):" if [ $PART_COUNT == 1 ]; then # 1 disc: degraded RAID 1 MDCMD="mdadm --create --run -l1 -n2 -amd /dev/md1 $* missing" elif [ $PART_COUNT == 2 ]; then # 2 discs: RAID 1 MDCMD="mdadm --create --run -l1 -n2 -amd /dev/md1 $*" else # 3 or more discs: RAID 5 MDCMD="mdadm --create --run -l5 -n$PART_COUNT -amd /dev/md1 $*" fi $MDCMD || exit 1 # Try to autodetect the RAID array, just like we do in our initrd. # This will fail if a single disk if we use GPT with a disk thats >2TB it seems? # With this test we make sure it works, before continiuing. echo "* Stopping and re-detecting RAID array, to test the bootprocess:" #speed up creation, because we have no udev rules for this: mkdir /dev/md mknod /dev/md/0 b 9 0 mknod /dev/md/1 b 9 1 mdadm --manage /dev/md0 -S || exit 1 mdadm --manage /dev/md1 -S || exit 1 udevadm settle #for some reason we have to wait.. sleep 1 mdadm --assemble --scan || exit 1 if ! grep md0 /proc/mdstat >/dev/null || ! grep md1 /proc/mdstat >/dev/null; then echo "ERROR ASSEMBLING RAID ARRAY. (are there unused disks with a different syn3 installation in the system?)" exit 1 fi # Creates LVM volume group from /dev/md1 #init disk echo -e "\n* Creating LVM:" pvcreate -y -ff /dev/md1 || exit 1 #-ff = force #create a volume group echo -e "\n* Creating SYN3 VOLUMEGROUP:" vgcreate -y syn3 /dev/md1 || exit 1 else #Not using MD, so just create a volumegroup by combining the partitions. #init disk echo -e "\n* Creating LVM:" pvcreate -y -ff $* || exit 1 #-ff = force #create a volume group echo -e "\n* Creating SYN3 VOLUMEGROUP:" vgcreate -y syn3 $* || exit 1 fi ##################### Activate LVM and create volumes #activate all volume groups echo -e "\n* Activating LVM groups:" vgchange -a y || exit 1 #create lvm parititons echo -e "\n* Creating paritions:" lvcreate --yes -L $SIZE_ROOT syn3 -n root || exit 1 if [ "$SIZE_SWAP" ]; then lvcreate --yes -L $SIZE_SWAP syn3 -n swap || exit 1 fi #metadata voor drbd lvcreate --yes -n boot.meta -L128M syn3 || exit 1 lvcreate --yes -n root.meta -L128M syn3 || exit 1 lvcreate --yes -n home.meta -L128M syn3 || exit 1 #we need to automaticly determine the rest of the free space? if [ "$SIZE_HOME" = "" ]; then #temporary reserve the free space, if specified if [ "$SIZE_FREE" ]; then lvcreate --yes -L $SIZE_FREE syn3 -n tmp || exit 1 fi #use the extends that are left: EXTENDS=`vgdisplay syn3 -c | cut -f16 -d:` lvcreate --yes -l $EXTENDS syn3 -n home || exit 1 #remove temporary space if [ "$SIZE_FREE" ]; then sleep 3 #sometimes complains its still busy lvremove -f /dev/syn3/tmp || exit 1 fi else #Size of home manually specified. lvcreate --yes -L $SIZE_HOME syn3 -n home || exit 1 fi #make /dev device nodes echo -e "\n* Creating DEVICE NODES:" lvscan || exit 1 ####################### Create filesystems # Other filesystems will be in LVM group: /dev/syn3/ #create filesystems echo -e "\n* Creating filesystems:" mkfs.xfs -f -s size=4096 /dev/syn3/root -L ROOT || exit 1 if [ "$SIZE_SWAP" ]; then mkswap /dev/syn3/swap || exit 1 fi mkfs.xfs -f -s size=4096 /dev/syn3/home -L HOME || exit 1 echo -e "\n* DONE" #release the flying monkeys: exit 0