Skip to content

Commit

Permalink
- Integrated P2V patch from Heinlein Support. We start with 1.9 now to
Browse files Browse the repository at this point in the history
  reflect the new feature in the version.
        * Migrate disk and network configuration if HW changed
        * Adjust drivers and initrd/initramfs
        * Adjust swap space with by-id mounting (only swap ATM)
        * Read mapping files in /etc/rear/mapping with answers instead of asking during recovery
        * Run PRE_RECOVERY_SCRIPT and POST_RECOVERY_SCRIPT scripts as a hook for user-supplied stuff
        * Changed the rescue system startup code to be a directory of shell snippets (/etc/scripts/system-setup.d)
        * recreate some FS attributes for ext*
        * recreate vfat
- Added AddExitTask/RemoveExitTask functions to handle several exit
  tasks (e.g. umount NETFS share)
- Added shell workflow to enter a ReaR shell where one can use all ReaR
  functions and source scriptlets
  • Loading branch information
schlomo committed Jun 6, 2010
1 parent 33ad4d0 commit 844d50b
Show file tree
Hide file tree
Showing 57 changed files with 1,377 additions and 167 deletions.
6 changes: 4 additions & 2 deletions usr/share/rear/AUTHORS
@@ -1,2 +1,4 @@
GSS Schlomo Schapiro
GD Gratien D'haese
GSS Schlomo Schapiro
GD Gratien D'haese
SSE Stefan Semmelroggen
PHEI Peer Heinlein
13 changes: 13 additions & 0 deletions usr/share/rear/CHANGES
@@ -1,3 +1,16 @@
Version 1.9.0 - not released
---------------------------
2010-06-05 GSS * Merged P2V patch from Heinlein Support with the following included changes:
* Migrate disk and network configuration if HW changed
* Adjust drivers and initrd/initramfs
* Adjust swap space with by-id mounting (only swap ATM)
* Read mapping files in /etc/rear/mapping with answers instead of asking during recovery
* Run PRE_RECOVERY_SCRIPT and POST_RECOVERY_SCRIPT scripts as a hook for user-supplied stuff
* Changed the rescue system startup code to be a directory of shell snippets (/etc/scripts/system-setup.d)
* recreate some FS attributes for ext*
* recreate vfat


Version 1.7.25 - 2010-06-04
---------------------------
2010-06-04 GD * Bug 600217 - Fedora link missing in restore, pack and finalize sub-directories
Expand Down
9 changes: 9 additions & 0 deletions usr/share/rear/TODO
@@ -0,0 +1,9 @@
* finalize/Fedora/i386/17_rebuild_initramfs.sh
- needs to be written, seems like RH builds rich initramfs with all modules included

