This is script which create for listed files shadow copies and then using
hardlinks and loopback mounts create lightweight Alternative System imsge, so
normal packaging and patching will do installation as usual, but without
affecting running system.
Idea is that for shadow system image we same system files which running system
has, but for files to be changed we creates shadow copies which will be
overwritten same way LiveUpgrade doing this. Advantage is that we do not have
to copy entire system as in LU case, but only nessesary files which will be
changed. Disadvantage - we need to know what files to protect this way and we
have quite a bit of hardlinks to clean it up.
Here the scriopt I wrote with some Bart help this early January 2007. It is not
of course final, not for real use, but at least may give you idea what is going
on, what I am talking about.
------------------------
#!/bin/ksh -hp
#
# ident "@(#)patchadd.ksh 2.100 06/12/17 SMI"
#
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# Sun considers its source code as an unpublished, proprietary trade secret,
# and it is available only under strict license provisions. This copyright
# notice is placed here only to protect Sun in the event the source is
# deemed a published work. Dissassembly, decompilation, or other means of
# reducing the object code to human readable form is prohibited by the
# license agreement under which this code is provided to the user or company
# in possession of this copy.
#
# RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the Government
# is subject to restrictions as set forth in subparagraph (c)(1)(ii) of the
# Rights in Technical Data and Computer Software clause at DFARS 52.227-7013
# and in similar clauses in the FAR and NASA FAR Supplement.
#
list_of_files_to_save=list_of_files_to_save
list_of_directories_to_save=list_of_directories_to_save
sorted_list_of_directories_to_save=sorted_list_of_directories_to_save
list_of_files=list_of_files
sorted_list_of_files=sorted_list_of_files
list_of_subdirectories=list_of_subdirectories
sorted_list_of_subdirectories=sorted_list_of_subdirectories
#list_of_symlinks_to_copy=list_of_symlinks_to_copy
list_of_files_to_link=list_of_files_to_link
list_of_subdirectories_to_mount=list_of_subdirectories_to_mount
rm $list_of_files_to_save
rm $list_of_directories_to_save
rm $sorted_list_of_directories_to_save
rm $list_of_files
rm $sorted_list_of_files
rm $list_of_subdirectories
rm $sorted_list_of_subdirectories
#rm $list_of_symlinks_to_copy
rm $list_of_files_to_link
rm $list_of_subdirectories_to_mount
# parameter - list of patches
# 1 Create list of files need to be changed
nawk '/^Files included with this patch/{on=1; continue}/^Problem
Description/{on = 0; continue;} {if (on ==1 && NF > 0)print $0}' $*/README* | \
sort > $list_of_files_to_save
# 2 Create list of affected directories
cat $list_of_files_to_save | \
while read file ; do
dirname $file >> $list_of_directories_to_save
done
sort -u $list_of_directories_to_save > $sorted_list_of_directories_to_save
# 3 Create shadow directory inside each affected directories
cat $sorted_list_of_directories_to_save | \
while read directory ; do
# 4. Create a list of affected directories files
for file in $directory/* ; do
if [ -f $file ] ;
then echo $file >> $list_of_files
fi
done
# 5. Create a list of affected directories directories
# list_of_content_subdirectories
for file in $directory/* ; do
if [ -d $file ] ;
then echo $file >> $list_of_subdirectories
fi
done
# 6. Create a list of affected directories symbolic links
# list_of_content_symlinks
# for file in $directory/* ; do
# if [ -h $file ] ;
# then echo $file >> $list_of_symlinks_to_copy
# fi
# done
mkdir $directory/shadow
done
# 7. Substract list_of_files_to_change from list_of_content_files
sort $list_of_files > $sorted_list_of_files
comm -23 $sorted_list_of_files $list_of_files_to_save > $list_of_files_to_link
# 8. Substract list_of_directories_to_change from list_of_content_subdirectories
sort $list_of_subdirectories > $sorted_list_of_subdirectories
comm -23 $sorted_list_of_subdirectories $sorted_list_of_directories_to_save >
$list_of_subdirectories_to_mount
# 9. Hardlink files into shadow directories
echo Hardlink existing files into shadow directories
cat $list_of_files_to_link | \
while read file ; do
ln $file `dirname $file`/shadow/`basename $file`
done
# 10 Copy files to shadow directories
echo Copy list to be saved to shadow directories
cat $list_of_files_to_save | \
while read file ; do
cp $file `dirname $file`/shadow/`basename $file`
done
# 11 Copy list_of_files_to_change to shadow directories
#echo Copy symlinks to shadow directories
#cat $list_of_symlinks_to_copy | \
#while read file ; do
# cp $file `dirname $file`/shadow/`basename $file`
#done
# 15 Loopbackmount subdirectories
echo Loopbackmount subdirectories to shadow directories
cat $list_of_subdirectories_to_mount | \
while read directory ; do
mount_point=`dirname $directory`/shadow/`basename $directory`
echo mkdir $mount_point
mkdir $mount_point
echo mount -F lofs $directory $mount_point
mount -F lofs $directory $mount_point
done
# 12 Loopback mount / to /sandbox
echo Loopback mount / to /sandbox
mkdir /sandbox
mkdir /sandbox-root
mount -F lofs / /sandbox
# 13 Loopback mount / to /samdbox/root
echo Loopback mount / to /samdbox/root
mount -F lofs / /sandbox/sandbox-root
# 14 Loopback mount shadow directories to their corresponding places
# in /sandbox (based on list_of_directories_to_change
echo Loopback mount shadow directories to their corresponding places
cat $sorted_list_of_directories_to_save | \
while read directory ; do
echo mount -F lofs $directory/shadow /sandbox$directory
mount -F lofs $directory/shadow /sandbox$directory
done
echo chroot /sandbox /usr/sbin/patchadd -R /sandbox-root /toxic_test/121430-09
-------------------------------------------------
I think this may be pretty valuable in case when some limited number of changes
need to be deployed on running system. And then by reboot this changes may by
flashed into real place.
vassun
This message posted from opensolaris.org