Getting Started, Documentation, Tips & Tricks

Commented script to CLONE ROOT DISK

Hi guys!

As I sometimes need to clone a root disk for backup purpose, I've read all your posts concerning this subject (e.g. viewtopic.php?t=8619 ) and tried to write my own script. The previous disk of the Indigo2 I'm using at work crashed, the only backup (bru) was done some 2 years ago and the file was corrupted. I had to reinstall everything from scratch: Irix, additional hardware, special software,...

The problem is that I don't know enough about shell scripts... :wink: . So, I've used foetz's one and modified it to include some options one could find usefull and - that's the most important part in my point of view - many comments to help beginners understand faster what the script does and geeks remember how to do it. I hope we'll all find here a reference for performing this cloning procedure.

Please feel free to use and modify it as your convenience. If you think some modifications would be usefull for many people, you can send me your script and I will try to include your improvements.

The following code will be updated with latest revisions when available (I hope so...).

last revision: 2006.09.09

Code: Select all

#!/sbin/ksh
#
#  auto xfs root disk duplicating
#  IRIX 6.2 or higher
#  26.04.2000 by R-A-C
#
#  modified by BetXen 2006.09.09
#
#  for more informations, see http://forums.nekochan.net/viewtopic.php?p=87120
#
#
#  LAST REVISION: 2006.09.09
#
#
#  ************************
#  * GENERAL INFORMATION: *
#  ************************
#
#  This script duplicates any xfs root disk onto another one using the
#  xfsdump/xfsrestore method. The target disk doesn't need to be greater or
#  equal in size than the source one. The free space should simply be big
#  enough to contain all the data of the first disk.
#
#  USAGE: scriptname (orig. disk cntrl) (orig. disk id) (target disk cntrl)...
#  (target disk id)
#  e.g. sgi_clone_root_disk 0 1 1 3 (will duplicate disk on scsi controller 0,
#  device id1 onto target disk on scsi controller 1 (i.e. external disk),
#  device id3)
#
#  If you copy/paste this text in a text editor, don't forget to chmod the
#  saved file to make it executable. Moreover, as it's a
#  system task, it should only be executed by root:
#       su
#   chown root:0 ./<name_of_your_script>
#   chmod a-x ./<name_of_your_script>
#   chmod u+x ./<name_of_your_script>
#
#  In order to be executed without the intervention of the user, the script
#  doesn't ask you for choices (e.g. spacecheck or not). If you want to
#  enable/disable it, please edit the script and uncomment/comment the
#  dedicated lines.
#
#  DON'T FORGET to partition the target disk as root drive at least once
#  before running the script. If you don't know how to perform this, please
#  follow these steps in your prefered shell:
#       fx
#       (enter)
#       <your_disk_controller_number>
#       <your_disk_drive_number>
#       (enter)
#       r
#       ro
#       (enter)
#       yes
#       ..
#       l
#       s
#       a
#       ..
#       ..
#       exi
#

export orig_cntrl=$1
export orig_drv=$2
export target_cntrl=$3
export target_drv=$4

clear