* finalize/Gentoo/i386/17_rebuild_initramfs.sh
- needs to be written, I have no idea what should be done here (since I don't have Gentoo)

* write network migration code for all other distributions

* support dhcp for network migration
8 changes: 4 additions & 4 deletions usr/share/rear/build/Debian/i386/60_fix_debian_stuff.sh
@@ -1,12 +1,12 @@
#
# debian has to do everything different from all other Linux systems ...

test -x "$(type -p lilo.real)" && {
if test -x "$(type -p lilo.real)" ; then
cp -af "$(type -p lilo.real)" $ROOTFS_DIR/bin/lilo
cp -a /lib/libdevmapper* $ROOTFS_DIR/lib/
}
fi

test -x "$(type -p lvmiopversion)" && {
if test -x "$(type -p lvmiopversion)" ; then
cp -af /lib/lvm-* $ROOTFS_DIR/lib/
cp -af /sbin/lvm* $ROOTFS_DIR/bin/
}
fi
1 change: 1 addition & 0 deletions usr/share/rear/build/GNU/Linux/00_create_symlinks.sh
Expand Up @@ -23,6 +23,7 @@ pushd $ROOTFS_DIR >/dev/null
ln -sf bin/init init
ln -sf bin sbin
ln -sf bin/bash bin/sh
ln -sf true bin/pam_console_apply # RH/Fedora with udev needs this
pushd usr >/dev/null
ln -sf /bin bin
ln -sf /lib lib
Expand Down
81 changes: 81 additions & 0 deletions usr/share/rear/build/GNU/Linux/60_verify_and_adjust_udev.sh
@@ -0,0 +1,81 @@
# verify that all required components for udev are present
#

# skip this script if udev is not part of the rescue system
test -d $ROOTFS_DIR/etc/udev/rules.d || return 0

ProgressStart "Checking udev"
# check that all external programs used by udev are available
while read file location ; do
# check for file in ROOTFS_DIR (if full path) or in lib/udev or in bin (if name without path)
if test -x $ROOTFS_DIR/$file -o \
-x $ROOTFS_DIR/lib/udev/$file -o \
-x $ROOTFS_DIR/bin/$file ; then
# everything is fine
# Log "matched external call to $file in $location"
echo "matched external call to $file in $location" 1>&8
else
ProgressStep
Log "WARNING: unmatched external call to '$file' in $location"
fi
done < <(
# get list of external files called in PROGRAM= or RUN= statements. The result is filtered
# for files (no $env{...} or socket: stuff) and looks like this:
# /bin/sed etc/udev/rules.d/56-sane-backends-autoconfig.rules:289
# ata_id etc/udev/rules.d/60-persistent-storage.rules:39
# /sbin/kpartx etc/udev/rules.d/70-kpartx.rules:38
# /sbin/kpartx etc/udev/rules.d/70-kpartx.rules:40
# /sbin/kpartx etc/udev/rules.d/70-kpartx.rules:42
# write_cd_rules etc/udev/rules.d/75-cd-aliases-generator.rules:4
# write_cd_rules etc/udev/rules.d/75-cd-aliases-generator.rules:6
# ipw3945d.sh etc/udev/rules.d/77-network.rules:3
# /sbin/ifup etc/udev/rules.d/77-network.rules:12
# /sbin/ifdown etc/udev/rules.d/77-network.rules:13
# /sbin/modprobe etc/udev/rules.d/80-drivers.rules:8
# /sbin/modprobe etc/udev/rules.d/80-drivers.rules:9
# /sbin/modprobe etc/udev/rules.d/80-drivers.rules:10
# /sbin/modprobe etc/udev/rules.d/80-drivers.rules:11
# /sbin/modprobe etc/udev/rules.d/80-drivers.rules:12
# /sbin/modprobe etc/udev/rules.d/80-drivers.rules:13
# /sbin/modprobe etc/udev/rules.d/80-drivers.rules:14
# /usr/sbin/pcscd etc/udev/rules.d/99-pcsc_lite.rules:4
# /usr/bin/killall etc/udev/rules.d/kino.rules:11
# the files without a path name are supposed to be in /lib/udev
cd $ROOTFS_DIR
grep -nE '(PROGRAM|RUN)' etc/udev/rules.d/* lib/udev/rules.d/* | \
sed -ne 's#\(^.*:[0-9]\+\):.*\(PROGRAM\|RUN\)[+!]\?="\([^"%\$ ]\+\).*#\3 \1#p' | \
grep -v ^socket: | \
uniq
)

# insert our module auto-loading rule
# the big and stupid problem is that some older udev versions, which we still want to support, use SYSFS{} instead of
# ATTRS{} so we have to find out how to write the rule:

# get some sysfs path with modalias in it (the printf prints it without the /sys ...)
sysfs_modalias_paths=( $(find /sys -type f -name modalias -printf "/%P\n" | sed -e 's#/modalias$##') )
# the result looks like this:
# /devices/pci0000:00/0000:00:00.0
# /devices/platform/i8042/serio1
# /devices/platform/i8042/serio0

# query the first sysfs path and choose ATTRS or SYSFS according to what *this* udev gives us
# I check for ATTR and not ATTRS because it might be either one of the two, depends on the
# sysfs path I query here and I don't predict that
if my_udevinfo -a -p $sysfs_modalias_paths | grep '{modalias}' | grep -q ATTR ; then
echo 'ACTION=="add", ATTRS{modalias}=="?*", RUN+="/bin/modprobe -v $attr{modalias}"'
else
echo 'ACTION=="add", SYSFS{modalias}=="?*", RUN+="/bin/modprobe -v $sysfs{modalias}"'
fi >>$ROOTFS_DIR/etc/udev/rules.d/00-rear.rules
ProgressStep

# udev requires certain standard groups, add them to the rescue system
# the groups and users are in rescue/default/15_users_and_groups.sh


ProgressStop

14 changes: 12 additions & 2 deletions usr/share/rear/conf/GNU/Linux.conf
Expand Up @@ -24,6 +24,8 @@ tee
awk
ip
ifenslave
ifrename
nameif
klogd
syslog-ng
syslogd
Expand Down Expand Up @@ -65,6 +67,9 @@ free
traceroute
less
vi
vim
pico
nano
rmmod
df
ls
Expand Down Expand Up @@ -95,6 +100,7 @@ mkfs.ext4dev
mkfs.jfs
mkfs.xfs
mkfs.reiserfs
mkfs.vfat
mkreiserfs
fsck.ext2
fsck.ext3
Expand Down Expand Up @@ -125,10 +131,12 @@ touch
scsi_id
logd
initctl
lspci
usleep
mktemp
/bin/true
strace
which
)

# the lib* serves to cover both 32bit and 64bit libraries!
Expand All @@ -152,7 +160,7 @@ nls_cp437
af_packet
unix
nfs
lockdd
lockd
sunrpc
cifs
usbcore
Expand All @@ -166,10 +174,12 @@ ehci_hcd
ohci_hcd
)

COPY_AS_IS=( ${COPY_AS_IS[@]} /dev /etc/protocols /etc/services /etc/rpc /etc/termcap /usr/share/terminfo /etc/netconfig /etc/*-release /lib*/firmware )
COPY_AS_IS=( ${COPY_AS_IS[@]} /dev /etc/inputr[c] /etc/protocols /etc/services /etc/rpc /etc/termcap /usr/share/terminfo /etc/netconfig /etc/mke2fs.conf /etc/*-release /lib*/firmware )
# exclude /dev/shm/*, due to the way we use tar the leading / should be omitted
COPY_AS_IS_EXCLUDE=( ${COPY_AS_IS_EXCLUDE[@]} dev/shm/\* )

# some stuff for the Linux command line
KERNEL_CMDLINE="$KERNEL_CMDLINE selinux=0"
# common users and groups
CLONE_USERS=( "${CLONE_USERS[@]}" daemon rpc )
CLONE_GROUPS=( "${CLONE_GROUPS[@]}" tty )
3 changes: 3 additions & 0 deletions usr/share/rear/conf/SUSE_LINUX.conf
@@ -0,0 +1,3 @@
# some scripts need this
COPY_AS_IS=( "${COPY_AS_IS[@]}" /etc/sysconfig/network/config /etc/sysconfig/network/scripts/functions )

13 changes: 12 additions & 1 deletion usr/share/rear/conf/default.conf
Expand Up @@ -193,6 +193,7 @@ loadkeys
kbd_mode
dumpkeys
diff
join
)

