Dreamplug Rollback System And UImage
Introduction
Requirements
-
uboot
configuration
- At least a dual boot system which tries at last the internal disk
- Software
- "das u-boot"
uimage
file
- system tar ball
Sources
- "HADES" configuration (http://www-hades.gsi.de), uploaded via
scp <file(s)> hadaq@http://jspc29.x-matter.uni-frankfurt.de:/srv/www/htdocs/bitfiles
How-to
Prepare your external usb device.
- Needs root privileges.
- Get the
uimage
and the system
tar ball
- Create a bootable SD-card/USB device
- "by Hand" :
- Partition your device into at least 2 partitions:
- first partition: FAT16, ≈ 30MB
- second partition: ext3, the rest
- 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
- Mount the partitions
- Extract
uimage
into the first partition
- Extract the tar ball into the second partition
- Unmount the partitions
Restore
- Plug your prepared USB device / SD card into the Dreamplug
- Restart your system
- Login to the dreamplug with root privileges
- user/pw: restore/nosoup4u
- becomes automatically:
root
- Internal SD card
- Optional: check internal
dev/sda
, there should be:
- 2 partitions
- VFAT, ≈30MB
- ext3, ≥ ≈4GB
- 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
- 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"
- 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
- restart system, with no boot device connected
- NOTE: at restart the restore account is automatically removed
Code:
Prepare
target=<span style="font-style:italic;font-variant:small-caps;"><Your Target Device, e.g. </span>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
- Plug your prepared USB device / SD card into the Dreamplug
- Restart your system
- Login to the dreamplug with root privileges
- user/pw: restore/nosoup4u
- becomes automatically:
root
-
#if you want to get the newest/or dreamplugRestoreLocalSystemFromExternal.sh is not on the system
wget -N https://wiki.gsi.de/pub/Epics/DreamplugRollbackSystemAndUImage/dreamplugRestoreLocalSystemFromExternal.sh
#optional source
source=<Your source Device, e.g. sdb>
chmod u+x ./dreamplugRestoreLocalSystemFromExternal.sh &&
./dreamplugRestoreLocalSystemFromExternal.sh
- 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