Wednesday, December 15, 2010

Dual-booting/virtualizing Fedora

What's the very first thing you should be doing on a brand new Dell laptop preloaded with Windows 7? Install Fedora 14, of course! But I don't want to just throw Windows away, I've plenty of software for the evil platform I can reuse and it is always necessary to test JBoss on different OS-es. Besides, Max was telling me that an amazing 70% of JBoss AS users are still developing on Windoze!

Dual booting the laptop is really the first step to get going and the 2nd link returned by Google on the subject what quite useful. I wasn't starting from scratch though, so I had first to make some space on the hard disk that was pre-loaded by Dell with 3 primary partitions: a small 39Mb one marked as OEM partition, an 11.15Gb recovery one that I didn't want to touch (although I might remove it at a later stage) and the rest of the space allocated to drive C: with all the windoze stuff in there.

Thankfully the latest windows let you shrink the C: volume without the need for any 3rd party tool like Partition Magic or GParted, down to point where the unmovable system/hidden files are located, and that practically released half of the allocated disk space. This is done through Panel-->Administrative Tools-->Computer Management-->Disk Management, right-click on the C: partition.

A part of the freed-up space (1/3) I wanted to create an NTFS data D: drive, so that programs and data are separated (always a good idea in case you want to re-install windows or need to release some space later on from that data partition), but I couldn't just create another primary partition because that would have been the 4th and final one, leaving no space for Linux. So D: had to go inside an extended partition and because I couldn't find any easy/quick way to do it (maybe fdisk?), I just went out and booted a GParted live disk to do just that.

With D: drive created and the remaining free space all within the extended partition the next step is to go ahead and install Fedora 14 from the DVD. I've created a custom partitioning scheme with a /boot (250Mb) partition, a swap partition (4G), and the rest of the space assigned to a logical volume, split into root / (15G), /var (4G) and /home (50G). In order to not mess things up with the windows MBR peculiarities, I've put the GRUB bootloader on the /boot partition so that the 2 OSes are effectively isolated from each other.

Going back to windows, installing EasyBCD and following the instructions here, takes away the configuration hassle and you can now boot either of the two OSes without upsetting the windows installation/bootloader. BTW, with this setup all the Linux partitions are within the extended partition, including the /boot one.

Now the next step is to virtualize the Linux installation within windows so that both operating system can be used at the same time, as well. The cool thing in this case is that the virtualized Linux guest sees the actual linux partitions in raw mode, not some virtual drive created atop the slowest of all filesystems (i.e. NTFS). And if performance of the virtualized Fedora guest becomes an issue you can always go back and dual boot directly accessing the same disk partitions.

After some failed attempts for accessing natively the Linux partitions with VMware player & VMware server, I managed to get it working with VirtualBox. Some hints to get this working can be found here. You basically need to create a Virtual Hard Disk (essentially a file in the host filesystem) that instead of containing the virtual disk data it merely points to the physical disk partitions to be accessed in raw mode. You should read the relevant part in the documentation with the necessary scary warnings before proceeding.

In short, cd to the virtual box program directory:
cd \Program Files\Oracle\VirtualBox

Find out the partitions numbers that you want to make available
vboxmanager internalcommands listpartitions -rawdisk \\.\PhysicalDrive0

Create the virtual file that will point to those partitions (6,7,8 in my case)
mkdir c:\Users\dimitris\.VirtualBox\VDI
vboxmanage internalcommands createrawvmdk -filename c:\Users\dimitris\.VirtualBox\VDI\ssddrive.vmdk -rawdisk \\.\PhysicalDrive0 -partitions 6,7,8 -register -mbr \NST\nst_linux.mbr


There are few things to note (discovered through trial-and-error).

  • First, if you get permission errors while executing the internal commands, deactivate Windows Defender and any other anti-virus software you might be using.
  • Second, the register flag will also make the virtual drive show up in the Virtual Media manager in the VirtualBox console, so you can attach it to your virtual machine.
  • Third, the -mbr option is necessary in order to get VirtualBox to know which boot record to use when booting the image. Now, if you have used EasyBCD to setup dual boot as described above, the linux MBR is conveniently stored in the location shown in the command (\NST\nst_linux.mbr), which is just perfect!
That last command is really the key to make it work, the rest is more or less standard procedure that you can find in the various on-line resources I've pointed out.

Enjoy your dual-booted / virtualized Fedora installation!

/Dimitris

1 comment:

Shyama Karan Dubey said...

Well said Dear Dimitris these AppsProb must be solved after reading your guide