# library files
Expand All @@ -211,7 +212,7 @@ COPY_AS_IS_EXCLUDE=( dev/shm/\* )

# users and groups to copy to the rescue system
CLONE_USERS=()
CLONE_GROUPS=()
CLONE_GROUPS=(group disk cdrom floppy tape audio video lp tty dialout kmem uucp )

# time synchronisation, could be NTP, RDATE or empty
TIMESYNC=
Expand Down Expand Up @@ -456,3 +457,13 @@ RESULT_SENDMAIL_OPTIONS=( -oi -t )
#
# full path to elilo.efi file. Leave empty to use automatic search for it
ELILO_BIN=

################ ---- custom scripts
#
# NOTE: The scripts can be defined as an array to better handly spaces in parameters. The
# scripts are called like this: eval "${PRE_RECOVERY_SCRIPT[@]}"
# call this after rear did everything in the recover workflow. /mnt/local refers to the recovered system
POST_RECOVERY_SCRIPT=

# call this before rear starts to do anything in the recover workflow. You have the rescue system but nothing else
PRE_RECOVERY_SCRIPT=
30 changes: 29 additions & 1 deletion usr/share/rear/dr/GNU/Linux/12_describe_filesystems.sh
@@ -1,9 +1,37 @@
# describe all filesystems
# describe all filesystems, including the extended attributes like max mount count,
# check interval, etc.

