d1fa99da5e
git-svn-id: svn://svn.compuextreme.de/Viitor/V963/ViitorSetup@5933 504e572c-2e33-0410-9681-be2bf7408885
318 lines
8.3 KiB
Bash
318 lines
8.3 KiB
Bash
#!/bin/bash
|
|
#Framework, welches ein komplettes Linux System aus den Sourcen erstellt
|
|
#dieses Framework wird im CVS Repository
|
|
#:pserver:cvs.compuextreme.de:/Data/cvs zur Verfügung gestellt
|
|
#
|
|
#Lage dieser Datei im Archiv: $Source: $
|
|
#
|
|
#(c) 2003 Harald Kueller, Germany
|
|
#This program is free software; you can redistribute it and/or
|
|
#modify ist under the terms of the GNU General Public License
|
|
#as published by the Free Software Foundation; either version
|
|
#2 of the License, or (at your option) any later version.
|
|
#
|
|
#This program is distributed in the hope that it will be useful,
|
|
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
#See the GNU General Public License for more details.
|
|
#
|
|
#You should have received a copy of the GNU General Public License
|
|
#along with this program; if not write to the Free Software Foundation,
|
|
#Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
#
|
|
#Script:
|
|
#BasisScript Viitor_Setup
|
|
#Script mit Funktionen zur Konfiguration und Wartung
|
|
#des Volume Management (LVM2.0)
|
|
#
|
|
#Letzte Änderung von: $Author: $
|
|
#Datum der letzten Änderung: $Date: $
|
|
#Version der Datei: $Revision: $
|
|
#
|
|
#$Log: $
|
|
#
|
|
|
|
GetLVMGroups() {
|
|
vgdisplay |grep "VG Name"|awk '{print $3}'
|
|
}
|
|
|
|
GetLVMVGSize() {
|
|
VOLGROUP=$1
|
|
SIZE=`vgdisplay $VOLGROUP|grep "VG Size"|awk '{print $3}'|sed -e "s/,/\./"`
|
|
case `vgdisplay $VOLGROUP|grep "VG Size"|awk '{print $4}'` in
|
|
GB)
|
|
SIZE=`echo "$SIZE * 1024"|bc`
|
|
;;
|
|
KB)
|
|
SIZE=`echo "$SIZE / 1024"|bc`
|
|
;;
|
|
esac
|
|
echo $SIZE
|
|
}
|
|
|
|
GetLVMVolumes() {
|
|
VOLGROUP=$1
|
|
lvdisplay $VOLGROUP -c|awk -F":" '{print $1}'
|
|
}
|
|
|
|
GetLVMVolumeSize() {
|
|
VOLGROUP=$1
|
|
VOLNAME=$2
|
|
BSIZE=`lvdisplay -c $VOLGROUP|grep $VOLNAME|awk -F":" '{print $7}'`
|
|
(( BSIZE = $BSIZE / 2 / 1024 ))
|
|
echo $BSIZE
|
|
}
|
|
|
|
ShowVolumeManagerMenue() {
|
|
$DIALOGPRG --stdout --clear --title "Viitor VolumeManager Administration" \
|
|
--menu "Which Funktion do you want to use ?" 0 0 6 \
|
|
"SELECT" "Volume To Change" \
|
|
"PCREATE" "New Physical Volume" \
|
|
"CREATE" "New Volume Group" \
|
|
"VCREATE" "New Volume" \
|
|
"EXIT" "Viitor VolumeManager"
|
|
}
|
|
|
|
SelectVMPhysicalNo() {
|
|
PVPART=""
|
|
for i in `pvdisplay|grep "PV Name"|awk '{print $3}'`; do
|
|
PARTNAME=`/bin/ls -ld $i|grep "^[bl]"|awk '{print $NF}'`
|
|
if [ -h "$i" ]; then
|
|
PARTNAME=/dev/$PARTNAME
|
|
fi
|
|
if [ ! "`pvdisplay $PARTNAME|grep "VG Name"|awk '{print $3}'`" ]; then
|
|
PVPART=$PVPART" $PARTNAME"
|
|
fi
|
|
done
|
|
NumEntrys=0
|
|
ENTRY=""
|
|
for i in $PVPART; do
|
|
ENTRY=$ENTRY" $i `pvdisplay $i|grep "PV Size"|awk '{print $3,$4}'|sed -e "s/ //"` Off"
|
|
(( NumEntrys = $NumEntrys + 1 ))
|
|
done
|
|
(( NumEntrys = $NumEntrys + 1 ))
|
|
if [ ! $NumEntrys = "1" ]; then
|
|
$DIALOGPRG --stdout \
|
|
--backtitle "ViitorLinux VolumeManager Setup" \
|
|
--title "Select Physical Volumes" \
|
|
--checklist "to use with the new Group?" \
|
|
0 0 $NumEntrys \
|
|
$ENTRY
|
|
else
|
|
$DIALOGPRG --title "ViitorLinux VolumeManager Setup" --clear \
|
|
--msgbox "There is no unused Physical Volume\nPlease create a new Physical Volume first" 0 0
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
GetNewVGName() {
|
|
$DIALOGPRG --stdout --title "Viitor VolumeManager Administration" \
|
|
--inputbox "Please give a new Name vor the new VolumeGroup" 9 35
|
|
}
|
|
|
|
SelectVMPartition() {
|
|
VMPART=""
|
|
NumEntrys=0
|
|
for i in `\ls /dev/{h,s}d? 2>/dev/null`; do
|
|
DEVNAME=`basename $i`
|
|
if [ "`cat /sys/block/$DEVNAME/device/type 2>/dev/null`" == "0" ] || \
|
|
[ "`cat /sys/block/$DEVNAME/device/media 2>/dev/null`" == "disk" ]; then
|
|
if [ "`cat /sys/block/$DEVNAME/removable 2>/dev/null`" == "0" ]; then
|
|
for j in `fdisk -l /dev/${DEVNAME}|grep "^\/dev"|sed -e "s/\*//"|awk '{ if ( $5 == "8e" ) print $1}'`; do
|
|
pvdisplay $j 2>&1 >/dev/null
|
|
if [ $? = "5" ]; then
|
|
VMPART="$HD $j hd${NumEntrys}"
|
|
(( NumEntrys++ ))
|
|
fi
|
|
done
|
|
fi
|
|
fi
|
|
done
|
|
if [ -f /proc/mdstat ]; then
|
|
for i in `grep md /proc/mdstat|awk '{print $1}'|sed -e "s/md//"`; do
|
|
pvdisplay /dev/md/$i >/dev/null 2>&1
|
|
if [ $? = "5" ]; then
|
|
VMPART=$VMPART" /dev/md/$i Unknown"
|
|
(( NumEntrys = $NumEntrys + 1 ))
|
|
fi
|
|
done
|
|
fi
|
|
(( NumEntrys = $NumEntrys + 1 ))
|
|
if [ $NumEntrys = "1" ]; then
|
|
return 1
|
|
else
|
|
$DIALOGPRG --stdout --clear --title "Viitor VolumeManager Administration" \
|
|
--menu "Select Partition vor Physical Volume" 0 0 $NumEntrys \
|
|
$VMPART
|
|
fi
|
|
}
|
|
|
|
SelectVolumeGroup() {
|
|
VOLUMEGROUPS=`GetLVMGroups`
|
|
GROUPARG=""
|
|
NumEntrys=0
|
|
for i in $VOLUMEGROUPS; do
|
|
GROUPARG=$GROUPARG" $i `GetLVMVGSize $i`MB"
|
|
(( NumEntrys = $NumEntrys + 1 ))
|
|
done
|
|
(( NumEntrys = $NumEntrys + 1 ))
|
|
$DIALOGPRG --stdout --clear --title "Select Volume" \
|
|
--menu "Please select Volumegroup" 0 0 $NumEntrys \
|
|
$GROUPARG
|
|
}
|
|
|
|
SelectVolume() {
|
|
GROUP=`SelectVolumeGroup`
|
|
if [ ! $? = "0" ]; then
|
|
return 1
|
|
fi
|
|
VOLUMES=`GetLVMVolumes $GROUP`
|
|
if [ ! $? = "0" ]; then
|
|
return 1
|
|
fi
|
|
VOLARG=""
|
|
NumEntrys=0
|
|
for i in $VOLUMES; do
|
|
VOLARG=$VOLARG" $i `GetLVMVolumeSize $GROUP $i`M"
|
|
(( NumEntrys = $NumEntrys + 1 ))
|
|
done
|
|
(( NumEntrys = $NumEntrys + 1 ))
|
|
if [ ! $NumEntrys = "1" ]; then
|
|
VOLUME=`$DIALOGPRG --stdout --clear --title "Select Volume" \
|
|
--menu "Please select Volume" 0 0 $NumEntrys \
|
|
$VOLARG`
|
|
if [ $? = "0" ]; then
|
|
echo $VOLUME
|
|
else
|
|
return 1
|
|
fi
|
|
else
|
|
$DIALOGPRG --title "ViitorLinux VolumeManager Setup" --clear \
|
|
--msgbox "There are no Volumes in Group $GROUP" \
|
|
0 0
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
GetNewVolumeSize() {
|
|
VOLUMENAME=$1
|
|
VOLUMESIZE=$2
|
|
$DIALOGPRG --stdout --title "INPUT BOX" \
|
|
--inputbox "The Volume $VOLUMENAME has a size of $VOLUMESIZE MBytes\n\n \
|
|
Which new size (in MByte) should the Volume $VOLUMENAME become?:" 11 60
|
|
}
|
|
|
|
|
|
ResizeVolume() {
|
|
VOLUME=$1
|
|
SIZE=$2
|
|
|
|
VOLNAME=`basename $VOLUME`
|
|
GROUPDIR=`dirname $VOLUME`
|
|
GROUPNAME=`basename $GROUPDIR`
|
|
$DEBUG lvresize -L "$SIZE"M $VOLUME
|
|
FILESYS=`mount|grep /dev/mapper/$GROUPNAME-$VOLNAME|awk '{print $5}'`
|
|
MOUNTPOINT=`mount|grep /dev/mapper/$GROUPNAME-$VOLNAME|awk '{print $3}'`
|
|
case $FILESYS in
|
|
reiserfs)
|
|
$DEBUG reiserfsck --check /dev/mapper/$GROUPNAME_$VOLUME
|
|
$DEBUG resize_reiserfs /dev/mapper/$GROUPNAME-$VOLUME
|
|
;;
|
|
xfs)
|
|
$DEBUG xfs_growfs $MOUNTPOINT
|
|
;;
|
|
*)
|
|
echo "$FILESYSTEM can not be reiszed!"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
CreateVolume() {
|
|
VOLGROUP=$1
|
|
if [ "$DIALOGPRG" == "dialog" ]; then
|
|
VOLINFO=`dialog --title "ViitorLinux VolumeManager Setup" \
|
|
--stdout --form \
|
|
"Insert Volume Information" 10 35 3 \
|
|
"VolumeName:" 1 1 "" 1 12 15 0 \
|
|
"VolumeSize:" 2 1 "" 2 12 15 0`
|
|
if [ ! $? = "0" ]; then
|
|
return 1
|
|
fi
|
|
VOLNAME=`echo $VOLINFO|awk '{print $1}'`
|
|
VOLSIZE=`echo $VOLINFO|awk '{print $2}'`
|
|
else
|
|
VOLINFO=`Xdialog --title "ViitorLinux VolumeManager Setup" \
|
|
--stdout --2inputsbox \
|
|
"Insert Volume Information" 15 0 \
|
|
"VolumeName:" "" \
|
|
"VolumeSize:" ""`
|
|
if [ ! $? = "0" ]; then
|
|
return 1
|
|
fi
|
|
VOLNAME=`echo $VOLINFO|awk -F"/" '{print $1}'`
|
|
VOLSIZE=`echo $VOLINFO|awk -F"/" '{print $2}'`
|
|
fi
|
|
if [ $? = "0" ]; then
|
|
$DEBUG lvcreate -L $VOLSIZE -n $VOLNAME $VOLGROUP
|
|
fi
|
|
}
|
|
|
|
VolumeMenue() {
|
|
while FUNC=`ShowVolumeManagerMenue` ; do
|
|
case $FUNC in
|
|
SELECT)
|
|
VOLUME=`SelectVolume`
|
|
if [ ! $? = "0" ]; then
|
|
continue
|
|
fi
|
|
VOLNAME=`basename $VOLUME`
|
|
GROUPDIR=`dirname $VOLUME`
|
|
GROUPNAME=`basename $GROUPDIR`
|
|
SIZE=`GetLVMVolumeSize $GROUPNAME $VOLNAME`
|
|
NEWSIZE=`GetNewVolumeSize $VOLUME $SIZE`
|
|
if [ ! $? = "0" ]; then
|
|
continue
|
|
fi
|
|
if [ ! "$NEWSIZE" -ge "$SIZE" ]; then
|
|
$DIALOGPRG --title "ERROR" \
|
|
--msgbox "Couldn't make a Volume smaller"\
|
|
0 0
|
|
continue
|
|
fi
|
|
ResizeVolume $VOLUME $NEWSIZE
|
|
|
|
;;
|
|
PCREATE)
|
|
PART=`SelectVMPartition`
|
|
if [ $? = "0" ]; then
|
|
$DEBUG pvcreate $PART
|
|
fi
|
|
;;
|
|
CREATE)
|
|
PHVOLS=`SelectVMPhysicalNo`
|
|
if [ ! $? = "0" ]; then
|
|
continue
|
|
fi
|
|
PHVOLS=`echo $PHVOLS|sed -e "s/\"//g"`
|
|
VGNAME=`GetNewVGName`
|
|
if [ "$GROUPS" ]; then
|
|
echo "vgcreate $VGNAME $PHVOLS" >/tmp/test
|
|
$DEBUG /sbin/vgcreate $VGNAME $PHVOLS >>/tmp/test 2>&1
|
|
else
|
|
$DIALOGPRG --title "ViitorLinux VolumeManager Setup" --clear \
|
|
--msgbox "No Physical Volume selected\nPlease select a Physical Volume" 0 0
|
|
fi
|
|
;;
|
|
VCREATE)
|
|
GROUP=`SelectVolumeGroup`
|
|
if [ $? = "0" ]; then
|
|
CreateVolume $GROUP
|
|
fi
|
|
;;
|
|
EXIT)
|
|
break
|
|
;;
|
|
esac
|
|
done
|
|
}
|