Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

Easier Reinstalls


I typically reinstall my computer operating system every six months. The reasons for this are that it cleans out the system and reinstalls require me to be in front of the computer for a total of about ten minutes so it’s painless. Notice I said “in front of the computer”, the system does all of the work for me with some specially crafted bash scripts.

If you ever need to reinstall your Linux system, the best thing you can do right now is some homework. Write yourself some bash scripts that will automate much of the work for you. This way you won’t have to spend so much time in front of the computer during the reinstall. I usually start the install process, go watch a movie, then run some bash scripts when the installer is done and grab a bite to eat while the scripts do the work for me. I don’t even bother logging into xorg until all of the scripts are done. I simply log into tty1, run the system script and go back to my movie.

I keep most of my packages, documents, etc., on a second hard drive but these files could also be kept on cd/dvd, have the system script mount the volume and let the scripts pull in the needed files from the mount point.

 

System Script

The system script should contain commands that modify system settings and content. You’ll notice that this script doesn’t contain any apt-get commands. The reason for this is that I believe the superuser should be present and keep an eye on any software application packages that are installed or removed in case fine tuning needs to be done. Of course, others are free to run their systems as desired.

Keep in mind that this script is only an example to show that some of the needed work can automated without requiring you to be at the computer. My system script is much more detailed than the below script, you should edit your script as needed.

#!/bin/bash

# check for admin rights; needed to run this script
if [ $UID != 0 ]
then
exit
fi

# make backups of important system files in case of mistakes
mkdir /etc/master_copies
cp /boot/grub/menu.lst /etc/fstab /etc/apt/sources.list /etc/sudoers /etc/X11/xorg.conf /etc/master_copies

# create directories needed for future use
mkdir /mnt/sdb1 /mnt/iso

# mount needed file systems
mount /dev/sdb1 /mnt/sdb1

# edit files as needed
cat /mnt/sdb1/system-files/fstab-entries >> /etc/fstab

# comment out ssh agent in Xsession.options
sed 's/use-ssh-agent/# use-ssh-agent/g' /etc/X11/Xsession.options

# add additional software sources
cat /mnt/sdb1/system-files/sources.list >> /etc/apt/sources.list

# install themes for system-wide use
dpkg -i /mnt/sdb1/packages/my-theme.deb /mnt/sdb1/packages/my-icons.deb
cp /mnt/sdb1/graphics/wallpapers/* /usr/share/backgrounds

# clean up the system
apt-get clean
updatedb

#done
exit

That’s it for the system script. When I return, the system should be ready for any apt-get commands I need to run. I can then verify the list of software to be installed, begin the installation and let the system does what it needs to do.

Making backups of important files is a vital step. I cannot tell you the number of times this step has saved my backside after making mistakes editing xorg.conf. I’m still not sure why most distros don’t include a step like this in their installers, it would save a lot of time and frustration with new linux users. Retrieving a missing sources.list file is as easy as mounting the file system in a LiveCD and copying the file from master_copies to its original location.

User Script

This script should contain commands that modify only the settings and content in $HOME. Again, this script is only an example to show that some of the needed work can automated without requiring you to be at the computer. My user script is much more detailed than the below script, you should edit your script as needed.

#!/bin/bash

# make sure we're in $HOME
cd $HOME

# make backups of important user files
mkdir .master_copies
cp some-file .master_copies

# copy needed files to $HOME
mkdir -p Documents
cp -r /mnt/sdb1/office-files/* Documents
cp -r /mnt/sdb1/settings/GNUstep .

# make needed symlinks
ln -s /dev/null .adobe
ln -s /dev/null .macromedia

# install themes
tar -xzf /mnt/sdb1/packages/infinity-theme.tar.gz .themes
tar -xzf /mnt/sdb1/packages/infinity-icons.tar.gz .icons
tar -xzf /mnt/sdb1/packages/myfonts.tar.gz .fonts

# tweak desired settings
gconftool-2 --type string --set /apps/metacity/general/theme "Infinity"
gconftool-2 --type string --set /desktop/gnome/interface/gtk_theme "Infinity"
gconftool-2 --type string --set /desktop/gnome/interface/font_name "MyFont 12"
gconftool-2 --type bool --set /apps/nautilus/desktop/home_icon_visible true
gconftool-2 --type bool --set /apps/nautilus/preferences/always_use_location_entry true
gconftool-2 --type integer --set /apps/panel/toplevels/bottom_panel_screen0/size 24
gconftool-2 --type integer --set /apps/panel/toplevels/top_panel_screen0/size 24

# done
exit

That’s it for the user script. The system reinstall should be complete and configured to my tastes and I can now reboot the system. Once the reboot is done, the system is ready for me to use and I spent a total of about ten minutes in front of the computer thanks to a couple of specially crafted bash scripts.

The gconftool-2 command comes in very handy here and can aid in setting up the system to meet the needs of the user. In fact, I don’t even bother with the gconf-editor anymore unless I need to track down a key because this method is much faster than using the GUI. More information about gconftool-2 commands and switches can be found in:

man gconftool-2

Comments

comments