Sunday, June 14, 2009

Virtual machine, physical disk

I've been a big fan of using virtual machines with products like VMware, Parallels and Sun's free VirtualBox. I recently had an old linux server die with a bad power supply but I still needed some of its data and services.

I removed the server disk and connected it to a ATA-USB converter. I could have just connected it to a linux virtual machine if I just needed the data but I wanted to boot from it.

VirtualBox makes it possible to connect a virtual machine to the physical disk. I plugged the USB converter into my Mac running OS-X and told the Mac to ignore the foreign file systems. Running diskutil in Terminal.app gave me the device assignment:

~/: diskutil list
/dev/disk0
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *111.8 Gi disk0
1: EFI 200.0 Mi disk0s1
2: Apple_HFS Macintosh HD 111.3 Gi disk0s2
/dev/disk2
#: TYPE NAME SIZE IDENTIFIER
0: FDisk_partition_scheme *38.2 Gi disk
1: Linux 101.9 Mi disk2s1
2: Linux 18.6 Gi disk2s
3: Linux 19.3 Gi disk2s3
4: Linux_Swap 188.2 Mi disk2s5


Virtual box has a command line tool to create a mapping from a virtual to a physical device:

~/: VBoxManage internalcommands createrawvmdk -filename `pwd`/linux.vmdk -rawdisk /dev/disk2
VirtualBox Command Line Management Interface Version 2.2.
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

RAW host disk access VMDK file /Users/verket/Library/VirtualBox/HardDisks/linux.vmdk created successfully.

I then used the VirtualBox GUI to define the IDE Primary Master as linux.vmdk. Booting my virtual machine accessed my physical drive through the USB converter giving me my server back but in virtual form.

No comments:

Post a Comment