Journal hazem's Journal: Linux/Windows Auto Rebuilder
October 19th, 2004
Hello!
After posting about creating an auto-re-imaging system using Linux to keep Windows running nicely, I got a lot of responses. (The article was "Spyware/Adware Prevention In Large Deployments?"). I mailed the following to several people and posted it as a reply to my own comments.
http://slashdot.org/comments.pl?sid=126181&cid=10561793
I just wrote up this document, and put the files inline within it. It should be clear how to snip them to make the individual files.
I'd release this under the GPL, but darn, it just doesn't seem like there's enough there to bother. I mean... can you really GPL some config scripts?
I found it helpful to configure the Linux stuff on one computer, then using a bootable Linux CD (I didn't want the local box slowed down by unnecessary services like networking), I put it on a server, called lin.tgz. I then booted on another machine with the bootable cd, and applied it to the
Good luck!
Hazem
hazem-dli at google's mail service
Linux Rebuilder
Write-up version 0.1, 19 October 2004, 4:17AM
This set of tools helps automate the process of keeping a Windows box with a consistent image. It works similarly to "Deep Freeze" by storing an image of the Windows system and all its software on a Linux partition. The computer boots into Linux, which restores this image to the Windows partition (overwriting whatever the user did before). It then reboots into Windows.
** Installing/Setup **
The scripts as I have written them use tar/gzip to make the image of the Windows partition. This is because I was working on Win98 boxes that use FAT32 (which Linux can easily read and write). Linux does not yet reliably write NTFS, so to use this on an NTFS based Windows system, such as Windows 2000, or Windows XP, the scripts will need to be rewritten using dd/gzip rather than tar/gzip.
Here are the basic steps:
1) Install Windows on your computer. If you are using one drive, partition that drive in half (or, if you know how much space you'll need, just a little more than that - make sure you leave enough room on the remaining partition for your linux install (as little as 50MB, and room for the compressed image of your windows image). Install all your applications and customize the Windows "image" so that it is exactly the way you want it to be each time you reboot.
2) Install some Linux version on the other half. Keep it small, since you won't need networking, X, or much else.
3) Create a
4) Modify
5) Modify
6) Create a
For FAT32 systems using tar/gzip, you'll need to add an entry to your
** Useful Points **
There are two main keys to why this thing works pretty well. First, lilo can invoke the same kernel with different options. The menu options I place in lilo.conf do this. The other key is contained in the win_reboot file. By invoking lilo with the -R option followed by a boot label, (eg. "lilo -R Windows"), lilo will override its default boot option on the next reboot.
There are two other nice features that work nicely. The first one is that while the kernel is loading, the keyboard cannot interrupt the process. This is great for keeping someone from hijacking the system. The second is that by putting the line "password=""" in lilo.conf will password protect the boot options that do not have a "bypass" in them. This allows the user to do some things, like boot directly into Windows, or even rebuild the Windows partition, but not make a new image of the Windows partition.
If you're going to do a dd/gzip option, you'll want to wipe your Windows partition's empty space. From the documentation for g4u, there is a link to a program called nulfile, which will fill up the empty space with 0's. http://www.feyrer.de/g4u/
(If you like imaging, check out g4u, since it has many options that are similar to Norton Ghost. It may even work to replace what I've done here, but I'm not sure.)
** How it Works **
There are several lilo boot options that come up when the computer boots. They are fairly self explanatory.
auto_rebuild: default - it goes to Linux and if rebuild is set, it rebuilds window and then reboots directly into Windows
Windows: boots directly into Windows
rebuild_win: allows someone to force a rebuild of Windows without rebooting directly into it
get_image: takes an image of what is currently on the Windows drive. This will become the new image that rebuilds are based on
auto_on: turns ON autotmatic rebuilds
auto_off: turns OFF automatic rebuilds
Some options are password protected. The password for these options is set by running lilo. It will prompt for the password and store it in a hashed form. One can put the actual password in plaintext in the lilo.conf, but I prefer a bit of secrecy here!
1) Basically, the computer boots up to lilo, which then launches the "auto_rebuild" option.
2) From
3) If it was "auto_rebuild", it checks to see if the file
4)
** Updating the Windows Software **
To install new software/updates to Windows, do the following:
1) do a "rebuild_win" go get to a known state
2) to an "auto_off" so that work isn't lost while rebooting during
3) updates and installs
4) boot direclty into Windows to install software and updates as needed
5) when the computer is reconfigured, reboot and choose "get_image"
6) reboot and select "auto_on". The computer will now re-image itself on reboot with the new settings.
** Cautionary Tales **
The only caveat is not to install anything that tweaks the partitions, such as the boot locker on Foolproof. Other foolproof stuff CAN be installed, though. So, you may consider installing Foolproof without bootlock, and then set the rebuilder for manual-only rebuilds.
The only other caveat is that you will want to turn off any auto update features in any of the software (Windows, AV, Spyware, etc). Each time the system is rebuilt, these softwares will try to re-update.
A nice improvement would be to allow the system to have the option of creating multiple Windows images to allow roll-backs, particularly if there was an error while creating the image. As it stands now, if it crashes while doing a "getimage", your only rescue is that the Windows partition should still be in good shape, and you can try again.
** Removing the Rebuilder **
First, to remove this system (or just totally disable it), boot up onto a Windows bootable floppy (or Windows install CD) that has fdisk on it. Just type: fdisk
If it then tries to boot into Linux instead, boot up on the same disk, use fdisk, and make sure the "active partition" is the Windows one.
This still leaves the Linux stuff in there, but it just gets bypassed. To get rid of that, you'll need to use a partitioning tool that will allow you to delete the Linux partition and then expand the Windows partition. I believe Partition Magic will do this.
** The Files **
File:
Notes: If your system is not set up on hda, you'll need to make more changes to this. It expects Windows on hda1, and your Linux installed on hda2
---- start lilo.conf ----
# LILO configuration file
# generated by 'liloconfig'
#
# Start LILO global section
boot =
#compact # faster, but won't work on all systems.
password=""
prompt
timeout = 50
# Normal VGA console
vga = normal
# Linux bootable partition config begins
image =
root =
label = AutoRebuild
append="auto_rebuild"
read-only # Non-UMSDOS filesystems should be mounted read-only for checking
bypass
# Linux bootable partition config ends
# DOS bootable partition config begins
other =
label = Windows
table =
bypass
# DOS bootable partition config ends
# Linux bootable partition config begins
image =
root =
label = Rebuild
append="rebuild_win"
read-only # Non-UMSDOS filesystems should be mounted read-only for checking
bypass
# Linux bootable partition config ends
# Linux bootable partition config begins
image =
root =
label = Get_Win
append="get_image"
read-only # Non-UMSDOS filesystems should be mounted read-only for checking
# Linux bootable partition config ends
# Linux bootable partition config begins
image =
root =
label = Auto-on
append="auto_on"
read-only # Non-UMSDOS filesystems should be mounted read-only for checking
# Linux bootable partition config ends
# Linux bootable partition config begins
image =
root =
label = Auto-off
append="auto_off"
read-only # Non-UMSDOS filesystems should be mounted read-only for checking
# Linux bootable partition config ends
# Linux bootable partition config begins
image =
root =
label = Linux
read-only # Non-UMSDOS filesystems should be mounted read-only for checking
# Linux bootable partition config ends
---- end lilo.conf ----
File:
Notes: This might have more stuff for your system, so you're really only concerned about the last line that invokes
---- start rc.local ----
#!/bin/sh
#
#
#
# Put any local setup commands in here:
cat
#invoke the rebuilder script
---- end rc.local ----
File:
Notes: This is the script that gets the Windows partition. It is written for Windows98, which uses FAT32. Since Linux can reliably read/write FAT32, I do some clean-up stuff, such as deleting temp files. You can't do this win Windows XP, and you will need to change from using tar/gzip to using dd/gzip
---- start getimage ----
#!/bin/bash
echo Creating new image file
echo
# if an image already exists, provide 10 seconds before the image is
# over-written
if [ -e
then
echo You have 10 seconds to hit ctrl-c and stop the regetting process
sleep 10
fi
#
# Skip these rm statements if you are using NTFS based systems
#
#swapfile is big and doesn't need to be backed up
rm
#also cleanup some other files
rm
rm -rf
rm -rf
rm -rf
rm
rm
rm
#get the boot sector of the partition
dd if=/dev/hda1 of=/image/bootsector.img bs=512 count=1
#create tgz archive of the Windows partition
#
# for NTFS, you would change this to something like:
# dd if=/dev/hda1 bs=8192|gzip -c >
# just make sure your image file name matches what is in putimage
tar cvzf
---- end getimage ----
File:
Notes: This is the script that puts the image back on the Windows partition. It's the complement to getimage. Again, it is written for Windows98, which uses FAT32. Since Linux can reliably read/write FAT32, I do some clean-up stuff, such as deleting all the files on the Windows partition. You can't do this win Windows XP, and you will need to change from using tar/gzip to using dd/gzip
---- start putimage ----
#!/bin/bash
echo Rebuilding Windows drive
echo
# if there is a command line arugment ("no sleep"), we go right into
# rebuilding. Otherwise, we give a 10 sec grace period!
if [ -z "$1" ]
then
echo You have 10 seconds to hit ctrl-c and stop the rebuild process
sleep 10
fi
if [ -e
then
# you can't do this if you're using NTFS - just skip it, since it's not necessary
#delete existing Windows
rm -rf
# with NTFS, this can be skipped too, since it's redundant
#restore the boot sector of the partition
dd of=/dev/hda1 if=/image/bootsector.img bs=512 count=1
# for NTFS, you'd need to change this to (based on getimage above)
# gunzip -c
#restore the Windows files
(cd
echo Windows drive rebuilt
else
echo
echo WARNING!
echo There was no image to rebuild from.
echo Try using "getimage"
fi
---- end putimage ----
File:
Notes: This script is called from
---- start reubilder ----
#!/bin/bash
# this is the main script for the Windows image rebuilder
# it is evoked from
#
# it looks at the kernel options set by lilo to determine the action
# look to see if we should rebuild Windows
if grep -q auto_rebuild
then
# we should automatically rebuild Windows
if [ -e
then
#echo I would rebuild Windows because the auto_rebuild_on exists
else
echo Did nothing: Auto-Rebuild currently turned off.. booting Windows
sleep 10
fi
elif grep -q rebuild_win
then
# we SHOULD rebuild Windows
#echo rebuild Windows
echo Rebooting to Windows in 10 seconds. Press ctrl-c to abort.
sleep 10
elif grep -q get_image
then
# we should get the current Windows drive as the new image
#echo get new image
elif grep -q auto_on
then
# we should set the auto-rebuild to ON
echo CAUTION: Set Auto-Rebuild to ON
touch
elif grep -q auto_off
then
# we should set the auto-rebuild to OFF
echo Set Auto-Rebuild to OFF
rm
else
# we don't do anything special - just go into Linux
echo booting into Linux.
fi
---- end rebuilder ----
File:
Notes: This is called to make lilo bypass its default and go directly into Windows.
---- start win_reboot ----
#!/bin/sh
#
# This overrides lilo's default boot option and forces the next reboot
# into the Windows drive
lilo -R Windows
---- end win_reboot ----
Linux/Windows Auto Rebuilder More Login
Linux/Windows Auto Rebuilder
Slashdot Top Deals