Monday, November 30, 2009

[Level 3] 1A2B shell game

Another game.

#!/usr/bin/bash
showUsage() {

  cat <<EOF

Usage:

  $0

Ex.

  $0

EOF

}



getNum() {

  #set -vx

  sNum="0|1|2|3|4|5|6|7|8|9"

  sAns=""

  declare -i n1=$RANDOM*10/32767+1

  declare -i n2=$RANDOM*9/32767+1

  declare -i n3=$RANDOM*8/32767+1

  declare -i n4=$RANDOM*7/32767+1

  s=`echo $sNum | cut -d'|' -f$n1` && sAns=$sAns$s && sNum=`echo $sNum | sed -e "s/$s//" | sed -e 's/||/|/g' | sed -e 's/^|//g' | sed -e s'/|$//'`

  s=`echo $sNum | cut -d'|' -f$n2` && sAns=$sAns$s && sNum=`echo $sNum | sed -e "s/$s//" | sed -e 's/||/|/g' | sed -e 's/^|//g' | sed -e s'/|$//'`

  s=`echo $sNum | cut -d'|' -f$n3` && sAns=$sAns$s && sNum=`echo $sNum | sed -e "s/$s//" | sed -e 's/||/|/g' | sed -e 's/^|//g' | sed -e s'/|$//'`

  s=`echo $sNum | cut -d'|' -f$n4` && sAns=$sAns$s && sNum=`echo $sNum | sed -e "s/$s//" | sed -e 's/||/|/g' | sed -e 's/^|//g' | sed -e s'/|$//'`

  echo $sAns

}



# check $sAns $sGuess

checkNum() {

  sAns=$1

  sGuess=$2

  declare -i A=0

  declare -i B=0

  sA1=`echo ${sAns:0:1}`

  sA2=`echo ${sAns:1:1}`

  sA3=`echo ${sAns:2:1}`

  sA4=`echo ${sAns:3:1}`

  sG1=`echo ${sGuess:0:1}`

  sG2=`echo ${sGuess:1:1}`

  sG3=`echo ${sGuess:2:1}`

  sG4=`echo ${sGuess:3:1}`

  if [ $sAns == $sGuess ]

  then

    echo "Bingo...($sOAns:$sGuess)" && return 0

  else

    [ "$sA1" == "$sG1" ] && A=$A+1 && sAns=`echo $sAns | sed -e "s/$sA1//"`

    [ "$sA2" == "$sG2" ] && A=$A+1 && sAns=`echo $sAns | sed -e "s/$sA2//"`

    [ "$sA3" == "$sG3" ] && A=$A+1 && sAns=`echo $sAns | sed -e "s/$sA3//"`

    [ "$sA4" == "$sG4" ] && A=$A+1 && sAns=`echo $sAns | sed -e "s/$sA4//"`

    echo $sAns | grep $sG1 >/dev/null && B=$B+1

    echo $sAns | grep $sG2 >/dev/null && B=$B+1

    echo $sAns | grep $sG3 >/dev/null && B=$B+1

    echo $sAns | grep $sG4 >/dev/null && B=$B+1

    echo $sGuess: $A"A"$B"B ..." >> $0.log

    cat $0.log

    return 1

  fi

}



######################################################## main



sOAns=`getNum`

#echo "sOAns=$sOAns"

declare -i nCount=0

cat /dev/null > $0.log

while true

do

  read -p "Please enter 4 digit number or quit (you have guess $nCount times): " sGuess

  [ `echo $sGuess | awk '{print(length($1))}'` -ne 4 ] && echo "shorter then 4 digits..." && continue

  [ $sGuess == "quit" ] && echo "The answer is: $sOAns" && break

  checkNum $sOAns $sGuess && break

  nCount=$nCount+1

done

rm $0.log


Wish this helps.

regards,
Stanley Huang

[Level 3] OX shell game.

Today, I deliver the shell programming course.
And I think, why not to write a simple shell script game.
The script should be to fun.