while read mountpoint device mountby filesystem junk ; do
mkdir -p $VAR_DIR/recovery$device
vol_id $device >$VAR_DIR/recovery$device/fs_vol_id || \
Error "Cannot determine filesystem info on '$device'
Your udev implementation (vol_id or udev_volume_id) does not recognize it."
echo "$device" >$VAR_DIR/recovery$device/depends
case $filesystem in
ext*)
tmp_fs_parameters=$(mktemp $TMP_DIR/fs_parameters.XXXXXX) || \
Error "Failed creating a temporary file in $TMP_DIR."
tune2fs -l $device > $tmp_fs_parameters || \
Error "Could not run tune2fs or failed to write to $tmp_fs_parameters."
FS_RESERVED_BLOCKS=$(grep "Reserved block count" $tmp_fs_parameters | sed -e 's/^.*: \+\([0123456789]\+\).*$/\1/g')
FS_MAX_MOUNTS=$(grep "Maximum mount count" $tmp_fs_parameters | sed -e 's/^.*: \+\([-0123456789]\+\).*$/\1/g')
FS_CHECK_INTERVAL=$(grep "Check interval" $tmp_fs_parameters | sed -e 's/^.*: \+\([0123456789]\+\).*$/\1/g')

# The check interval is displayed in seconds, but tune2fs only allows us to set
# the interval in days, weeks or month. So we have to convert the seconds to days
(( FS_CHECK_INTERVAL = FS_CHECK_INTERVAL / 86400 ))
rm $tmp_fs_parameters
fs_parameters=$VAR_DIR/recovery$device/fs_parameters
> $fs_parameters || Error "Could not write to $fs_parameters"
echo "FS_RESERVED_BLOCKS=$FS_RESERVED_BLOCKS" > $fs_parameters
echo "FS_MAX_MOUNTS=$FS_MAX_MOUNTS" >> $fs_parameters
echo "FS_CHECK_INTERVAL=$FS_CHECK_INTERVAL" >> $fs_parameters
;;
*)
Log "The filesystem $filesystem on $device does not support extended filesystem"
Log "parameters like max mount count, check imterval etc. or it"
Log "is not implemented in ReaR yet"
Log "Please file a bug if you think this is an error"
;;
esac
done <$VAR_DIR/recovery/mountpoint_device
4 changes: 4 additions & 0 deletions usr/share/rear/dr/Linux-i386/31_describe_device_properties.sh
Expand Up @@ -12,6 +12,10 @@ while read device junk ; do
dd if=$device of=$VAR_DIR/recovery$device/mbr bs=446 count=1 >/dev/null || Error \
"Could not store MBR for '$device'"

# if we have udev collect also the drivers required for this device
FindDrivers $device >$VAR_DIR/recovery/$device/drivers || Error "Could not determine the required drivers for '$device'"
# NOTE: The result can be empty if we simply don't know!

done <$VAR_DIR/recovery/required_devices


32 changes: 32 additions & 0 deletions usr/share/rear/finalize/Debian/i386/17_rebuild_initramfs.sh
@@ -0,0 +1,32 @@
# rebuild the initramfs if the drivers changed
#
# probably not required, but I prefer to rely on this information when it
# is backed by udev
have_udev || return 0

