Converting a physical partition with freebsd to a vmware image
There are many virtualization solutions today, but I chose a VMware solution for purposes of this article (conversion of a physical partition), as VMware is a pioneer in virtualization industry, company’ products are very fast, extremely portable, and many of them are free. VMware images are playable in VMware Player, which is also free for platforms that support it. This means that you can carry VMware Player and your images anywhere on a USB disk and play them without restrictions in Linux and Windows.
Putting a VMware image back to a physical disk is quite simple, too, but I will mostly focus on how to make a portable FreeBSD (applicable also to OpenBSD) virtual computer. I decided for this solution because my motherboard recently died. I realized that with a portable virtual computer on a portable USB disk I can enjoy real freedom.
Although I have a notebook, my Internet browser in it is without e-mail accounts and without all my bookmarks, music and books. When my motherboard died I understood that I must have a couple of virtual images, but not just the ordinary ones like I can download from the Internet, but the ones with all the software I love and with all my personal customizations – something an image of a virtual PC downloaded from the Internet can never substitute.
What you must do to convert a physical disk to a VMware image?
I will carefully describe all the steps I did, but as we are moving into the waters of portability, I must, too, leave the BSD ocean and move into Linux or Windows waters.
1) You must prepare an empty and configured (with CD-ROM devices, disks, networking, etc.) VMware image (the configuration is actually held in an accompanying VMX text file).
To do this,
a) either use proprietary VMware software; there are several packages, VMware Server is free (Linux and Windows);
b) or download one of many VMware images (free premade appliances), delete its content and use it; however, one of the drawbacks of this solution is that the premade images for VMware Player do not always come in the sizes you may like.
c) You may use some free utilities like qemu-img, which is included in the Qemu package and which creates empty disk images for use not only with QEMU, but also with VMware products. VMmanager is another free tool that does the same job but in Windows.
2) Before you make the backup, empty spaces on your physical partition must be zeroed, otherwise the gzipped partition will be too big. FreeBSD has internal partitions, so run the following command in all of them:
dd if=/dev/zero of=/usr/000file bs=200M
Note please that I use the term “partition” here as it is used generally for Windows or Linux. However, in the FreeBSD terminology I should use “slice” (“s” in device such as ad0s2). In FreeBSD, partitions (internal partitions that fdisk of Windows or Linux does not see) have letters assigned to them (ad0s2a, ad0s2d, etc. – that is, here we deal with slice 2 and internal partitions “a” and “d”).
After a very big file is created in /usr with the above command, delete it and run the command again, but point the execution of zeroing empty spaces into /var (of=/var/000file), /tmp, etc., because FreeBSD (during its installation process) always assigns (and mounts) its own internal partitions to these directories (/ = ad0s1a, /var = ad0s1e, /tmp = ad0s1d, etc.). To avoid possible boot problems, make sure that you copy (backup) the physical partition (if unsure, look into /etc/fstab) from /dev/ad0s2 to /dev/ad0s2 (not to /dev/ad0s1 in your virtual image). If the FreeBSD partition on your physical Hard Drive is /dev/ad0s2, make two primary partitions in your virtual image and restore the backup to /dev/ad0s2 (not to /dev/ad0s1). However, FreeBSD boots more intelligently than Linux. In case you have a different disk specified in /etc/fstab in your physical hard drive, the system (shortly after it boots) will ask you to supply the correct boot device. I inform about this because I took care of this issue and I advise you to do the same.
3) Now you must backup your FreeBSD partition. You may use any image creation program (like Norton Ghost, Acronis, etc.) that makes an image of a physical disk, or just use the following Unix command: dd if=/dev/ad0s2 bs=1M | gzip -2 > /mnt/diskimg.gz (and replace /dev/ad0s2 with your own device).
4) The VMware image must be partitioned and you must use the primary partition for FreeBSD (not a logical one). The size of it cannot be smaller than the size of the uncompressed image (the copy of your physical disk) now residing in the gzipped file (or in the Norton Ghost’s GHO image, etc.). To partition your virtual disk, you can also use the standard FreeBSD sysinstall tool (available on a bootable installation FreeBSD CD/DVD), or utilities such as gparted.
In my case I used an old DOS version of Partition Magic (I created three unformatted primary [DOS] partitions in my virtual disk) – I made two small primary partitions and the one required for FreeBSD (/dev/ad0s3).
5) You must create a bootable ISO image with the compressed (gzipped, etc.) partition in it; after you boot your virtual computer with it, restore the copied physical partition to your newly created VMware image. The way I did this was that I prepared a bootable ISO of the Norton Ghost image (compressed physical partition) with a bootable DOS floppy image in it (run the command like: mkisofs -b DOSfloppy.img -o /mnt/DOSandIMAGE.iso . With the dot at the end of the command mkisofs will put the directory where you presently work into the ISO file, so keep also your partition in the GHO or gzipped format in this directory). If you want to do it the same way as I did it, visit www.bootdisk.com and download some DOS/Win98 floppy images.
The dd command to restore the image can be used, too, but you need some Unix bootable floppy or CD/ISO. If you feel a little bit uncertain, use the NetBSD tool g4u, which is Harddisk Image Cloning for PC’s and which works the same way as Norton Ghost.
You may also work with two ISO images; however, one of them must be bootable (ISO image of g4u, for example; the other ISO image containing your copied physical partition does not need to be bootable in case you use two CD-ROM’s – that is, two ISO files).
6) After you create the partition(s) with fdisk (or gparted, Partition Magic, sysinstall, etc.) in your VMware image and with the size corresponding with the size of your physical FreeBSD disk, reboot the virtual computer. With a DOS or Unix bootable floppy or bootable CD (ISO image) you may now restore the backup. To do this with dd in Unix, run the command:
gzip -dc /path/to/image.gz | dd of=/dev/ad0s1
In case you decide to go on with the Acronis products, you can easily create a bootable CD applicable for image creation and restoration. But in this case the easiest way is to put the Acronis image file (the copy of your FreeBSD physical disk) into another ISO image (with mkisofs). With utilities such as g4g or Live CD’s such as my MaheshaBSD project and with a second computer around it is painless to restore the copy of your physical disk via FTP in Unix. MaheshaBSD has a working VSFTPD server in it, so just boot two computers with this CD and run the dd or the dump command to restore the image. It can even reside on a NTFS partition, as MaheshaBSD has no problem to mount NTFS volumes. To learn how to use networking in your virtual computer, see Some Questions And Answers below.
The last and very important thing is to make sure that the virtual partition that holds your FreeBSD in it is set active. You may also install FreeDOS, or some very small Unix systems (or even full installation of OpenBSD) onto the first two small partitions (if you have them) and use GAG boot manager to switch between them (multiple boot). This does not mean that small partitions are really needed, but they may appear very handy for testing purposes.
Some Questions and Answers
How to play your VMware images in FreeBSD?
In VirtualBox, just select File > Virtual Media Manager, click on Add in Virtual Media Manager and select your newly created VMware VMDK file. VirtualBox runs under FreeBSD very well and it is free.
Alternatively, you can use some conversion utilities like qemu-img and convert the VMware virtual disk for use with Qemu. Unfortunately, Qemu is slow, but there are a lot of sites dedicated to VMware-to-Qemu conversion. You need to install Qemu and use its qemu-img utility:
qemu-img convert win2kpro.vmdk -O qcow win2kpro.img
Running VMware on FreeBSD as a host is possible, but only older versions of VMware Workstations run. I recommend using VirtualBox.
Is it possible to convert VMware disk image (VMDK) to Xen?
Yes. You will find many websites that deal with this issue. However, there may be some little problems, so check them out. For the conversion you need the vmware-vdiskmanager tool that comes with VMware Server (for example, VMware Server 1.0). Check the Wiki.xensource.com website.
How to play your VMware images in Linux/Windows?
Download VMware Player, VMware Server, or VirtualBox. All alternatives are free and available for several platforms. To use your VMware image with Windows, edit the VMX file in notepad and change the syntax for CD-ROM and floppy devices (if you need them). Change:
ide1:0.fileName = “/dev/acd0″ to ide1:0.fileName = “H:”
floppy0.fileName = “/dev/fd0″ to floppy0.fileName = “A:”
Use the real letter (H: or I: or G:) that Windows assigned to the CD-ROM device.
In Linux the VMX file must describe these devices as they are known to the hosting Linux system. If your CD-ROM device is /dev/sr0 in Linux, you must have the following line in your VMX file: ide1:0.fileName = “/dev/sr0″
How to use the Internet?
The le (or em) driver handles networking. I configured my VMware image with a bridged networking and used the dhclient command to connect to the Internet (dhclient le0). It worked.
How to run X?
Before you backup your physical FreeBSD partition, install the Xorg VMware driver. It is in /usr/ports/x11-drivers/xf86-video-vmware. You can do this even after copying your physical partition to the virtual image. Running the command Xorg -configure in your virtual computer is necessary, too. Depending on the version of Xorg, sometimes adding the command Option “AllowEmptyInput” “Off” to your newly generated xorg.conf is necessary for your mouse to work. Then just run the startx command and enjoy.
Are VMware tools necessary?
The company does not presently support use of VMware tools (a special package of VMware enhancements) for FreeBSD and they are actually not needed at all for networking or X.
How to put a virtual computer back to a physical partition?
You must use the same method but reversely (the dd command, Acronis, Norton Ghost, g4u, etc.) – back up your virtual computer. To do so, you only need another (empty) virtual disk or just an FTP storage. After making a copy of your virtual disk you must make a bootable CD/DVD with it. Use the same standard way you use for restoring physical partitions.
Are there any special tweaks recommended?
Reduce kern.hz (Kernel Timer Frequency), as the FreeBSD’s default value of kern.hz is set to a relatively high number. High kern.hz value is beneficial on real hardware. To check your present kern.hz value on the system, type: sysctl kern.hz and if it is over 100, make your virtual FreeBSD a little bit faster by adding the following line to your /boot/loader.conf: kern.hz=45
How about sound and video?
I did not make any changes and the sound and video worked (ogg, mp3 files, avi, mpg, etc.).
May I use snapshots with FreeBSD?
Yes. Snapshots, a very valuable feature of every good virtualization software today, save your time, because you immediately restore your virtual system to the point you left it the last time (starting your virtual machine again but without booting it), but they bring a very big security problem.
Anybody who has a physical access to your virtual computer’s snapshot may (after he or she restores it) read your emails (if a snapshot was made with Thunderbird active on your desktop), or perhaps grab your passwords. Use snapshots in physically secure environment only (do not carry them on portable USB disks that you may lose). Although you may argue that anybody can boot a virtual FreeBSD machine in a single user mode, you are right, but this article is not primarily about security. When someone opens your VM in single user mode it is still a bit harder for him or her to access other encrypted stuff that is not left as an easy prey on your desktop (seen immediately after a snapshot restoration). However, the rule of thumb is that the same security measure you apply to your car keys do also apply to your virtual machines and keep them always away from prying eyes.
The article first appeared in the 2011 April issue of BSD magazine (http://www.bsdmag.org/) – free computer magazine (feel free to download it and see the article also with pictures).
About the Author
Let’s Play Mission 2: Team Player (Buy Modern Warfare 2?)
Clip Plus 4 GB MP3 Player (Black)
Pyle PSW Waterproof Neckband MP3 Player and Headphones for Swimming, Water Sports
Inflatable Images West Virginia Mountaineers NCAA Inflatable Bubba Player Lawn Figure (60 Tall) INF-05-0023
Get into game mode by having your favorite teams inflatable mascot or logo! These are next generation in airLite lawn/tailgate inflatables that really show your school spirit and are larger than life. Details : Patented internal air Lite inflation fan; High quality design & construction; For both indoor & outdoor use; lightweight & durable; Easy to use & display; Just plug it in; set it up & go!…
Sharper Image Personal Entertainment Center DVD/ TV/ CD/ Radio/ Sound Soother Player
Wide 7-inch TFT LCD Screen
20 Soothering Sounds
Aluminum Cone Speakers
Wierless Remote Control
AM/FM Digital Tuner
DVD; TV; CD; AM/FM; 7″ LCD Display.
Panasonic Smart Networking 4K Upscaling Wi-Fi and 3D Blu-ray Disc Player, Features Miracast Technology for Stream Movies Music and Images from your Smartphone, VIERA Connect and Web Browser, Plays 2D and 3D Formats, USB 2.0 High Speed, and Multi User Mode, HDMI Output with Cable Included
Panasonic Smart Network Plus 3D Blu-ray Disc Player, with all New 4K TechnologyBuilt-In 4K (UHD) Up-ScalingConverts to 4K video signal (8M pixels) for improved resolution and richer textural expression, virtually equivalent to Ultra HD digital cinemaWeb BrowserBrowse your favorite websites, watch the news, shop on the web, search for information, share with family and friendsWide Variety of Online…
IMAGE® 3 Color LED Illuminated Backlight Red/Blue/Purple Multimedia Shortcut Keys Backlit Switchable Gaming USB Wired PC Keyboard for Professional Gaming Players
Net Weight: 810g
Normal Keys: 103
Media Keys: 6
Interface Type: USB
Product Positioning: Competitive gaming keyboard
USB Cable Length: 150cm
System Support: win9x, 2000, ME, XP, VISTA, win7, win8
Backlight turn off automatically when without typing in 10 minutes.
Sony BDPS3200 Blu-ray Disc Player with Wi-Fi
Accent your entertainment experience with unique design, super Wi-Fi, and 200+ streaming services1 like Netflix, YouTube, Hulu Plus, and more. Mirror your mobile device on your compatible TV with Miracast technology2…
24W Mini Multimedia LCD Image System LED Projector with SD / USB / AV / VGA /HDMI Port
Product Specifications: Model No.: mini projector Projection System: LCD Projection Image Size: 20-120 INCH Native Resolution: 320 x 240 Max. Resolution: 1920 x 1080 LED brightness: 400LM Color: 16770K Power: 24W Contrast Ratio: 300:1 Aspect Ratio:support 4:3/16:9 Focus: Manual Projection Distance: 1 ~3.8m Video Format: MPEG1 / MPEG2 / MPEG4 / RM RMVB / H264 / MOV / MJPEG / FLV / VC1 / DivX Pictur…
Dugeons & And Dragons Mens T-Shirt – Original Player Manual Artwork Image
This black 100% cotton tee is perfect for fans of Dungeons And Dragons….