#!/usr/bin/bash
showUsage() {
  cat<<EOF
Usage:
  $0 init/load 0/X
Ex.
  $0 init 0/X
  $0 load O/X
EOF
}

checkLine() {
  sDisp=$1
  s1=`echo $sDisp | cut -d'|' -f1`
  s2=`echo $sDisp | cut -d'|' -f2`
  s3=`echo $sDisp | cut -d'|' -f3`
  s4=`echo $sDisp | cut -d'|' -f4`
  s5=`echo $sDisp | cut -d'|' -f5`
  s6=`echo $sDisp | cut -d'|' -f6`
  s7=`echo $sDisp | cut -d'|' -f7`
  s8=`echo $sDisp | cut -d'|' -f8`
  s9=`echo $sDisp | cut -d'|' -f9`
  if [ $s1 == $s2 ] && [ $s2 == $s3 ]
  then
    echo "$s1 wins..." && return 0
  elif [ $s4 == $s5 ] && [ $s5 == $s6 ]
  then
    echo "$s4 wins..." && return 0
  elif [ $s7 == $s8 ] && [ $s8 == $s9 ]
  then
    echo "$s7 wins..." && return 0
  elif [ $s1 == $s4 ] && [ $s4 == $s7 ]
  then
    echo "$s1 wins..." && return 0
  elif [ $s2 == $s5 ] && [ $s5 == $s8 ]
  then
    echo "$s2 wins..." && return 0
  elif [ $s3 == $s6 ] && [ $s6 == $s9 ]
  then
    echo "$s3 wins..." && return 0
  elif [ $s1 == $s5 ] && [ $s5 == $s9 ]
  then
    echo "$s1 wins..." && return 0
  elif [ $s3 == $s5 ] && [ $s5 == $s7 ]
  then
    echo "$s3 wins..." && return 0
  else
    return 1
  fi
}

checkDone() {
  sArea=`cat $0.area | sed -e 's/[ ]*//g'`
  sDisp=`cat $0.disp | sed -e 's/n//g' | sed -e 's/. - ./|/g' | sed -e 's/[ -.]*//g'`
  checkLine $sDisp && return 0
  [ `echo $sArea | grep -c "[1-9]"` -eq 0 ] && echo "even..." && return 0
  return 1
}

############################ main
sAct=${1:-init}
case $sAct in
init)
  sArea="1 2 3 4 5 6 7 8 9"
  echo $sArea > $0.area
  sDisp="1 | 2 | 3n- . - . -n4 | 5 | 6n- . - . -n7 | 8 | 9"
  echo $sDisp > $0.disp
  sOX=$2
  clear && echo $sDisp | sed -e 's|n|\\\\n|g' | xargs echo
  if [ "$sOX" == "X" ] || [ "$sOX" == "x" ]
  then
    sOX=X
  else
    sOX=O
  fi
  $0 load $sOX
  ;;
load)
  sOX=$2
  sArea=`cat $0.area`
  sDisp=`cat $0.disp`
  while true
  do
    read -p "Please enter your pos ($sOX): " nPos
    sNArea=`echo $sArea | sed -e "s/$nPos//"`
    [ "$sArea" != "$sNArea" ] && sArea=$sNArea && break
  done
  echo $sArea > $0.area
  sDisp=`echo $sDisp | sed -e "s/$nPos/$sOX/"`
  echo $sDisp > $0.disp
  clear && echo $sDisp | sed -e 's|n|\\\\n|g' | xargs echo
  checkDone && rm $0.area $0.disp && exit 0
  if [ $sOX == "O" ]
  then
    sOX=X
  else
    sOX=O
  fi
  $0 load $sOX
  ;;
*)
  showUsage
  exit 1
  ;;
esac





Wish this helps.

regards,
Stanley Huang

Friday, November 27, 2009

[Level 3] The script for demo creating mass zones on OpenSolaris

Days ago, my colleague will demo about the virtualization techniques on OpenSolari.
So I share the script for him to demo fast creating zones on OpenSolaris.
After test, my lap will create a zone per 3 seconds.
That impress him, and he decided to demo on that session.

