Showing posts with label virtualbox. Show all posts
Showing posts with label virtualbox. Show all posts

Sunday, 12 January 2014

Virtualize an old Windows XP disk partition (howto convert disk partition to virtual disk for VirtualBox)

I dug out an old hard disk. I was curious: what gems are stored here?

Turns out there was nothing, but it was in interesting exercise in converting a single disk partition into a VM - something that is not trivial.

I plugged my old drive into a USB hard disk docking station and had a look. It contained Windows XP and Linux from an old PC dating from 2004-2007 I believe.

"Hey!" I thought. I could virtualize this for no good reason and show how easy it is using free and open source software.

Ubuntu Packages

I installed VirtualBox and mbr.

Create VirtualBox VM

  • Select New
  • Name your VM (say TEST)
  • Select Windows and Windows XP
  • Set memory size (default is ok)
  • Select 'do not add a virtual hard drive' - we will create this later in tis VM's directory.

Create Virtual Disk Drive

Open a terminal and change to your ~/VirtualBox\ VM/TEST directory for this example.

Copy and paste my script into your editor.

#!/bin/bash

DISK=/dev/sdd
PART=1

printf "Copy boot sector image...\n"
sudo dd if=$DISK of=mbr.img bs=512 count=1 || { printf "FAILED\n"; exit 1; }
printf "Done\n"

# put 'normal' mbr incase grub or something was used
printf "Replace MBR code..."
sudo install-mbr mbr.img -t 36 || { printf "FAILED\n"; exit 1; }
printf "Done\n"

printf "Copy disk (%s) partition %d...(at 10MB/s 1GB will take 100s)...\n" "$DISK" $PART
PARTIMG=part${PART}.img
sudo dd if=${DISK}${PART} of=$PARTIMG bs=512 || { printf "FAILED\n"; exit 1; }
sudo chown $USER:$USER $PARTIMG
printf "Done\n"

printf "Make VirtualBox VMDK image with MBR...\n"
sudo VBoxManage internalcommands createrawvmdk -filename ./disk.vmdk -rawdisk $DISK -partitions $PART -mbr ./mbr.img || { printf "FAILED\n"; exit 1; }
# VB needs this owned by user
sudo chown $USER:$USER disk-pt.vmdk
printf "Done\n"

# switch to partition image and zero starting offset
# eg.
# from this: RW 8514387 FLAT "/dev/sdd" 63
# to this: RW 8514387 FLAT "/home/phil/Development/pc-part2disk/part1.img" 0
 
printf "Modify VMDK files to use disk partition image...\n"
sudo cat disk.vmdk | sed "s@\"$DISK.*@\"./$PARTIMG\" 0@" > diskimage.vmdk
sudo chown $USER:$USER diskimage.vmdk
printf "Done\n"

# remove VB vmdk that points to physical drive - no longer required
sudo rm disk.vmdk

exit 0
 Change DISK and PART to suit your case. This example uses disk /dev/sdd and partition 1.

Also, run chmod +x

Sunday, 27 February 2011

Another Virtualised OS-X Example

In case this is copied, go to the original site which should be http://philatwarrimoo.blogspot.com/2011/02/another-virtualised-os-x-example.html

To see if my first virtualised OS-X was a fluke, I'll have another go. This will just list the steps I take and there won't be much discussion.

>VBoxManage internalcommands listpartitions -rawdisk /dev/sda
Number Type StartCHS EndCHS Size (MiB) Start (Sect)
1 0xee 1023/254/63 1023/254/63 200 1
2 0xaf 1023/254/63 1023/254/63 119102 409640
4 0x83 1023/254/63 1023/254/63 11444 244330976
3 0xaf 1023/254/63 1023/254/63 23167 343011768

The OS-X partition I want is Number 2: type is 0xaf and the size is about right.

I have found my first fault: I created the vmdk file in VB 3.2.8. Under VB 4.0 the '-register' option is no longer used. VB 4.0 has a '-relative' option for Linux hosts that would make sense to use, but 'relative' and 'register' are too different for it to be a typo.

My source used '-register' so VB 4.0 must be different.

>VBoxManage internalcommands createrawvmdk -filename /home/phil/.VirtualBox/HardDisks/osxpart1.vmdk -rawdisk /dev/sda -partitions 2RAW host disk access VMDK file /home/phil/.VirtualBox/HardDisks/osxpart1.vmdk created successfully.

I should point out that the name of the vmdk file that I used is from the viewpoint of OS-X, not the actual partition number - use your own naming scheme.

The '-register' option adds the new vmdk file to the list of hard disks available - looks like I'll have to register manually somehow.

I added an entry in the VirtualBox.xml file for the new hard disk like this:
I got the UUID from the osxpart1.vmdk.xml file - I used the uuid.image number for the uuid attribute.

That did the trick.