# check if we need to do something
if test -s $TMP_DIR/storage_drivers && ! diff $TMP_DIR/storage_drivers $VAR_DIR/recovery/storage_drivers >/dev/null ; then
# remember, diff returns 0 if the files are the same

# merge new drivers with previous initrd modules
# BUG: we only add modules to the initrd, we don't take old ones out
# could be done better, but might not be worth the risk
INITRD_MODULES="$( sort -t " " -k 1 -u $TMP_DIR/storage_drivers /mnt/local/etc/initramfs-tools/module[s] )"
# use [] to skip file if it does not exist
# -t " " -k 1 tries to keep the comments unsorted

echo "$INITRD_MODULES" >/mnt/local/etc/initramfs-tools/modules

mount -t proc none /mnt/local/proc
mount -t sysfs none /mnt/local/sys
if chroot /mnt/local /bin/bash --login -c "update-initramfs -v -u -k all" 1>&2 ; then
LogPrint "Updated initramfs with new drivers for this system."
else
LogPrint "WARNING !!!
initramfs creation failed, please check '$LOGFILE' to see the error
messages in detail and decide yourself, wether the system will boot or not.
"
fi
umount /mnt/local/proc /mnt/local/sys

fi
52 changes: 52 additions & 0 deletions usr/share/rear/finalize/GNU/Linux/15_migrate_disk_devices.sh
@@ -0,0 +1,52 @@
# migrate disk device mappings

# skip if no mappings
test -s $TMP_DIR/mappings/disk_devices || return 0

Log "TAG-15-migrate: $DISK_DEVICE_MAPPINGS_SED_SCRIPT"

test "$DISK_DEVICE_MAPPINGS_SED_SCRIPT" || BugError "The sed script for the disk device mappings
is missing, it should be defined in verify/GNU/Linux/21_migrate_recovery_configuration.sh."

# now run sed
pushd /mnt/local >/dev/null
# the funny [] around the first letter make sure that shopt -s nullglob removes this file from the list if it does not exist
# the files without a [] are mandatory, like fstab
for file in [b]oot/{grub.conf,menu.lst,device.map} [e]tc/grub.* [b]oot/grub/{grub.conf,menu.lst,device.map} \
[e]tc/sysconfig/grub [e]tc/sysconfig/bootloader \
[e]tc/lilo.conf \
[e]tc/mtab etc/fstab \
[e]tc/mtools.conf \
[e]tc/smartd.conf [e]tc/sysconfig/smartmontools \
[e]tc/sysconfig/rawdevices \
[e]tc/security/pam_mount.conf.xml
do

# sed -i bails on symlinks, so we follow the symlink and patch the result
# on dead links we warn and skip them
# TODO: maybe we must put this into a chroot so that absolute symlinks will work correctly
if test -L "$file" ; then
if linkdest="$(readlink -f "$file")" ; then
LogPrint "Patching '$linkdest' instead of '$file'"
file="$linkdest"
else
LogPrint "Not patching dead link '$file'"
continue
fi
fi

sed -i "$DISK_DEVICE_MAPPINGS_SED_SCRIPT" "$file" ||\
Error "Patching '$file' with sed failed."
done

# we still need to modify the swap entries in /etc/fstab if byid mounting is used
# TODO: keep swap priorities and other options
if grep -q "^/dev/disk/by-id/.*swap" etc/fstab ; then
sed -i -e '/^\/dev\/disk\/by-id\/.*swap/d' etc/fstab
for swapfile in $(find $VAR_DIR/recovery -name swap_vol_id) ; do
device_dir=$(dirname $swapfile)
swap_device=${device_dir##$VAR_DIR/recovery}
echo "$swap_device swap swap defaults 0 0" >> etc/fstab
done
fi
popd >/dev/null

0 comments on commit 844d50b

Please sign in to comment.