The same script that I'd like to share to you, please refer the following script code.
Any question, and suggestion, please feel free to let me know.

#!/usr/bin/bash
showUsage() {
  cat<<EOF
Usage:
  $0 [c]reate  [original index] [start index] [end index]
  $0 [d]estroy [start index]    [end index]   [always yes]
  $0 [l]ist
Ex.
  $0 c 1 2 10   => create  zone2, zone3, ... ,zone10
  $0 c 1 3 8    => create  zone3, zone4, ... ,zone8
  $0 d 2 10 [F] => destroy zone2, zone3, ... ,zone10
  $0 l
PS.
  for solaris 11 only
  all indexes must greater then 1, less then 255
Zones:
`listZone`
EOF
}

createOriginZone() {
  echo "create Zone (zone$nOriginIndex)..."
  zfs create -p $sBaseZoneZFS/zone$nOriginIndex
  chmod 700 $sBaseZonePath/zone$nOriginIndex
  zonecfg -z zone$nOriginIndex <<EOF
create
set zonepath=$sBaseZonePath/zone$nOriginIndex
add net
set physical=$sIF
set address=$sClassIP.$nOriginIndex/$nNetmask
end
commit
EOF
  zoneadm -z zone$nOriginIndex install
}

## build snapshot by zoenadm, and create snapshot for every clone.
## case1 $@
case1() {
  declare -i nOriginIndex=${1:-1}
  declare -i count=${2:-0}
  declare -i nZones=${3:-254}
  while [ $count -le $nZones ]
  do
    echo "create zone$count ....."
    zonecfg -z zone$nOriginIndex export -f /tmp/zone$count.cfg
    perl -pi -e "s/zone$nOriginIndex/zone$count/g" /tmp/zone$count.cfg
    perl -pi -e "s|^set address=.*|set address=$sClassIP.$count/$nNetmask|g" /tmp/zone$count.cfg
    zonecfg -z zone$count < /tmp/zone$count.cfg
    zoneadm -z zone$count clone zone$nOriginIndex
    echo "create zone$count done!"
    count=$count+1
  done
}

## build snapshot manually, and use one snapshot.
## case2 $@
## not work in OpenSolaris...
case2() {
  declare -i nOriginIndex=${1:-1}
  declare -i count=${2:-0}
  declare -i nZones=${3:-254}
  ## create first clone zone and use it's snapshot for later...
  case1 $nOriginIndex $count $count
  sOriginSnapshot=`zfs get -H origin $sBaseZoneZFS/zone$count | cut -d'    ' -f3`
  ## zfs snapshot $sOriginZoneZFS@$sTimestamp # not work

  count=$count+1
  while [ $count -le $nZones ]
  do
    echo "create zone$count ....."
    zonecfg -z zone$nOriginIndex export -f /tmp/zone$count.cfg
    perl -pi -e "s/zone$nOriginIndex/zone$count/g" /tmp/zone$count.cfg
    perl -pi -e "s|^set address=.*|set address=$sClassIP.$count/$nNetmask|g" /tmp/zone$count.cfg
    zonecfg -z zone$count < /tmp/zone$count.cfg
    zoneadm -z zone$count clone -s $sOriginSnapshot zone$nOriginIndex
    echo "create zone$count done!"
    count=$count+1
  done
}

createMassZones() {
  declare -i nOriginIndex=${1:-1}
  declare -i count=${2:-0}
  declare -i nZones=${3:-254}
  nSleep=5
  sTimestamp=`date "+%Y%m%d%H%M%S"`
 
  if [ `zoneadm list -cv | grep -wc zone$nOriginIndex` -eq 0 ]
  then
    read -p "Do you want to create the zone (zone$nOriginIndex)? (y/N):" yN
    if [ "$yN" == "Y" ] || [ "$yN" == "y" ]
    then
      createOriginZone
      zoneadm -z zone$nOriginIndex boot
      zlogin -C zone$nOriginIndex
    else
      echo "Exit program..."
      exit 1
    fi
  fi
 
  zlogin zone$nOriginIndex init 5
  sleep $nSleep
 
  case1 $@
  #case2 $@
}

