After following the long thread about the best way to utilize a
single partition for both linux and Windoze, I have finally
reached what I think is a near ideal situation. Thanks especially
to Joerg Prust both via c.o.l. and email.
The basic idea that Joerg suggested is what I'm using: create the
windows swap file taking the whole partition, figure out how many
sectors are used up by the fat and the first entry in it and save
those to a file. Boot linux, run mkswap, and save the same number
of sectors.
Now, what needs to be done is a way to install the
proper set of sectors to the partition at boot time. This is
where we differ. The debug script that he suggested did not work
for me, because DOS refused to do anything except format the drive
after it had been used by linux. Instead, I decided to make the
restoration of the sectors the job of linux (the owner of the
computer is a dos weenie anyway, and we often don't use the
autoexec.bat on boot). Then I "modified" /etc/shutdown and
/etc/rc to handle everything.
Here's a by-the-numbers explanation of what I did:
1) on an empty, dos formatted partition (this one created using fips,
a safe partition splitter), create a "permanent" swap file for
Windoze.
2) determine the number of sectors that need to be saved. From an
email message from Joerg: (joerg: hope you don't mind...)
>The tricky part is the number of sectors you want to write, or want
>to read if you create your sector files in the first place.
>You have to know how many FAT-sectors (FileAllocationTable) your disk
>uses, 'cos following those comes the Root (\) directory sector, up to
>which you have to save the sectors.
>There are utilities which can give you this information for your disk,
>i.e. 'InfoPlus' or 'Fat' which you can obtain from wuarchive.wustl.edu.
>In InfoPlus on Page 16 (Boot & DOS drive parameters) you are
>told your 'Root directory sector' of your disks, this is the offset of
>that sector (i.e. 13 for my disk).
>'Fat' calls that 'First dir sector'. This number, incremented by one,
>is the number of sectors you have to save from your swap partition.
I used "fat d: /i" to get the information. for me it was 26
3) boot linux and save the sectors in /etc/dos.sec (season to taste) using
dd. For me, it was
dd if=/dev/hdb2 of=/etc/dos.sec bs=512 count=26
change count to the number of sectors det. above, if to the device
that will be your swap partition
4) run mkswap
5) save the same number of sectors into a different file (/etc/linux.sec)
ex:
dd if=/dev/hdb2 of=/etc/linux.sec bs=512 count=26
Now, the trick is to make sure that the correct sectors are there on
startup, and that the Windoze files are restored at shutdown. The
first part is trivial. From my /etc/rc:
---begin rc excerpt---
/bin/echo restoring swap partition...
/bin/dd if=/etc/linux.sec of=/dev/hdb2 bs=512 count=26 ||
/bin/echo restoration failed
/etc/swapon -a
---end rc excerpt
note that the if= and of= are switched from when we were
saving sectors. This is of course obvious, but strikes me as
a rather simple "silly mistake" that can make life
difficult.
Shutdown provided a tougher problem. What I eventually decided to
do was move /etc/shutdown to /etc/.shutdown (/etc/shutdown.exe is
another reasonable alternative) and replace /etc/shutdown with a
sh script. The sh script simply restores the Windoze sectors to
the swap device, after checking the argument number to see if
possibly the intent is to go single user. Then /etc/.shutdown is
called. Two notes here: make sure that the script has perms 500
or maybe 550; also, I'm using the sysvinit package, so I don't
know if the way I check arguments is valid for other shutdowns.
Here's my /etc/shutdown:
---begin shutdown
#!/bin/sh
if test $# -ge 2
then
echo restoring Windoze swap file...
/bin/dd if=/etc/dos.sec of=/dev/hdb2 bs=512 count=26
fi
exec /etc/.shutdown $*
---end shutdown
In my inittab there's an entry to deal with "power fail." It
didn't need any changes at all, because I decided to call my
script shutdown rather than something like "quit." If you use
halt or reboot directly, obviously things don't get restored. But
if you habitually use them, then I don't feel any sympathy for you
:)
For os/2, I'm sure something similar could be done. The main
decision would be to determine: what state should we be in
when the power is off. I chose dos, both because it's not my
computer, and things worked easier that way. If os/2 can
configure the shutdown procedure and has something like dd, then I
would suggest that it be responsible for restoring things it's way
when done.
I have had no problems at all with the above set-up. To protect
myself, though, I have a boot/root floppy that does the following:
fsck all partitions, restore Windoze swap partition from it's own
copy of dos.sec, re-install lilo (my MBR), reboot. Any better
suggestions would be great, although this strikes me as quite
clean as is.
Thanks again to Joerg, and anyone else who contributed useful
ideas to the net...
--
Maurice S. Barnum --- I consult, therefore I am:
Ask me, and I shall answer.
Believe me, and I shall laugh.