Menu

Can I run a script after clonezilla finish?

DaiXiTrum
2009-12-29
2013-04-05
  • DaiXiTrum

    DaiXiTrum - 2009-12-29

    Now that I have my clonezilla live running in full automation with PXE boot, I would like to run a script after clonezilla finishes.

    I saw a '-o1' parameter during expert mode to run the script in $OCS_POSTRUN_DIR as clone finishes, but I don't know where the OCS_POSTRUN_DIR directory to put my script in?

     
  • Steven Shiau

    Steven Shiau - 2009-12-30

    The variable is in /opt/drbl/conf/drbl-ocs.conf. If you do not modify it, OCS\_POSTRUN\_DIR is:

    /opt/drbl/share/ocs/postrun/

    Steven.

     
  • DaiXiTrum

    DaiXiTrum - 2009-12-31

    I copy my script (named czpostrun1) from my tftp server just before calling the ocs-sr.  After clonezilla finishes, I saw a post run message saying that it will run scripts within the …/postrun directory, with 3 lines of asteris (*), but it did not list or run anything.

    I checked the /opt/drbl/share/ocs/postrun/ directory, and my czpostrun1 file is in there.

     
  • Steven Shiau

    Steven Shiau - 2010-01-04

    Is /opt/drbl/share/ocs/postrun/czpostrun1 excutable? i.e. is its mode is 755, for example.

    Or you can run:

    run-parts -test /opt/drbl/share/ocs/postrun/

    to see if your command will be excuted or not.

    Steven.

     
  • DaiXiTrum

    DaiXiTrum - 2010-01-04

    Added the chmod 755 after download the file and it showed up in the list to run.

    But now I have a "Exec format error" when clonezilla tries to execute the script. I just have one line in my script to download a file from my tftp server.

    Once clonezilla drop out to the command line, I can manually execute my script with bash or sh with no error.

     
  • Steven Shiau

    Steven Shiau - 2010-01-05

    Normally a "Exec format error" means the script was edited on MS windows, and you want to run it on GNU/Linux.

    You can use the command "dos2unix" to convert the script file. Then this problem should be gone.

    Steven.

     
  • DaiXiTrum

    DaiXiTrum - 2010-01-05

    Steven,

    I created my file using vi from my other redhat machine, but I ran the dos2unix anyway. Still have the same problem.

    After clonezilla drop to a shell, I ran the dos2unix on my script czpostrun1 and ran the 'run-parts /opt/drbl/share/ocs/postrun/' command, and still have the same error.

    As a test, I remove my czpostrun1 script and created a file name 'test' with just one line 'echo test1' using vi. Then I ran the run-parts command and got the same 'Exec format error' error message when run-parts tried to execute my test script.

    I also tried the dos2unix on the test script and re-run the run-parts, but I still see the same problem.

    BTW, I'm using the 20091230-karmic version.

     
  • Steven Shiau

    Steven Shiau - 2010-01-05

    Very weird… You mean you can run the command by ./czpostrun1. But if you run "run-parts ./" it complains "Exec format error"… Weird…

    I will try to see if I can reproduce the problem tomorrow.

    Steven.

     
  • DaiXiTrum

    DaiXiTrum - 2010-01-05

    Yes, that's the problem.

    Thank Steven.

     
  • DaiXiTrum

    DaiXiTrum - 2010-01-07

    This is my default file under pxelinux.cfg (I break down the append line for easy reading)

    PROMPT 1
    TIMEOUT 200
    DEFAULT 1
    LABEL 1
        kernel cz1/vmlinuz
        append initrd=cz1/initrd.img boot=live union=aufs noswap noprompt vga=788  
        live-netdev=eth1 ip=frommedia fetch=tftp://192.168.1.100/cz1/filesystem.squashfs 
        ocs_prerun="busybox tftp -g -b 10240 -r clonezilla_custom_ocs -l /tmp/clonezilla_custom_ocs 192.168.1.100" 
        ocs_live_run="bash /tmp/clonezilla_custom_ocs" ocs_live_keymap=NONE ocs_lang=en_US.UTF-8 nolocales
    

    And this is my clonezilla_custom_ocs file:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    #!/bin/bach
    . /opt/drbl/sbin/drbl-conf-functions
    . /opt/drbl/sbin/ocs-functions
    . /etc/ocs/ocs-live.conf
    # Load language file
    ask_and_load_lang_set en_US.UTF-8
    # 1. Mount the clonezilla image home
    # Types: local_dev, ssh_server, samba_server, nfs_server
    #prep-ocsroot -t nfs_server
    mount -t nfs 192.168.1.100:/cz/home/partimag/ /home/partimag/
    # copy the clonezilla_postscript to the /opt/drbl/share/ocs/postrun directory
    busybox tftp -g -b 10240 -r czpostrun1 -l /opt/drbl/share/ocs/postrun/czpostrun1 192.168.1.100
    chmod 755 /opt/drbl/share/ocs/postrun/czpostrun1
    run-parts --test /opt/drbl/share/ocs/postrun
    # 2. Restore the image
    if mountpoint /home/partimag/ &>/dev/null; then
        #ocs-sr -l en_US.UTF-8 -c -p choose restoredisk "2009-11-12-14-img" "sda"
        #ocs-sr -l en_US.UTF-8 -b -p reboot restoredisk "2009-11-12-14-img" "sda"
         ocs-sr -g auto -v -nogui -b -r -j2 -o1 -p true restoredisk "2009-11-12-14-img" "sda"
    else
        [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
        echo "Fail to find the Clonezilla image home /home/partimag!"
        echo "Program terminated!"
        [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
    fi
    

    And my czpostrun1

    fileName="clonezilla_finished"
    echo $fileName
    busybox tftp -g -r $fileName -l /tmp/$fileName 192.168.1.100
    
     
  • DaiXiTrum

    DaiXiTrum - 2010-01-07

    Steven,

    I added the shebang for my czpostrun1 script and it works.

    Thanks a lot for your help.

    I hope the next ubuntu build will fix that crypto disk problem and I'll be all set.

     

Log in to post a comment.

MongoDB Logo MongoDB