destroyMassZones() {
  declare -i count=${1:-0}
  declare -i nZones=${2:-254}
  declare    sF=$3
  declare    sOrigSnap=""
  if [ "$sF" == "F" ] || [ "$sF" == "f" ]
  then
    sF="-F"
  else
    sF=""
  fi

  while [ $count -le $nZones ]
  do
    echo "destroy zone$count ....."
    zoneadm -z zone$count halt
    zoneadm -z zone$count uninstall $sF
    zonecfg -z zone$count delete $sF

    ## auto delete snapshot/clone after zoneadm -z zone$count uninstall
    #sOrigSnap=`zfs get -H origin $sBaseZoneZFS/zone$count/ROOT/zbe | awk '{print($3)}'`
    #zfs destroy -R $sOrigSnap
    #echo "zfs destroy -R $sOrigSnap"

    echo "destroy zone$count done!"
    count=$count+1
  done
}

listZone() {
  zoneadm list -iv
}
######################################################## main
sVersion="5.11"
sIF=yukonx0
sClassIP=172.31.248
nNetmask=24
sBaseZoneZFS=rpool/zones
sBaseZonePath=/export/home/zones
zfs create -o mountpoint=$sBaseZonePath -p $sBaseZoneZFS
chmod 700 $sBaseZonePath

[ `uname -r` != "$sVersion" ] && echo "For Solaris 11 only, exit program..." && exit 3
case $1 in
c|create)
  [ $# -lt 4 ] && echo "Error without enough parameters, exit program..." && showUsage && exit 1
  shift
  createMassZones $@
  ;;
d|delete)
  [ $# -lt 3 ] && echo "Error without enough parameters, exit program..." && showUsage && exit 1
  shift
  destroyMassZones $@
  ;;
l|list)
  listZone
  ;;
*)
  echo "Error with wrong action($1), exit program..." && showUsage && exit 2
  ;;
esac



Wish this helps.

regards,

Stanley Huang

Wednesday, November 25, 2009

[Level 3] Script for create VirtualBox VM quickly.

This script is for quickly create VirtualBox VM,
it base on ZFS snapshot/clone technique.
The description for the script is as the following:

The step as below:
1. create a ZFS filesystem first.
Ex. # zfs create -p rpool/vbox/sourceOS
2. create a VirtualBox VM for source and put the vdi on the above ZFS filesystem.
3. use the script:
Usage:
  $0 create New_Machine_Name Source_Machine_Name interface begin_index end_index
Ex.
  ./createVBoxClientByClone.sh create NewVM SourceVM yukonx0 3 5
the above command will create 3 VMs (NewVM_3, NewVM_4, NewVM_5):
The actions of create are,
. snapshot origin ZFS
. clone from origin ZFS snapshot to new ZFS
. re-new vdi uuid on new ZFS
. create new vm
. modify new vm
. modify new vm nic
4. If you want to delete VMs, use the command as below:
Usage:
  $0 delete New_Machine_Name Source_Machine_Name interface begin_index end_index
Ex.
  ./createVBoxClientByClone.sh delete NewVM SourceVM yukonx0 3 5
Above comand will delete 3 VMs (NewVM_3, NewVM_4, NewVM_5),
The actions of delete are:
. modify new vm (detach disk)
. unregister new vm
. destroy snapshot and new build-ed ZFS

The script as blow:

#!/usr/bin/bash
showUsage() {
  cat <<EOF
Usage:
  $0 create New_Machine_Name Source_Machine_Name interface begin_index end_index
Ex.
  $0 create OS111b_MySQL OS111b_origin yukonx0 1 10
  $0 delete OS111b_MySQL OS111b_origin yukonx0 1 10
VMMachine:
`showVMS | sed -e 's/^/  /'`
EOF
}

## Usage:
##   setUUID vdi_file
## Ex.
##   setUUID /Karajon/VBoxes/Guest/guest.vdi
setUUID() {
  sVDI=$1
  VBoxManage -q internalcommands setvdiuuid $sVDI
}

