Epics@GSI Webhome

Dreamplug Rollback System And UImage

Introduction

Requirements

Sources

How-to

Prepare your external usb device.

  1. Needs root privileges.
  2. Get the uimage and the system tar ball
  3. Create a bootable SD-card/USB device
    • "by Hand" :
      1. Partition your device into at least 2 partitions:
        • first partition: FAT16, ≈ 30MB
        • second partition: ext3, the rest
      2. Format the device using mkfs.vfat and mkfs.ext3
        • Note: give the FAT partition only " " as name
    • "automatic" :
      • Follow the steps described in the topic DreamplugCreateBootableUSBDeviceFromLocalSystem
        • download/extract the script dreamplugCreateBootDeviceFunctionSet.sh
          • NOTE: our dreamplug devices, already contain this script
            • extract it from the system tar ball, ≈ 2min
        • source the this script
        • just excute the function createBootDevicePartition
  4. Mount the partitions
  5. Extract uimage into the first partition
  6. Extract the tar ball into the second partition
  7. Unmount the partitions

Restore

  1. Plug your prepared USB device / SD card into the Dreamplug
  2. Restart your system
  3. Login to the dreamplug with root privileges
    • user/pw: restore/nosoup4u
    • becomes automatically: root
  4. Internal SD card
    1. Optional: check internal dev/sda, there should be:
      • 2 partitions
        1. VFAT, ≈30MB
        2. ext3, ≥ ≈4GB
    2. Alternatively: clean and repartition /dev/sda:
      • Follow the steps described in the top DreamplugCreateBootableUSBDeviceFromLocalSystem, downloading the script, sourcing it, and just executing the function createBootDevicePartition
        source ~/dreamplugCreateBootDeviceFunctionSet.sh && target=<target> createBootDevicePartition
                    
      • Note: the current distribution of the image already contains the source: ~/dreamplugCreateBootDeviceFunctionSet.sh
  5. execute dreamplugRestoreLocalSystemFromExternal.sh,
    • the current distribution also contains it at ~/dreamplugRestoreLocalSystemFromExternal.sh
    • it performs the following steps
      • checks /proc/cmdline
        • root mustn't be the internal /dev/sda2
      • it takes the current / as source for the system
        • respecify source to be different
      • mounts internal devices: /dev/sda1 and /dev/sda2
      • mounts source device's first partition: /dev/sdX1
      • rsync of uimage
      • rsync of "system"
        • takes ≈ < 20 min
      • unmounts previously mounted devices
      • optional options:
        • -d: rsync with option --delete, any other content on the target system will be erased
        • -v: rsync with option --verbose, (much) more output
        • -n: rsync with option --dryRun, do nothing, just simulate
  6. restart system, with no boot device connected
  7. NOTE: at restart the restore account is automatically removed

Code:

Prepare

target=<Your Target Device, e.g. sdd> &&
cd $(mktemp -d) && 
wget -N http://jspc29.x-matter.uni-frankfurt.de/bitfiles/dreamplug-uimage-04112013.tar.xz && 
wget -N http://jspc29.x-matter.uni-frankfurt.de/bitfiles/dreamplug-system-01032016.tar.xz &&
scr=$(tar atf dreamplug-system-01032016.tar.xz | grep -w dreamplugCreateBootDeviceFunctionSet.sh) && 
tar axf dreamplug-system-01032016.tar.xz $scr && 
mv $scr $(basename $scr) && unset scr && 
. ./dreamplugCreateBootDeviceFunctionSet.sh && 
createBootDevicePartition && 
createBootDeviceMounts && 
tar Jxvf dreamplug-uimage-04112013.tar.xz -C /mnt/${target}1 && 
tar Jxvf dreamplug-system-01032016.tar.xz -C /mnt/${target}2 &&     
createBootDeviceUnmounts 
#optional: cd && rm -rf $OLDPWD

Restoring from external USB stick / SD card

  1. Plug your prepared USB device / SD card into the Dreamplug
  2. Restart your system
  3. Login to the dreamplug with root privileges
    • user/pw: restore/nosoup4u
    • becomes automatically: root
  4. #if you want to get the newest/or dreamplugRestoreLocalSystemFromExternal.sh is not on the system 
    wget -N https://wiki.gsi.de/foswiki/pub/Epics/DreamplugRollbackSystemAndUImage/dreamplugRestoreLocalSystemFromExternal.sh 
    
    #optional source
    source=<Your source Device, e.g. sdb>
    
    chmod u+x ./dreamplugRestoreLocalSystemFromExternal.sh  && 
    ./dreamplugRestoreLocalSystemFromExternal.sh
    

  1. reboot your device, with no boot device connected

Script code
dreamplugRestoreLocalSystemFromExternal.sh:

#!/bin/bash
   
   function dreamplugRestoreUsage()
   {
     echo -e "usage:"
     echo -e "       $0 [ options ] " 
     echo -e "$0 restores local file system from the source via rsync"
     echo -e "       $0 -h : this help"
     echo -e "       $0 -d : performs rsync with the option '--delete'"
     echo -e "       $0 -n : performs rsync with the option '--dryRun'"
     echo -e "       $0 -v : performs rsync with the option '--verbose'"
     echo -e "       $0 -s : source device"
     echo -e "\nsetting the environment variable 'clearSystem' to a not empty value"
     echo -e "  performes the rsync with the option '--delete'"
     echo
     exit
   }
   
   function dreamplugRestoreSetSource()
   {
      source=${source:=$(basename $(cat /proc/cmdline | tr " " "\n" | grep root= | cut -d "=" -f 2 | sed -e 's/\(.*\)[1-9]/\1/'))}
      echo source: $source
   }
   
   function dreamplugRestoreChecks ()
   {
      cat /proc/cmdline | grep -q root=/dev/$target 
      if [ $? -eq 0 ]
      then 
         echo "you MUST NOT sync to the running system on /dev/$target, reboot using an external device"  
         return 1;
      fi
   }
   
   function dreamplugRestoreMounts()
   {
      for item in ${source}1 ${source}2 ${target}1 ${target}2
      do
          if [ -b /dev/${item} ];
          then 
              mkdir -p /mnt/${item} &&
              echo mounting: /dev/${item} '->' /mnt/${item} &&
              mount /dev/${item} /mnt/${item} ||
              return 1;
          else
         echo "\"/dev/$item\" is not an available (block) device"
         return 1;
          fi
      done
   }
   
   function dreamplugRestoreRsyncs()
   {
      { TIMEFORMAT=$'real\t%1lR'; 
        time { grep -q /mnt/${source}1 /etc/mtab && 
               grep -q /mnt/${target}1 /etc/mtab && 
               echo syncing: /mnt/${source}1 /mnt/${target}1"
                    rsync ${dryRun} ${verbose} --stats --one-file-system --archive --hard-links --acls --xattrs ${clearSystem} /mnt/${source}1/ /mnt/${target}1";
               eval rsync ${dryRun} ${verbose} --stats --one-file-system --archive --hard-links --acls --xattrs ${clearSystem} /mnt/${source}1/ /mnt/${target}1; 
               echo;
             } || return 1;
        echo; 
        time { grep -q /mnt/${source}2 /etc/mtab && 
               grep -q /mnt/${target}2 /etc/mtab && 
               echo syncing: /mnt/${source}2/ /mnt/${target}2"
                    rsync ${dryRun} ${verbose} --stats --one-file-system --archive --hard-links --acls --xattrs ${clearSystem} /mnt/${source}2/ /mnt/${target}2" ;
               eval rsync ${dryRun} ${verbose} --stats --one-file-system --archive --hard-links --acls --xattrs ${clearSystem} /mnt/${source}2/ /mnt/${target}2;
               echo; 
             } || return 1;
        echo;
      }
   }
   
   function dreamplugRestoreUmounts()
   {
      cd /
      for item in ${source}1 ${source}2 ${target}1 ${target}2 
      do
          if [ -d /mnt/${item} ];
          then 
        grep -q /mnt/${item} /etc/mtab &&
             echo unmounting: /mnt/${item} &&
             umount /mnt/${item}
          fi
      done
   }
   
   function dreamplugRestoreEvaluateOptions()
   {
       # evaluate options and assign
       OPTIND=1
   
       while getopts ":hs:t:dnv" arg
       do
          case $arg in
         \? | h ) Help=TRUE; ;;
         s )     source=$OPTARG;;
         d )     clearSystem=TRUE;;
         n )     dryRun=TRUE;;
         v )      verbose=TRUE;
          esac
       done
       shift $(($OPTIND - 1))
   }
   
   function dreamplugRestoreMain()
   {
       dreamplugRestoreEvaluateOptions $*
   
       # Help?
       if [ 'TRUE' = "$Help" ]; then dreamplugRestoreUsage; return 0; fi
   
       clearSystem=${clearSystem:+--delete}
       dryRun=${dryRun:+--dry-run}
       verbose=${verbose:+--verbose}
   
       echo -n -e ${clearSystem:+"NOTE: 'rsync ${clearSystem}' in use\n"}
       echo -n -e ${dryRun:+"NOTE: 'rsync ${dryRun}' in use\n"}
       echo -n -e ${verbose:+"NOTE: 'rsync ${verbose}' in use\n"}
   
       target=sda;
       echo target: $target   
   
       dreamplugRestoreSetSource $* && 
       dreamplugRestoreChecks && 
       dreamplugRestoreMounts && 
       dreamplugRestoreRsyncs 
   
       dreamplugRestoreUmounts
       unset source target
   }
   
   #main
   dreamplugRestoreMain $*
   unset main dreamplugRestoreSetSource dreamplugRestoreChecks dreamplugRestoreMounts dreamplugRestoreRsyncs dreamplugRestoreUmounts verbose dryRun clearSystem Help


-- PeterZumbruch - 01 Mar 2016
-- PeterZumbruch - 2016-03-01
Topic attachments
I Attachment Action Size Date Who Comment
dreamplugRestoreLocalSystemFromExternal.shsh dreamplugRestoreLocalSystemFromExternal.sh manage 4.4 K 2014-10-15 - 15:15 PeterZumbruch restore shell script: restoring system from usb image
Topic revision: r22 - 2016-03-01, PeterZumbruch
 
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding GSI Wiki? Send feedback
Imprint (in German)
Privacy Policy (in German)