The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

If you buy from Amazon USA, please support us by using this link.
Scripts / handy tips
 New Topic  |  Go to Top  |  Go to Topic  |  Search  |  Log In   Newer Topic  |  Older Topic 
 Ensure that your hibernating XP partition is read-only
Author: Peter S. Housel 
Date:   23-07-03 19:04

I dual-boot my laptop between FreeBSD 5.1-CURRENT and Windows XP Professional. I've found through bitter experience that a sure
recipe for lost files is to:

1. Boot into XP, then hibernate it.
2. When starting the machine again, boot into FreeBSD.
3. Mount XP's FAT partition read-write, and write some files.
4. Reboot and resume XP.

XP's in-memory cache now no longer matches what's on the disk,
resulting in cross-linked files and other filesystem corruption.

To avoid this, I now mount my FAT filesystem read-only by default:

# Device Mountpoint FStype Options Dump Pass#
/dev/ad0s1 /dos/c msdos ro 0 0

To re-mount it as read-write when it is safe, I placed the
following file in /usr/local/etc/rc.d:

case "$1" in
if /usr/local/sbin/hiberfil; then
/sbin/mount -u -o rw /dev/ad0s1

I found through experimentation that when XP is not hibernating,
the first 4K of C:\hiberfil.sys is all zeroes. The
/usr/local/sbin/hiberfil script performs this check:


open(HIBERFIL, "</dos/c/hiberfil.sys") || exit 0;

my $sector = '';
if(sysread(HIBERFIL, $sector, 4096) != 4096) {
exit 0;

if ($sector eq ("\0" x 4096)) {
exit 0;
} else {
exit 1;

Reply To This Message
 Re: Ensure that your hibernating XP partition is read-only
Author: Peter S. Housel 
Date:   26-07-03 23:54

Oops... unescaped angle brackets messed up the perl script. The open(HIBERFIL, ...) line should read:

open(HIBERFIL, "</dos/c/hiberfil.sys") || exit 0;

Reply To This Message
 Forum List  |  Threaded View   Newer Topic  |  Older Topic 

 User Login
 User Name:
 Remember my login:
 Forgot Your Password?
Enter your email address or user name below and a new password will be sent to the email address associated with your profile.
How to get the most out of the forum