## Usage:
##   createVM vm_name os_type.
## Ex.
##   createVM S10u8_MySQL Solaris_64
## PS.
##   OS Type: Solaris Solaris_64 OpenSolaris OpenSolaris_64
createVM() {
  sVMName=$1
  sOSType=$2
  /opt/VirtualBox/VBoxManage -q createvm \
    --name $sVMName \
    --ostype $sOSType \
    --register
}

## Usage:
##   modifyVMNIC vm_name source_vm interface
## Ex.
##   modifyVMNIC S10u8_MySQL S10u8_Source yukonx0
modifyVMNIC() {
  sTVMName=$1
  sSVMName=$2
  sIF="$3 - Ethernet"
  sAttachedTo=bridged
  sAdapterType=82540EM
  while read n
  do
    /opt/VirtualBox/VBoxManage -q modifyvm $sTVMName \
      --nic$n $sAttachedTo \
      --nictype$n $sAdapterType \
      --cableconnected$n on \
      --bridgeadapter$n "$sIF"
  done <
<EOF
  `VBoxManage -q showvminfo $sSVMName | grep "^NIC [1-4]:" | cut -d: -f1 | awk '{print($2)}'`
EOF
}

## Usage:
##   modifyVM vm_name hda seq_no
## Ex.
##   modifyVM S10u8_MySQL /Karajon/VBox/$sVMName/$sVDI $nSeq
modifyVM() {
  sVMName=$1
  declare -i nMemory=768
  sHDA=$2
  sDVD_ISO=/Karajon/ISOs/osol-1002-125-ai-x86.iso
  declare -i nVRDPport=3390+$3

  /opt/VirtualBox/VBoxManage -q modifyvm $sVMName \
    --memory $nMemory \
    --hda $sHDA \
    --boot1 disk --boot2 dvd \
    --dvd $sDVD_ISO \
    --audio solaudio --audiocontroller ac97 \
    --vrdp on --vrdpport $nVRDPport
}

## Usage:
##   startVM vm_name
## Ex.
##   startVM S10_U8
startVM() {
  sVMName=$1
  /opt/VirtualBox/VBoxManage -q startvm $sVMName
}

showVMS() {
  VBoxManage -q list vms
}

## Usage:
##   getVMOSType vm_name
## Ex.
##   getVMOSType OS111b_MySQL
getVMOSType() {
  sVMName=$1
  sOSType=""
  sGuestOS=`VBoxManage -q showvminfo $sVMName | grep "^Guest OS:" | cut -d: -f2`
  sOS=`echo $sGuestOS | awk '{print($1)}'`
  declare -i nVer=`echo $sGuestOS | cut -d\( -f2 | cut -d' ' -f1`
  sOSType="$sOS"_"$nVer"
  echo "$sOSType"
}

## Usage:
##   getVMHDA vm_name
## Ex.
##   getVMHDA OS111b_MySQL
getVMHDA() {
  sVMName=$1
  sHDA=`VBoxManage -q showvminfo $sVMName | grep "^Primary master:" | cut -d: -f2 | awk '{print($1)}'`
  echo $sHDA
}

## Usage:
##   getZFS vdi_file
## Ex.
##   getZFS /Karajon/VBoxes/OS111b_MySQL/abc.vdi
getZFS() {
  sVDIFile=$1
  sVDIFolder=`dirname $sVDIFile`
  sZFS=`zfs list | grep $sVDIFolder$ | awk '{print($1)}'`
  echo $sZFS
}

## Usage:
##   cloneFS source_zfs target_name
## Ex.
##   sCloneFS=`cloneZFS Karajon/VBoxes/OS111b_origin S10u8_MySQL_1`
## PS. use this function to get clone ZFS name
cloneZFS() {
  sSZFS=$1
  sSnapshotName=$2
  sTZFS=`echo $sSZFS | sed -e 's|/[^/]*$||'`/$sSnapshotName
  pfexec zfs snapshot $sSZFS@$sSnapshotName || exit 2
  pfexec zfs clone $sSZFS@$sSnapshotName $sTZFS || exit 2
  echo $sTZFS
}