I created a new VM, called it maxosxp1 and VirtualBox automatically selected Mac OS X - nice.

I told it to use the new osxpart1.vmdk file that I just created and left everything else as default for the time being.

I tried to run it, and it didn't work. But I have found that you need to do this to populate the XML or VBOX file to make the next steps easier.

Note: in VB 4.0, the file is now in VirtualBox VMs/(machine name)/(machine name).vbox. It is still an XML file so you can edit it with a text editor - but as before only when VirtualBox is not running.

To make it boot I need to add in the special Apple SMC key.

I added these to the ExtraData section:

<ExtraDataItem name="VBoxInternal2/EfiBootArgs" value=" "/><ExtraDataItem name="VBoxInternal2/EfiGopMode" value="4"/><ExtraDataItem name="VBoxInternal2/SmcDeviceKey" value="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"/>

I then started the VM.

It was slow to boot, but it got there. As it was loading I could see VMWare and VirtualBox kernel extensions loading and I thought that it will not like that - running a VM manager in a VM.

It wanted me to identify my keyboard and that was it.

I logged in, hit (shift)-(right command)-F to enter fullscreen mode.

Apart from being slow and running warm, it looked like I was running OS-X on a PM rather than a VM.

To solves the high CPU load problem, just delete the right kernel extension.
sudo rm -fr /System/Library/Extensions/AppleIntelCPUPowerManagement.kext
I haven't done that yet as I might want to boot into this partition sometime soon to tidy it up.


So, no fluke.

Saturday, 19 February 2011

Boot a Real Mac OS-X Partition under Linux and VirtualBox - What Works

VirtualBox 4.0


Works (does something)
  • Nat networking
  • Safari (I have edited this post using Safari on the OS-X VM)
  • iTunes (starts - that is all I have done)
  • iPhoto (starts - that is all I have done)
  • About
  • System Preferences
  • Finder
  • Finder sees other SMB and AFS shares
  • Shutdown (mostly) 
  • 1 CPU runs flat-out - to 'fix' this I ran this command. When the VM is idle the host load is much reduced:
  • sudo rm -fr /System/Library/Extensions/AppleIntelCPUPowerManagement.kext
  • By removing /System/Library/Extension
  • Calculator
  • YouTube
  • Sound - I have tried IntelHD/ALSA
  • USB with VirtualBox extras
  • Disk Utility
  • Intel PRO/1000 MT Desktop (Bridged adapter, eth1)
  • Time Machine backup to Time Capsule if a network bridge is available

