michielovertoom.com

Dualbooting Windows and FreeBSD • 16 May 2010

It's possible to prepare a harddisk in such a way that both Windows and FreeBSD can reside on it. At boot time, the FreeBSD bootmanager menu can be used to choose which operating system to start.

Since Windows always installs a MBR, it has to installed first, and FreeBSD second. We let FreeBSD install its own MBR, overwriting the one Windows put there.

It is also possible to use the Windows boot loader to choose which operating system to start, but that is slightly more difficult and needs BootPart, and not discussed in this article.

The reason I did this was because I wanted to use a SSD in my laptop, with a big Windows partition and a smaller FreeBSD one.

First, I booted the Windows XP installation CD and used its partition manager to delete all existing partitions on the SSD, which can hold 80GB in total. I then created one partition for Windows, size 56 GB. I let the installer put Windows on this, and after installation I verified it booted correctly.

Next, I booted FreeBSD 8.0-release from a USB memory stick and chose 'standard install'. I let sysinstall use the remaining 22GB. When it was time to label, I created just one slice, mountpoint /, softupdates on. When sysinstall asks what kind of MBR to install, it's important to choose 'Boot Manager', otherwise you won't get the boot menu.

When the install was done, I rebooted, and was greeted by this menu:

F1 Win F2 FreeBSD F6 PXE Boot:

I was able to succesfully boot both Windows and FreeBSD.

Details

I had already a working Windows XP installation on the old 250GB laptop harddisk, which I wanted to transfer to the SSD. I have done stuff like this before (see NTFS Cloning and shrinking for a lenghty discussion). I shrunk it to about 52GB using: # ntfsclone -o ntfslaptop.img /dev/ad2s1 # mdconfig -a -t vnode -f ntfslaptop.img # ntfsresize --size 56404131840 /dev/md0 # ntfsclone --force -o shrunk.img /dev/md0 # mdconfig -d -u /dev/md0 # dd if=shrunk.img of=/dev/ad4s1 bs=1m

Remark: In the above example, ad2 is the original laptop harddisk, and ad4 is the new SSD disk. I also placed both image files on different working harddisks, to minimize seeking and maximize transfer speed.

That resulted in a shrunk image of exactly 56,404,128,256 bytes, that is 110,164,313 sectors of 512 bytes each. When creating the Windows partition on the SSD, I didn't want to waste any space. I found that using a partition size of 53796MB resulted in a partition of 110,173,707 sectors, that is 56,408,937,984 bytes. That was the closest I could get. This results in an unused area of 9394 sectors (4,809,728 bytes, about 4.5MB) of wasted disk space.

Resulting disk layout:

offset size end slice type 0 63 62 12 - 63 110173707 110173769 ad4s1 4 ntfs 110173779 46127718 156301487 ad4s2 8 bsd

Interesting: at the end of the NTFS partition thus sits a number of unused sectors, which could be used to stuff some data away, unbeknownst to the operating system: the NTFS partition has 110173707 sectors (from 63 to 110173769, including), of which the first 110164313 are actually used (from 63 to 110,164,376, including). That leaves a free space from sector 110,164,376 to 110,173,769, including. Which is indeed 9394 sectors in size.

Comments

jljack • 17 May 2010

heh, i also have one of those stickers

bulent • 3 Sep 2014

is dual boot possible with windows 8 and freebsd 10?

Leave a comment

name (required)



content last edited on October 31, 2010, 13:38 - rendered in 2.53 msec