########################################################### main

[ $# -lt 6 ] && echo "Error without enough parameters, exit program..." && showUsage && exit 1
sAct=$1
sNMN=$2
sSMN=$3
sIF=$4
declare -i nStartMachine=$5
declare -i nEndMachine=$6

sOSType=`getVMOSType $sSMN`
sSHDA=`getVMHDA $sSMN`
sSZFS=`getZFS $sSHDA`
sCloneFS=""
sTHDA=""
sTZFS=""

case $sAct in
create)
  # set -vx
  declare -i nCount=$nStartMachine;
  while true
  do
    [ $nCount -gt $nEndMachine ] && break
    createVM "$sNMN"_"$nCount" $sOSType
    sCloneFS=`cloneZFS $sSZFS "$sSMN"_"$nCount"`
    sTHDA=`zfs get -H mountpoint $sCloneFS | awk '{print($3)}'`/`basename $sSHDA`
    setUUID $sTHDA
    modifyVM "$sNMN"_"$nCount" $sTHDA $nCount
    modifyVMNIC "$sNMN"_"$nCount" $sSMN $sIF
    nCount=nCount+1
    sleep 1
  done
  # set +vx
  ;;
delete)
  # set -vx
  declare -i nCount=$nStartMachine;
  while true
  do
    [ $nCount -gt $nEndMachine ] && break
    VBoxManage -q modifyvm "$sNMN"_"$nCount" --hda none || exit 3
    VBoxManage -q unregistervm "$sNMN"_"$nCount" --delete || exit 3
    zfs list -t snapshot | grep $sSMN@"$sSMN"_"$nCount" | while read f x
    do
      pfexec zfs destroy -R $f
    done
    nCount=nCount+1
  done
  # set +vx
  ;;
*)
  echo "Error with wrong action($sAct), exit program..."
  showUsage
  exit 1
esac







Wish this helps.

regards,
Stanley Huang

Thursday, November 19, 2009

[Level 2] How to get ZFS clone file system?

Now I have use VirtualBox with ZFS clone file system.
So sometimes, I have to figure out which file system is native, which file system is clone.
Therefore, I write a script to list the ZFS clone file system.

#!/usr/bin/bash
showUsage() {
  cat <
<EOF
Usage:
  $0 pool_name
Ex.
  $0 rpool
EOF
}

######################################################## main