Does not work (or I can't get it working)
  • glxgears (X11 crashes repeatedly)
  • Shutdown (rarely)
  • V8 Benchmark runs too slow for Safari's liking

VirtualBox 3.2.8 OSE


Works (does something)
  • Nat networking
  • Safari
  • iTunes (starts - that is all I have done)
  • iPhoto (starts - that is all I have done)
  • About
  • System Preferences
  • Finder
  • Finder sees other SMB and AFS shares
  • Shutdown (sometimes) 
  • 1 CPU runs flat-out
  • Calculator
  • YouTube
  • Disk Utility

Does not work (or I can't get it working)
  • Bridge Networking
  • Audio
  • glxgears (X11 crashes repeatedly)
  • Finder can not connect to other SMB and AFS shares
  • Shutdown (sometimes)
  • V8 Benchmark runs too slow for Safari's liking


Boot a Real Mac OS-X Partition under Linux and VirtualBox

This should be easy, but Apple make it hard.

I have a MacBook Pro. I have OS-X Leopard 10.5.2 installed as well as Ubuntu 10.10 linux.

I wanted to get my OS-X partition to run as a virtual machine.

After many false starts I got something to work.



First, the specs.
Hardware: MacBook Pro 4,1, early 2008, 2.4GHz, 200GB, 15"
http://en.wikipedia.org/wiki/MacBook_Pro
Host OS: Ubuntu 10.10
VM Manager: VirtualBox 3.2.8 OSE r64453
Guest OS: OS-X 10.5.2 Leopard (I don't bother to update it as I don't use it much and it have virtually nothing installed)
Overview

1. Get VirtualBox to list the physical partition in the Virtual Media Manager.
2. Setup the VM
3. Tweak it.
3. Run it.

1. Setup Disk Image

Please proceed at your own risk. Only do this if you have backed-up your disk partitions (with Time Machine for example, but don't forget about your linux partition) or your don't care about any data on your disk.

I used this information to create my VMM vmdk file.
http://ejs.seniejitrakai.net/2010/11/01/running-virtualbox-guests-from-physical-drive/
In my case, my hard drive is /dev/sda under linux.



phil@max:~$ VBoxManage internalcommands listpartitions -rawdisk /dev/sda

Oracle VM VirtualBox Command Line Management Interface Version 3.2.8_OSE(C) 2005-2010 Oracle CorporationAll rights reserved.
Number  Type   StartCHS       EndCHS      Size (MiB)  Start (Sect)1       0xee  1023/254/63  1023/254/63           200            12       0xaf  1023/254/63  1023/254/63        119102       4096404       0x83  1023/254/63  1023/254/63         11444    2443309763       0xaf  1023/254/63  1023/254/63         23167    343011768


The OS-X partition in my case is number 3. It is about 23GB.

Then I made the vmdk file like this:

phil@max:~$ VBoxManage internalcommands createrawvmdk -filename /home/phil/.VirtualBox/HardDisks/example.vmdk -rawdisk /dev/sda -partitions 3 -register 
Oracle VM VirtualBox Command Line Management Interface Version 3.2.8_OSE(C) 2005-2010 Oracle CorporationAll rights reserved.
RAW host disk access VMDK file /home/phil/.VirtualBox/HardDisks/example.vmdk created successfully.

This made this file - yours will be different, but it should have the same structure:

# Disk DescriptorFileversion=1CID=279c9811parentCID=ffffffffcreateType="partitionedDevice"
# Extent descriptionRW 1 FLAT "example-pt.vmdk" 0RW 409639 ZERO RW 243921336 ZERO RW 23437500 ZERO RW 75243292 ZERO RW 47448016 FLAT "/dev/sda" 343011768RW 262184 ZERO 
# The disk Data Base #DDB
ddb.virtualHWVersion = "4"ddb.adapterType="ide"ddb.geometry.cylinders="16383"ddb.geometry.heads="16"ddb.geometry.sectors="63"ddb.uuid.image="99ca08b3-6d2e-4ed4-8790-2430cfe5a57a"ddb.uuid.parent="00000000-0000-0000-0000-000000000000"ddb.uuid.modification="00000000-0000-0000-0000-000000000000"ddb.uuid.parentmodification="00000000-0000-0000-0000-000000000000"

Now if you run Virtual Media Manager, you should now see a new hard drive entry for your physical partition.


That wasn't that hard, thanks to Sun/Innotek for making this easy.

2. Setup VM.

The key fields are these:
OS Type = Mac OS X
Use an existing hard disk - the one I created above: example.vmdk
The rest are the current defaults (which I will list below).
I also enabled 3D acceleration, but I can pick either.
Too easy, right?

3. Tweak VM

Apple OS-X checks to see if a special key is in a chip. VMs don't currently emulate this chip with the key, so you need to get the key off your machine and add it manually to the VirtualBox XML file that describes the VM.

The key is really a plea from Apple to not steal their OS. Here is their EULA for 10.5.

http://images.apple.com/legal/sla/docs/macosx105.pdf

It contains this clause:

A. Single Use. This License allows you to install, use and run one (1) copy of the Apple Software on a single Apple-labeled computer at a time. You agree not to install, use
or run the Apple Software on any non-Apple-labeled computer, or to enable others to do so. This License does not allow the Apple Software to exist on more than one
computer at a time, and you may not make the Apple Software available over a network where it could be used by multiple computers at the same time. 

I think this complies: One licensed and installed copy of OS-X on an Apple-labeled computer. I can't run it twice because that would do bad things to the file system.

So, I'll continue...

In my case the XML file is /home/phil/.VirtualBox/Machines/example/example.xml

This is what it might look like:


<?xml version="1.0"?>
<VirtualBox xmlns="http://www.innotek.de/VirtualBox-settings" version="1.11-linux">
  <Machine uuid="{0db68b53-a452-40bd-bb83-ad8952411320}" name="example" OSType="MacOS" snapshotFolder="Snapshots" lastStateChange="2011-02-19T08:34:33Z">
    <MediaRegistry>
      <HardDisks/>
      <DVDImages/>
      <FloppyImages/>
    </MediaRegistry>
    <Hardware version="2">
      <CPU count="1" hotplug="false">
        <HardwareVirtEx enabled="true" exclusive="true"/>
        <HardwareVirtExNestedPaging enabled="true"/>
        <HardwareVirtExVPID enabled="true"/>
        <PAE enabled="true"/>
        <HardwareVirtExLargePages enabled="false"/>
        <HardwareVirtForce enabled="false"/>
      </CPU>
      <Memory RAMSize="1024" PageFusion="false"/>
      <Firmware type="EFI"/>
      <HID Pointing="USBTablet" Keyboard="USBKeyboard"/>
      <HPET enabled="true"/>
      <Chipset type="ICH9"/>
--- SNIP --- 


  </Machine>
</VirtualBox>

As you can see, the whole configuration of a VM is, more-or-less, understandable.

But wait! To do the next bit, you have to run the VM once. Until you do this scary thing, the XML file is missing bits that make the next part easier.

So, start the VM. When you see lots of text you can close the window and shutdown the VM.


This is all safe it seems.

My example VM XML file now looked like this - the highlighted bits are what we want to see:


<?xml version="1.0"?>
<VirtualBox xmlns="http://www.innotek.de/VirtualBox-settings" version="1.11-linux">
  <Machine uuid="{57d6a1c9-833f-4fb7-b765-f4c37793bc56}" name="example" OSType="MacOS" snapshotFolder="Snapshots" lastStateChange="2011-02-19T08:27:47Z">
    <MediaRegistry>
      <HardDisks/>
      <DVDImages/>
      <FloppyImages/>
    </MediaRegistry>
    <ExtraData>
      <ExtraDataItem name="GUI/LastCloseAction" value="powerOff"/>
      <ExtraDataItem name="GUI/LastGuestSizeHint" value="1024,768"/>
      <ExtraDataItem name="GUI/LastNormalWindowPosition" value="400,61,1024,815"/>
      <ExtraDataItem name="GUI/LastWindowPostion" value="37,53,1024,815"/>
      <ExtraDataItem name="GUI/MiniToolBarAlignment" value="bottom"/>
      <ExtraDataItem name="GUI/SaveMountedAtRuntime" value="yes"/>
      <ExtraDataItem name="GUI/ShowMiniToolBar" value="yes"/>
    </ExtraData>
--- SNIP --- 
  </Machine>
</VirtualBox>

To tweak it, I followed these instructions:
http://www.takwing.idv.hk/tech/virtual/vb320_macvm/page3.html

Modify your VM's xml file by adding the following line to the section:

<ExtraDataItem name="VBoxInternal2/SmcDeviceKey" 
value="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"/>



Mine then looked like this:

<?xml version="1.0"?>
<VirtualBox xmlns="http://www.innotek.de/VirtualBox-settings" version="1.11-linux">
  <Machine uuid="{57d6a1c9-833f-4fb7-b765-f4c37793bc56}" name="example" OSType="MacOS" snapshotFolder="Snapshots" lastStateChange="2011-02-19T08:27:47Z">
    <MediaRegistry>
      <HardDisks/>
      <DVDImages/>
      <FloppyImages/>
    </MediaRegistry>
    <ExtraData>
      <ExtraDataItem name="GUI/LastCloseAction" value="powerOff"/>
      <ExtraDataItem name="GUI/LastGuestSizeHint" value="1024,768"/>
      <ExtraDataItem name="GUI/LastNormalWindowPosition" value="400,61,1024,815"/>
      <ExtraDataItem name="GUI/LastWindowPostion" value="37,53,1024,815"/>
      <ExtraDataItem name="GUI/MiniToolBarAlignment" value="bottom"/>
      <ExtraDataItem name="GUI/SaveMountedAtRuntime" value="yes"/>
      <ExtraDataItem name="GUI/ShowMiniToolBar" value="yes"/>
      <ExtraDataItem name="VBoxInternal2/SmcDeviceKey" value="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"/>
    </ExtraData>
--- SNIP --- 
  </Machine>
</VirtualBox>    

4. Run it.

That's it.

Let me know if it worked for you, and if you have a different hardware, host, guest configuration.

If it didn't work, then I probably can't help - but you you want me to explain anything that I did in more detail then please ask.

BTW, if this kills you disk, damages your data, or generally make your life a misery then you will recall that I warned you, right?

Saturday, 23 May 2009

Some links to quality and popular Open Source software


What application do you want?

Anti virus? Try ClamAV for unix/linux or ClamXAV for Mac OS-X or ClamWin for Windows.

Word processor, Spreadsheet, Presentation etc.? Try OpenOffice

Web browser? Try Firefox, Webkit, Chrome (from Google), Safari (from apple - based on WebKit), Stainless

Mozilla Firefox runs on Windows, Mac OS-X, and Linux PCs
Webkit runs runs on (Windows and Mac OS-X PCs. Safari probably a better version for most people.
Google Chrome runs on just Windows for now. You can get an beta Mac OS-X version here.
Apple Safari runs on Windows and Mac OS-X PCs
Stainless (closed source?) runs on Mac OS-X. It is tiny, very fast and very simple. I added this because it is an interesting project.


Graphics editor? Try the GIMP

Media player? Try VLC

Bit Torrent client? Try Transmission (open source).

Sound editor? Try Audacity

Email client? Try Mozilla Thunderbird.

Virtual PC environment? Try Virtual Box

This allows you to run other operating systems (guests) on your current OS (host). For example you might like to run Linux on your Windows PC. Linux would run in a window or full-screen if you like and at the same time you can run all your other Windows applications.

Virtual Box allows you to easily install multiple copies of Linux and even other Windows versions on your current Windows PC. It also works on your Mac so you can run Windows and Linux on your Mac - this is what I do. You can start them up and shut them down just like real PCs.