if [[ $# != 4 ]]; then
print "STOP! Bad number of arguments"
print "usage: scriptname (orig. disk cntrl) (orig. disk id) (target disk cntrl) (target disk id)"
print ""
print "example: sgi_clone_root_disk 0 1 1 3"
print ""
exit 1

elif [[ ${target_cntrl} = 0  &&  ${target_drv} = 1 ]]; then
print ""
print "STOP! Target drive is dks0d1..."
print "Isn't it your root drive?"
print "If you really want to do this, please edit the script..."
print ""
exit 1

elif [[ ${orig_cntrl} = ${target_cntrl}  &&  ${orig_drv} = ${target_drv} ]]; then
print ""
print "STOP! Original disk same as target disk..."
print ""
exit 1

else
print ""
print "***************************"
print "* ... formatting disk ... *"
print "***************************"
print ""
mkfs /dev/rdsk/dks${target_cntrl}d${target_drv}s0

print ""
print "*************************"
print "* ... mounting disk ... *"
print "*************************"
print ""
mkdir /sgi_clone_dsk_tmp
mount /dev/dsk/dks${target_cntrl}d${target_drv}s0 /sgi_clone_dsk_tmp

#  Uncomment the next lines if you want the script to inform you about available
#  space on the destination disk. Would take time, but could be usefull if you
#  have a smaller disk.
#
#   print ""
#   print "***********************************************************"
#   print "* ... giving size infos (in terms of 1024-byte blocks)... *"
#   print "***********************************************************"
#   print ""
#   print "Disk usage of /:"
#   du -k -s /
#   print ""
#   print "Free space on target disk:"
#   df -k /dev/dsk/dks${target_cntrl}d${target_drv}s0
#   print ""
#   print "     PLEASE CHECK SPACE!"
#   print "     Sleeping 15 seconds to let you abort script..."
#   sleep 15

print ""
print "************************************"
print "* ... duplicating data content ... *"
print "************************************"
print ""
print "Informations will be given every 30 seconds."
print ""
cd /sgi_clone_dsk_tmp
#  If you don't want infos during the process, remove "-p 30" in the next line.
timex xfsdump -l 0 -p 30 - / | xfsrestore - .

print ""
print "*****************************"
print "* ... making boot stuff ... *"
print "*****************************"
print ""
cd /stand
dvhtool -v get sash sash /dev/rdsk/dks${orig_cntrl}d${orig_drv}vh
dvhtool -v get ide ide /dev/rdsk/dks${orig_cntrl}d${orig_drv}vh
dvhtool -v creat sash sash /dev/rdsk/dks${target_cntrl}d${target_drv}vh
dvhtool -v creat ide ide /dev/rdsk/dks${target_cntrl}d${target_drv}vh

#  Uncomment the next lines if you plan to use this script as a backup one and
#  to write a file containing the date and time on your disks' root folder.
#   print ""
#   print "***************************************************"
#   print "* ... writing /_LAST_CLONE_.txt on both disks ... *"
#   print "***************************************************"
#   print ""
#   echo "Last clone using sgi_clone_disk script made on " > /_LAST_CLONE_.txt
#   date >> /_LAST_CLONE_.txt
#   more /_LAST_CLONE_.txt > /sgi_clone_dsk_tmp/_LAST_CLONE_.txt

print ""
print "**********************"
print "* ... unmounting ... *"
print "**********************"
print ""
cd /
umount /sgi_clone_dsk_tmp
sleep 1
rm -rf /sgi_clone_dsk_tmp

print ""
print "****************"
print "* ... done ... *"
print "****************"
print ""

fi
exit 0



foetz, thanks a lot for your help!


Raphaël[/b]
:Onyx2: : oxygen (4xR12k400) / :A3504L: :A3504L: : neon (16xI2 1.6, 9MB L2) / :O200: :O200: : beryllium (4xR12k270)
:Fuel: : nitrogen (R16k800) / :Octane2: : carbon (2xR14k600) / :Octane: : lithium (R10k400) / :Octane: : fluorine (2xR12k300) / spare 2xR12k360
:O2: : hydrogen (R10k195) / :O2: : sodium (R5k180) / :O2: : R5k180->200 MB and PM only
:Indigo2IMP: : helium (R10k195, HighImpact) / :Indigo2IMP: : boron (R4k250)/ :Indigo: : magnesium (R4k100) / :Indy: : aluminium (R5k180)
:4D70GT: 4D70GT : my very first one (now property of musée bolo and the foundation mémoires informatiques )
See the hinv/gfxinfo posts here .
nice :P
r-a-c.de
SWEET!!!!!!!!!
Powerbook 1.5 Ghz 10.5.2
PowerMac 1.8 Ghz 10.5.2
O2 Irix 6.5.30m
O2 Irix 6.5.30m
Octane Irix 6.5.30m
Octane 2 Irix 6.5.30m
FreeNAS Server 1.8 TB FreeBSD
_______________________
Tell me have you danced with the devil in the pale moon light?
script updated: 2006.09.09

- comment added concerning chown/chmod in order the script to be executed only by root.


Raphaël
:Onyx2: : oxygen (4xR12k400) / :A3504L: :A3504L: : neon (16xI2 1.6, 9MB L2) / :O200: :O200: : beryllium (4xR12k270)
:Fuel: : nitrogen (R16k800) / :Octane2: : carbon (2xR14k600) / :Octane: : lithium (R10k400) / :Octane: : fluorine (2xR12k300) / spare 2xR12k360
:O2: : hydrogen (R10k195) / :O2: : sodium (R5k180) / :O2: : R5k180->200 MB and PM only
:Indigo2IMP: : helium (R10k195, HighImpact) / :Indigo2IMP: : boron (R4k250)/ :Indigo: : magnesium (R4k100) / :Indy: : aluminium (R5k180)
:4D70GT: 4D70GT : my very first one (now property of musée bolo and the foundation mémoires informatiques )
See the hinv/gfxinfo posts here .
Excellent!
This will be perfect in my script collection.

Thank you for sharing!
Hello,

I've just got a 73 Go disk from eBay, and I've decided to reorganize my partitions and disks. One of the steps is to clone my actual 18 Go system disk onto this 73 Go. The script of foetz and BetXen will do the job.
The step I've come across were :
- fx to create the partitions on the new /dev/dsk/dks0d2, with the answers given in the first commented part of the script;
- run the script : './diskcloner.sh 0 1 0 2', which complains about 2 inodes at 15%, and an orphan at about 90%;
- power-off the octane.

After having extracted the former system disk, and replaced it with the newly created one (on scsi id 1), I rebooted the computer, and miserably arrived to a "prom" screen saying :

Code: Select all

Unable to execute xio(0)pci(15)scsi(0)disk(1)rdisk(0) partition(0): execute format error



Autoboot failed
xio(0)pci(15)scsi(0)disk(1)rdisk(0) partition(0): execute format error
Hit Enter to contine


Nice... Could it mean that the drive I've just bought on eBay is crappy, or did I do something wrong?

Thanks in advance for any advise/answer.

PB
Octane R14k 600MHz, V6, 2048 MB RAM, 73GB HD0, 18GB HD1, 73GB HD2
pub_bronx wrote: Nice... Could it mean that the drive I've just bought on eBay is crappy, or did I do something wrong?


Cloning only works if disks are exactly the same size.

I prefer to do the following:

(a) fx to setup the disk
(b) xfsdump/xfsrestore to save restore contents
(c) dvhtool to update the volume header with new sash.

This same procedure works no matter the size of disk.
If he have used the script from above he used the right way by performing xfs_dump. So the different disk sizes doesnt matter.

About the problem.... he have to check if the bootinfo contains the name of the kernel. Without that the prom uses some ENV settings which doesnt exists on every system.

Code: Select all

fx/label/show> boot

----- bootinfo-----
root partition = 0     swap partition = 1    bootfile = /unix


You can create the missing info within the fx tool.

regards
Joerg
Hello,

joerg wrote: You can create the missing info within the fx tool.


Is it too late for me to do that by now, after having already copied the other partitions with the script?

And is it related to the 'OSLoadFilename' variable Ian Mapleson is talking about in http://futuretech.blinkenlights.nl/disksfiles.html#CLONE , in the 'Cloning A Root Disk' section?

porter wrote: (a) fx to setup the disk
(b) xfsdump/xfsrestore to save restore contents
(c) dvhtool to update the volume header with new sash.


If I can't have the script work for my case, I'll have to try that way. Thanks for the tip!

PB
Octane R14k 600MHz, V6, 2048 MB RAM, 73GB HD0, 18GB HD1, 73GB HD2
pub_bronx wrote: Hello,

joerg wrote: You can create the missing info within the fx tool.


Is it too late for me to do that by now, after having already copied the other partitions with the script?


No its not to late.

And is it related to the 'OSLoadFilename' variable Ian Mapleson is talking about in http://futuretech.blinkenlights.nl/disksfiles.html#CLONE , in the 'Cloning A Root Disk' section?


Yes, but i dont knows if its the same for all sgi machines.

regards
Joerg
Hello,
Thanks for your help. I managed to boot from this newly cloned drive simply by adding

Code: Select all

setenv OSLoadFilename /unix

in the 'PROM shell'.

As a contribution, I'd like to propose a patch to this so useful script: with a small change, it can be used to clone option disks as well:

Code: Select all

--- diskcloner.sh.orig  Fri Dec 29 19:28:15 CET 2006
+++ diskcloner.sh       Fri Dec 29 20:38:58 CET 2006
@@ -66,6 +66,9 @@
export target_cntrl=$3
export target_drv=$4

+export system_mode="System"
+export option_mode="Option"
+
clear

if [[ $# != 4 ]]; then
@@ -91,88 +94,108 @@
exit 1

else
-   print ""
-   print "***************************"
-   print "* ... formatting disk ... *"
-   print "***************************"
-   print ""
-   mkfs /dev/rdsk/dks${target_cntrl}d${target_drv}s0
+   select mode in $system_mode $option_mode Exit; do
+      if [[ "$mode" = "$system_mode" || "$mode" = "$option_mode" ]] ; then
+         break;
+      elif [[ "$mode" = "Exit" ]] ; then
+            exit 1;
+      fi
+         print "Wrong choice... Hit a digit!";
+   done
+fi
-   print ""
-   print "*************************"
-   print "* ... mounting disk ... *"
-   print "*************************"
-   print ""
-   mkdir /sgi_clone_dsk_tmp
-   mount /dev/dsk/dks${target_cntrl}d${target_drv}s0 /sgi_clone_dsk_tmp
+if [[ "$mode" = "$system_mode" ]] ; then
+       export target_partition=0;
+elif [[ "$mode" = "$option_mode" ]] ; then
+       export target_partition=7;
+else
+       print "This shouldn't have happened! Exiting...";
+       exit 1;
+fi

+print ""
+print "***************************"
+print "* ... formatting disk ... *"
+print "***************************"
+print ""
+mkfs /dev/rdsk/dks${target_cntrl}d${target_drv}s${target_partition}
+
+print ""
+print "*************************"
+print "* ... mounting disk ... *"
+print "*************************"
+print ""
+mkdir /sgi_clone_dsk_tmp
+mount /dev/dsk/dks${target_cntrl}d${target_drv}s${target_partition} /sgi_clone_dsk_tmp
+
#  Uncomment the next lines if you want the script to inform you about available
#  space on the destination disk. Would take time, but could be usefull if you
#  have a smaller disk.
#
-#   print ""
-#   print "***********************************************************"
-#   print "* ... giving size infos (in terms of 1024-byte blocks)... *"
-#   print "***********************************************************"
-#   print ""
-#   print "Disk usage of /:"
-#   du -k -s /
-#   print ""
-#   print "Free space on target disk:"
-#   df -k /dev/dsk/dks${target_cntrl}d${target_drv}s0
-#   print ""
-#   print "     PLEASE CHECK SPACE!"
-#   print "     Sleeping 15 seconds to let you abort script..."
-#   sleep 15
-
-   print ""
-   print "************************************"
-   print "* ... duplicating data content ... *"
-   print "************************************"
-   print ""
-   print "Informations will be given every 30 seconds."
-   print ""
-   cd /sgi_clone_dsk_tmp
+#print ""
+#print "***********************************************************"
+#print "* ... giving size infos (in terms of 1024-byte blocks)... *"
+#print "***********************************************************"
+#print ""
+#print "Disk usage of /:"
+#du -k -s /
+#print ""
+#print "Free space on target disk:"
+#df -k /dev/dsk/dks${target_cntrl}d${target_drv}s${target_partition}
+#print ""
+#print "     PLEASE CHECK SPACE!"
+#print "     Sleeping 15 seconds to let you abort script..."
+#sleep 15
+
+print ""
+print "************************************"
+print "* ... duplicating data content ... *"
+print "************************************"
+print ""
+print "Informations will be given every 30 seconds."
+print ""
+cd /sgi_clone_dsk_tmp
#  If you don't want infos during the process, remove "-p 30" in the next line.-   timex xfsdump -l 0 -p 30 - / | xfsrestore - .
+timex xfsdump -l 0 -p 30 - / | xfsrestore - .

-   print ""
-   print "*****************************"
-   print "* ... making boot stuff ... *"
-   print "*****************************"
-   print ""
-   cd /stand
-   dvhtool -v get sash sash /dev/rdsk/dks${orig_cntrl}d${orig_drv}vh
-   dvhtool -v get ide ide /dev/rdsk/dks${orig_cntrl}d${orig_drv}vh
-   dvhtool -v creat sash sash /dev/rdsk/dks${target_cntrl}d${target_drv}vh
-   dvhtool -v creat ide ide /dev/rdsk/dks${target_cntrl}d${target_drv}vh
+if [[ "$mode" = "$system_mode" ]] ; then
+       print ""
+       print "*****************************"
+       print "* ... making boot stuff ... *"
+       print "*****************************"
+       print ""
+       cd /stand
+       dvhtool -v get sash sash /dev/rdsk/dks${orig_cntrl}d${orig_drv}vh
+       dvhtool -v get ide ide /dev/rdsk/dks${orig_cntrl}d${orig_drv}vh
+       dvhtool -v creat sash sash /dev/rdsk/dks${target_cntrl}d${target_drv}vh
+       dvhtool -v creat ide ide /dev/rdsk/dks${target_cntrl}d${target_drv}vh
+fi

#  Uncomment the next lines if you plan to use this script as a backup one and
#  to write a file containing the date and time on your disks' root folder.
-#   print ""
-#   print "***************************************************"
-#   print "* ... writing /_LAST_CLONE_.txt on both disks ... *"
-#   print "***************************************************"
-#   print ""
-#   echo "Last clone using sgi_clone_disk script made on " > /_LAST_CLONE_.txt
-#   date >> /_LAST_CLONE_.txt
-#   more /_LAST_CLONE_.txt > /sgi_clone_dsk_tmp/_LAST_CLONE_.txt
-
-   print ""
-   print "**********************"
-   print "* ... unmounting ... *"
-   print "**********************"
-   print ""
-   cd /
-   umount /sgi_clone_dsk_tmp
-   sleep 10
-   rm -rf /sgi_clone_dsk_tmp
-
-   print ""
-   print "****************"
-   print "* ... done ... *"
-   print "****************"
-   print ""
+#print ""
+#print "***************************************************"
+#print "* ... writing /_LAST_CLONE_.txt on both disks ... *"
+#print "***************************************************"
+#print ""
+#echo "Last clone using sgi_clone_disk script made on " > /_LAST_CLONE_.txt
+#date >> /_LAST_CLONE_.txt
+#more /_LAST_CLONE_.txt > /sgi_clone_dsk_tmp/_LAST_CLONE_.txt
+
+print ""
+print "**********************"
+print "* ... unmounting ... *"
+print "**********************"
+print ""
+cd /
+umount /sgi_clone_dsk_tmp
+sleep 10
+rm -rf /sgi_clone_dsk_tmp
+
+print ""
+print "****************"
+print "* ... done ... *"
+print "****************"
+print ""

-fi
exit 0


Any modification/correction/enhancement is of course welcome!

HTH,
PB
Octane R14k 600MHz, V6, 2048 MB RAM, 73GB HD0, 18GB HD1, 73GB HD2
pub_bronx wrote: Hello,
Thanks for your help. I managed to boot from this newly cloned drive simply by adding

Code: Select all

setenv OSLoadFilename /unix

in the 'PROM shell'.


And if you add this info into the bootinfo its not needed as a prom variable and your disk works in every machine (same type i mean).

regards
Joerg
Hello joerg,
Adding this info into the bootinfo can be done with fx, can't it?
Actually, when I run fx on (ctlr = #0, drive = #1, lun = #0), '[l]abel' => '[s]how' => '[b]ootinfo', I only see:

Code: Select all

----- bootinfo-----
root partition = 0     swap partition = 1    bootfile =

As I'm a bit stressed by doing something wrong here, causing potential unvolontary disk erasure, could you explain me which steps you go through to set up the 'bootfile' field?
Thanks in advance,
PB
Octane R14k 600MHz, V6, 2048 MB RAM, 73GB HD0, 18GB HD1, 73GB HD2
Its in

Code: Select all

fx -x
fx/label/set/bootinfo



The last entry have to be "/unix" and dont forget to sync.

regards
Joerg

Code: Select all

----- bootinfo-----
root partition = 0     swap partition = 1    bootfile = /unix


It worked! Thank you for the tip!
PB
Octane R14k 600MHz, V6, 2048 MB RAM, 73GB HD0, 18GB HD1, 73GB HD2