Thursday, January 7, 2010

[Level 3] Create Belenix on USB stick

It's very easy to install Belenix on a USB stick.
Open a terminal on Belenix, and then execute the command 'usbdump'.
At this time, the script will part the USB then install grub on it.

The following script is that modified from usbdump.

1. uncompress_microroot.sh
uncompress the mircroroot archieve and mount it on/tmp/microroot.

2. compress_microroot.sh
compress the /tmp/mircroroot and archieve it on USB stick.

3. init_belenix.sh
Initialize Belenix, it will execute the script uncompress_microroot.sh and compress_microroot.sh
Because Belenix cannot regonize my Ethernet card, so I add the setting on file [archive dir]/etc/driver_alias and [archive dir]/boot/solaris/devicedb/master.

PS. My shellwill create backup flag file for DR.



##---------------------------------------------{compress_microroot.sh}

#!/usr/bin/bash -x
sNow=`date "+%Y%m%d%H%M%S"`
sTmpDir=/tmp
sTmpMicroRoot=$sTmpDir/microroot
sTmpRootFile=$sTmpDir/x86.microroot
sUSBDir=/.cdrom
sUSBRootFile=$sUSBDir/boot/x86.microroot
if [ ! -d $sTmpMicroRoot ]
then
echo "cannot find microroot directory ($sTmpMicroRoot) !"
echo "exit program!"
exit
fi
umount -f $sTmpMicroRoot
lofiadm -d $sTmpRootFile
rmdir $sTmpMicroRoot
cd $sTmpDir
gzip $sTmpRootFile
mv $sUSBRootFile $sUSBRootFile.$sNow
cp $sTmpRootFile.gz $sUSBRootFile
cd $sUSBDir/boot
mv -f $sTmpRootFile.gz $sTmpRootFile.$sNow
echo "Please change directory to `pwd` ..."



##-------------------------------------------{uncompress_microroot.sh }
#!/usr/bin/bash -x
#sNow=`date "+%Y%m%d%H%M%S"`
sTmpDir=/tmp
sTmpMicroRoot=$sTmpDir/microroot
sTmpRootFile=$sTmpDir/x86.microroot
sUSBDir=/.cdrom
sUSBRootFile=$sUSBDir/boot/x86.microroot
if [ ! -f $sUSBRootFile ]
then
echo "cannot find microroot ($sUSBRootFile) !"
echo "exit program!"
exit
fi
#cp $sUSBRootFile $sUSBRootFile.$sNow
cp $sUSBRootFile $sTmpRootFile.gz
cd $sTmpDir
gunzip $sTmpRootFile.gz
mkdir -p $sTmpMicroRoot
mount -F ufs -o nologging `lofiadm -a $sTmpRootFile` $sTmpMicroRoot
cd $sTmpMicroRoot
echo "Please change directory to `pwd` ..."


##--------------------------------------------------{init_belenix.sh }
#!/usr/bin/bash -x
#sNow=`date "+%Y%m%d%H%M%S"`
sTmpDir=/tmp
sTmpMicroRoot=$sTmpDir/microroot
sTmpRootFile=$sTmpDir/x86.microroot
sUSBDir=/.cdrom
sUSBRootFile=$sUSBDir/boot/x86.microroot
sUSBShell=$sUSBDir/shell
sBenelixVersion=$sUSBDir/BELENIX_VERSION
#sShellDir=`pwd`/`dirname $0`
#sBaseDir=$sShellDir/..
ls $sUSBDir
if [ ! -d $sUSBDir ]
then
#echo "$sUSBDir doesnot exist! exit program..."
#exit
mkdir $sUSBDir
fi
if [ `ls $sUSBDir | wc -l` -eq 0 ]
then
#echo "$sUSBDir is empty! exit program..."
#exit
mount -F lofs $sUSBDir $sUSBDir
elif [ ! -f $sBenelixVersion ]
then
echo "The folder ($sUSBDir) is not the home directory of belenix!"
echo "exit program"
exit
fi
#exit
if [ "$1" == "-f" ] # force running belenix initialization
then
echo "Re-initialize belenix..."
[ -f $sUSBRootFile.orig ] && cp $sUSBRootFile.orig $sUSBRootFile
[ -f $sUSBShell/.init_down ] && rm $sUSBShell/.init_down
elif [ -f $sUSBShell/.init_down ] # check init status
then
echo "init belenix done!"
echo "exit program..."
exit # prevent run the log file...
else
echo "init belenix..."
fi
if [ -f $sUSBRootFile ] && [ ! -f $sUSBRootFile.orig ]
then
cp $sUSBRootFile $sUSBRootFile.orig
fi
################################### in microroot
#s. uncompress_microroot.sh
$sUSBShell/uncompress_microroot.sh
#1. $sTmpMicroRoot/etc/driver_aliases
# add: 'iprb "pci8086,103e"'
echo 'iprb "pci8086,103e"' >> $sTmpMicroRoot/etc/driver_aliases
#2. $sTmpMicroRoot/boot/solaris/devicedb/master
# add: 'pci8086,103e pci8086,103e net pci iprb.bef "Intel PRO/100 VE Ethernet"
'
echo 'pci8086,103e pci8086,103e net pci iprb.bef "Intel PRO/100 VE Ethernet"
' >> $sTmpMicroRoot/boot/solaris/devicedb/master
#3. $sTmpMicroRoot/etc/skel/.bashrc
# add: export PATH=$sUSBShell:$PATH
# export PS1='\u@\h:\w# '
echo "export PATH=$sUSBShell:\$PATH" >> $sTmpMicroRoot/etc/skel/.bashrc
echo "export PS1='\u@\h:\w# '" >> $sTmpMicroRoot/etc/skel/.bashrc
echo "xset -b" >> $sTmpMicroRoot/etc/skel/.bashrc
#4. $sTmpMicroRoot/etc/shadow
# $ passwd root
# copy password to $sTmpMicroRoot/etc/shadow
passwd root
sNewPwd=`grep "^root:" /etc/shadow | cut -d: -f2`
perl -pi -e "s/tj5ElkRBX7LF2/$sNewPwd/" $sTmpMicroRoot/etc/shadow
#5. $sTmpMicroRoot/etc/xdg/xfce4/xinitrc
# add: xset -b
if [ `grep -c "^xset -b$" $sTmpMicroRoot/etc/xdg/xfce4/xinitrc` -eq 0 ]
then
echo "xset -b" >> $sTmpMicroRoot/etc/xdg/xfce4/xinitrc
fi
#e. compress_microroot.sh
# $sUSBShell/compress_microroot.sh
################################### in /.cdrom/belenix.zlib
################################### in /.cdrom/belenix.1.zlib
################################### create flag file
echo "create flag file ($sUSBShell/.init_down)..."
echo "This file is for identify the initialization of belenix, do not remove it.
.." > $sUSBShell/.init_down









Wish this helps.

regards,
Stanley Huang