There are lots of threads asking about how to safely upgrade, and there are lots of posts giving instructions that work for some people but not others. This is intended to be a "once and for all" solution, both for major upgrades and for security patches. Several posts describe security patches as safe to apply, but many people still report problems. The procedure described below will make sure your system still works. It's not necessary when installing regular program updates, like Safari 3.1.1, only system updates and security patches. I have successfully installed the 10.4.11 update from a 10.4.8 system, and security patches 2008-02 and 2008-03, using this procedure. And I now have a 100% working up-to-date system.
There are two shell scripts that need to be created, "backup.sh" and "restore.sh" which, as the names imply, backup critical system components on your current installation and then restore those components after an upgrade.
ONE-TIME SETUP
First, you need to create a backup directory and put the backup and restore scripts in that directory. This only needs to be done once. Thereafter, installing an update is as simple as running two scripts. A good place for the backup directory is in your home directory, so open a terminal and do the following:
CODE
cd ~
sudo -s
{enter password}
mkdir sys_backup
cd sys_backup
sudo -s
{enter password}
mkdir sys_backup
cd sys_backup
You can, of course, use a different directory name and location (the scripts only operate within the directory in which they are executed). Still in the terminal window, type:
CODE
nano backup.sh
Now, copy the following code and paste it into the nano editor (to paste within nano, right-click and select Paste):
backup.sh:
CODE
#!/bin/sh
# --------
echo Backing up kernel ...
cp -p /mach_kernel ./
# --------
echo Backing up kernel extensions, bundles, plugins ...
if [ ! -d system.library.extensions ]
then
echo Creating backup system.library.extensions directory ...
mkdir system.library.extensions
fi
cp -Rp /System/Library/Extensions/* system.library.extensions/
# --------
echo Backing up loginwindow.app ...
if [ ! -d system.library.coreservices ]
then
echo Creating backup system.library.coreservices directory ...
mkdir system.library.coreservices
fi
cp -Rp /System/Library/CoreServices/loginwindow.app system.library.coreservices/
# --------
echo Backing up profiler reporters ...
if [ ! -d system.library.systemprofiler ]
then
echo Creating backup system.library.systemprofiler directory ...
mkdir system.library.systemprofiler
fi
cp -Rp /System/Library/SystemProfiler/* system.library.systemprofiler/
# --------
echo Backing up configuration bundles ...
if [ ! -d system.library.systemconfiguration ]
then
echo Creating backup system.library.systemconfiguration directory ...
mkdir system.library.systemconfiguration
fi
cp -Rp /System/Library/SystemConfiguration/* system.library.systemconfiguration/
echo All done!
# --------
echo Backing up kernel ...
cp -p /mach_kernel ./
# --------
echo Backing up kernel extensions, bundles, plugins ...
if [ ! -d system.library.extensions ]
then
echo Creating backup system.library.extensions directory ...
mkdir system.library.extensions
fi
cp -Rp /System/Library/Extensions/* system.library.extensions/
# --------
echo Backing up loginwindow.app ...
if [ ! -d system.library.coreservices ]
then
echo Creating backup system.library.coreservices directory ...
mkdir system.library.coreservices
fi
cp -Rp /System/Library/CoreServices/loginwindow.app system.library.coreservices/
# --------
echo Backing up profiler reporters ...
if [ ! -d system.library.systemprofiler ]
then
echo Creating backup system.library.systemprofiler directory ...
mkdir system.library.systemprofiler
fi
cp -Rp /System/Library/SystemProfiler/* system.library.systemprofiler/
# --------
echo Backing up configuration bundles ...
if [ ! -d system.library.systemconfiguration ]
then
echo Creating backup system.library.systemconfiguration directory ...
mkdir system.library.systemconfiguration
fi
cp -Rp /System/Library/SystemConfiguration/* system.library.systemconfiguration/
echo All done!
CTRL+O will save the file and CTRL+X will exit nano. To make sure the script is executable (or else you won't be able to run it) type this command:
CODE
chmod +x backup.sh
Now we need the restore script.
UPDATED 2008/6/28. Now disables kexts that may have previously been removed by the user, but have been re-installed by the upgrade/patch.
CODE
nano restore.sh
Copy the following code and paste it into the nano editor:
restore.sh:
CODE
#!/bin/sh
# --------
echo Restoring kernel ...
if [ ! -f ./mach_kernel ]
then
echo Backup of mach_kernel does not exist. Execute backup.sh first. You are probably screwed.
exit
fi
cp -p ./mach_kernel /
# --------
echo Restoring kernel extensions, bundles, plugins ...
curr_dir=$PWD/system.library.extensions
cd /System/Library/Extensions
for file in *
do
if [ -e "$curr_dir/$file" ]
then cp -Rp "$curr_dir/$file" /System/Library/Extensions/
else
echo Disabling "$file"...
mv "$file" "$curr_dir/$file_disabled"
fi
done
cd $curr_dir/..
# --------
echo Restoring loginwindow.app ...
cp -Rp system.library.coreservices/* /System/Library/CoreServices/
# --------
echo Restoring configuration bundles ...
cp -Rp system.library.systemconfiguration/* /System/Library/SystemConfiguration/
# --------
echo Restoring profiler reporters ...
cp -Rp system.library.systemprofiler/* /System/Library/SystemProfiler/
# --------
echo Cleaning kernel extensions cache ...
rm /System/Library/Extensions.mkext
rm /System/Library/Extensions.kextcache
# --------
echo Repairing disk permissions ...
diskutil repairPermissions /
echo All done!
# --------
echo Restoring kernel ...
if [ ! -f ./mach_kernel ]
then
echo Backup of mach_kernel does not exist. Execute backup.sh first. You are probably screwed.
exit
fi
cp -p ./mach_kernel /
# --------
echo Restoring kernel extensions, bundles, plugins ...
curr_dir=$PWD/system.library.extensions
cd /System/Library/Extensions
for file in *
do
if [ -e "$curr_dir/$file" ]
then cp -Rp "$curr_dir/$file" /System/Library/Extensions/
else
echo Disabling "$file"...
mv "$file" "$curr_dir/$file_disabled"
fi
done
cd $curr_dir/..
# --------
echo Restoring loginwindow.app ...
cp -Rp system.library.coreservices/* /System/Library/CoreServices/
# --------
echo Restoring configuration bundles ...
cp -Rp system.library.systemconfiguration/* /System/Library/SystemConfiguration/
# --------
echo Restoring profiler reporters ...
cp -Rp system.library.systemprofiler/* /System/Library/SystemProfiler/
# --------
echo Cleaning kernel extensions cache ...
rm /System/Library/Extensions.mkext
rm /System/Library/Extensions.kextcache
# --------
echo Repairing disk permissions ...
diskutil repairPermissions /
echo All done!
CTRL+O to save, CTRL+X to exit. Again make sure the script is executable:
CODE
chmod +x restore.sh
You now have everything in place to perform all updates in the future.
BACKING UP YOUR SYSTEM
Before you upgrade or apply a security patch, run the backup script. NOTE: You must "sudo -s" before running the scripts since the files involved are owned by root:wheel. I was tempted to put the sudo command in the script itself, but I decided it was better to sudo manually so that you know you're about to change system files. Open a terminal, sudo, cd to your sys_backup directory, and run backup.sh:
CODE
sudo -s
{enter password}
cd ~/sys_backup
./backup.sh
{enter password}
cd ~/sys_backup
./backup.sh
The script will display the steps it is performing while backing up the critical components. IF YOU SEE AN ERROR MESSAGE, DO NOT CONTINUE UNTIL YOU'VE RESOLVED THE PROBLEM. Most likely you didn't copy/paste the scripts properly, or if you input them by hand there's a typo. If you've followed the one-time setup procedure exactly, you should not get any errors, so double-check that you've done everything right before you post problems in this thread.
When the script completes, you now have all your system critical components backed up and are ready to upgrade. You may want to copy your sys_backup folder to a memory stick or external drive, just to be on the safe side. It's called a Hackintosh for a reason.
UPDATE PROCEDURE
Leave the Terminal window open, start the Software Update tool and click "Check Now". At this point, you want to update the system, not individual programs, so uncheck everything except the update you're installing. Let the system perform the upgrade, but DO NOT CLICK THE RESTART BUTTON. This is very important (which is why it's bold, CAPITALIZED, and red). You do not want the system to reboot into an upgraded kernel, because that will mean certain death 99% of the time. Leave that window as it is, waiting for you to click Restart, and go back to the terminal to run the restore script:
CODE
./restore.sh
This script restores your critical components, clears the kext cache, and repairs disk permissions. It will display the steps as it goes, and when disk permissions are being repaired you may get a whole slew of output. This is normal and means that some permissions were repaired. When the script is done, go back to the Software Update window and click Restart.
This backup/update/restore procedure can be followed for the security patches as well. As I said, some people have reported no problems installing a security patch without doing anything fancy, but I got a Gray Screen Of Death several times trying to install the 2008-02 security update before I settled on this procedure.
CONCLUSION
Once you have done your one-time setup, upgrading (or installing a security patch) is as simple as:
1) sudo -s, then run backup.sh
2) Install the upgrade/patch but DO NOT RESTART yet
3) run restore.sh, then Restart
Technically, you should only have to run the backup script once, so the process boils down to just the last two steps. However, I recommend running the backup script every time, since it is possible that your backup files may have accidentally been deleted or altered in some way during your day-to-day work (though not likely).
Some people may note that the backup script backs up more files than are really necessary; however, I found out the hard way that it is difficult to determine in advance which files you really need to back up for a particular update. Better safe than sorry, as they say.