[ $# -lt 1 ] && echo "Error without parameters, exit program..." && showUsage && exit 1
sPoolname=$1 #sPoolname=${1:-rpool}
echo "get pool($sPoolname)..."
zfs get -r origin $sPoolname | egrep -v -- 'origin[ ]+-[ ]+-$'


The you can use the command to find out the clone file system.
# getCloneFS.sh rpool

get pool(rpool)...
NAME                                          PROPERTY  VALUE                                         SOURCE
rpool/ROOT/opensolaris                        origin    rpool/ROOT/opensolaris-1@2009-11-18-05:46:35  -
#





Wish this helps.

regards,
Stanley Huang

[Level 1] Install freemind on OpenSolaris

These days, my colleague want to find the freemind tool which can run on OpenSolaris,
finally, we got one.
And you can download it from the following link:

http://freemind.sourceforge.net/wiki/index.php/Download

After downloaded, you can got a zip file. then de-compress it.

# cd /src

# mkdir freemind
# cd freemind; unzip ../freemind-bin-max-0_8_1.zip
< lengthy output omitted >
# chmod u+x ./freedmind.sh
# ./freemind.sh
# ps -ef | grep freemind
 stanley  1155   810   0 14:25:00 pts/2       0:05 /usr/java/bin/java -Dfreemind.base.dir=. -cp ::./lib/freemind.jar:./lib/ant/lib


Wish this helps.

regards,
Stanley Huang

[Level 2] Tips on ZFS.

1. Is that possible to migrate root filesytem from smaller hard disk to larger one without shutdown the operation system? The answer is "Yes", if you use OpenSolaris.
You can use a larger disk to attach into the pool and make the hard disk be a part of mirror disk of the root file system. After join the pool, the zfs pool will reslivering the data from origin one to new hard disk. After reslivered, then deatch the old hard disk, then the zfs capacity will also increased.
The simulation output as the following.

# mkdir /temp

# mkfile 128m /temp/128m
# mkfile 256m /temp/256m
# ls /temp/*m
-rw-------   1 stanley  staff    134217728 Nov 19 09:06 /temp/128m
-rw-------   1 stanley  staff    268435456 Nov 19 09:06 /temp/256m
#

# pfexec zpool create myPool /temp/128m
# zpool status myPool
  pool: myPool
 state: ONLINE
 scrub: none requested
config:

    NAME          STATE     READ WRITE CKSUM
    myPool        ONLINE       0     0     0
      /temp/128m  ONLINE       0     0     0

errors: No known data errors

# zfs list myPool
NAME     USED  AVAIL  REFER  MOUNTPOINT
myPool  68.5K  90.9M    19K  /myPool

#

# pfexec zpool attach myPool /temp/128m /temp/256m
# zpool status myPool
  pool: myPool
 state: ONLINE
 scrub: resilver completed after 0h0m with 0 errors on Thu Nov 19 09:09:26 2009
config:

    NAME            STATE     READ WRITE CKSUM
    myPool          ONLINE       0     0     0
      mirror        ONLINE       0     0     0
        /temp/128m  ONLINE       0     0     0
        /temp/256m  ONLINE       0     0     0  71.5K resilvered


errors: No known data errors

# zfs list myPool
NAME     USED  AVAIL  REFER  MOUNTPOINT
myPool  80.5K  90.9M    19K  /myPool

#

# pfexec zpool detach myPool /temp/128mb
# zpool status myPool
  pool: myPool
 state: ONLINE
 scrub: resilver completed after 0h0m with 0 errors on Thu Nov 19 09:09:26 2009
config:

    NAME          STATE     READ WRITE CKSUM
    myPool        ONLINE       0     0     0
      /temp/256m  ONLINE       0     0     0  71.5K resilvered

errors: No known data errors

# zfs list myPool
NAME     USED  AVAIL  REFER  MOUNTPOINT
myPool    82K   219M    19K  /myPool



2. How to shrink virtual disk of VirtualBox?
Virtual disk will not shrink even you delete data in the virtual machine. So, is that possible to shrink the virtual disk of VirtualBox? The answer is yes, if your virtual disk is on ZFS file system.
The steps as the following.
a. Create a virtual disk with dynamic disk type.
b. Add virtual disk to the virtual machine.
c. Attach the new virtual to the old one, and make them be a mirror disk.
d. After disk reslivered, detach the old disk from the mirror.

The same way can may your disk from fix disk size type to dynamic disk size type.

Wish this helps.

regards,
Stanley Huang

Tuesday, November 10, 2009

[Leve 1] Use usb to com to connect SPARC machine in OpenSolaris.

Today, I try to use my colleage's usb to com cable, to connect SPARC machine.
1. check /dev/term folder first.
# ls -al /dev/term
total 8
drwxr-xr-x   2 root root   2 2009-11-10 18:20 .
drwxr-xr-x 252 root sys  252 2009-11-10 18:20 ..

2. connect cable then try again.
# ls -al /dev/term
total 9
drwxr-xr-x   3 root root   3 2009-11-10 18:00 .
drwxr-xr-x 253 root sys  253 2009-11-10 18:00 ..
lrwxrwxrwx   1 root root  48 2009-11-10 18:00 0 -> ../../devices/pci@0,0/pci1043,8263@1d/device@1:0

3. use tip command to connect SPRAC machine.
PS. you have to set baud rate to 9600.
# tip -9600 /dev/term/0

4. Start the SPARC machine then you will get the console.

Wish this helps.

regards,
Stanley Huang