Player Image

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?

VirtualBox

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.

Qemu

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

VMware

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

Juraj’s karma with FreeBSD

Let’s Play Mission 2: Team Player (Buy Modern Warfare 2?)


Eric Berry Tennessee Volunteers Adidas Player Image T-Shirt


Eric Berry Tennessee Volunteers Adidas Player Image T-Shirt



This 100% cotton Adidas NCAA Player Image T-Shirt features a screen print graphic of your favorite player’s name and image, plus the team logo on chest. Great for any fan! Officially licensed by the NCAA….


Official Licensed Premium GENUINE FC Barcelona Enhancing W/TEAM PLAYER IMAGES - Messi, Neymar & Others, prints Pencil Case / Pen Pouch DOUBLE FILL (2 Pockets) !! - Licensed FC Barcelona Merchandise


Official Licensed Premium GENUINE FC Barcelona Enhancing W/TEAM PLAYER IMAGES – Messi, Neymar & Others, prints Pencil Case / Pen Pouch DOUBLE FILL (2 Pockets) !! – Licensed FC Barcelona Merchandise


$16.99


FC Barcelona W/TEAM PLAYER IMAGES & SIGNATURE prints Pencil Case – DOUBLE FILL (with 2 pockets) – Official Licensed FC Barcelona Merchandise – with tags (pls se photos). Images made of beautiful PVC; Pencil case widens and enhances with zipper in the middle. Size 20″…

Peyton Manning Indianapolis Colts Reebok Youth Player Image T-Shirt


Peyton Manning Indianapolis Colts Reebok Youth Player Image T-Shirt



This Reebok youth Player Image t-shirt features a high end quality screenprinted graphic of your favorite NFL player. Made of 100% cotton and features a ribbed crew-cut collar. Officially licensed by the NFL….


Sharper Image Portable Cd/ Am-fm Radio Soother Si585 Sound Therapy


Sharper Image Portable Cd/ Am-fm Radio Soother Si585 Sound Therapy



They don’t make them like they use to
We have had hundreds of these CD units over the years.
Only TWO had the CD function not working.
Most CD units now-a-days last for 6 months before they have problems.
If you want a LONG lasting CD/Radio/Soother the older Sharper Image is the way to go
Sharper Image SI585 Clock Radio With Soother
The CD players last for years. New CD players last for months
Sm…


Sharper Image Personal Entertainment Center DVD/ TV/ CD/ Radio/ Sound Soother Player


Sharper Image Personal Entertainment Center DVD/ TV/ CD/ Radio/ Sound Soother Player


$499.99


Product Features:

Wide 7-inch TFT LCD Screen

DVD Player

TV/Cable Tuner

CD/MP3 Player

20 Soothering Sounds

Aluminum Cone Speakers

Wierless Remote Control

AM/FM Digital Tuner

Alarm Clock

Product Specifications:

DVD; TV; CD; AM/FM; 7″ LCD Display.
TV has cable-ready built-in Digital TV Tuner.
Programmable CD drive plays CD-R, CD-RW and CD-MP3.
Built-in Digital Tuner has 10 AM and 10 FM pre…


Sharper Image CD/Radio & Sound Soother With Aluminum Cone Speaker Technology SI785SIL - CD clock radio


Sharper Image CD/Radio & Sound Soother With Aluminum Cone Speaker Technology SI785SIL – CD clock radio



This beautifully trim, portable stereo features a CD player, an AM/FM/TV-band tuner, a Sound Soother with 20 soundscapes and more.
Each built-in speaker now features an aluminum cone diaphragm, a high-compliance suspension ring and an oversize neodymium magnet.
This new technology delivers super-high energy output, low distortion and enhanced frequency response that’s hard to believe in speakers …








OmniMount ECSB Component Shelf Wall Shelf for TVs and Video Accessories


OmniMount ECSB Component Shelf Wall Shelf for TVs and Video Accessories


$59.95


The ECS is a glass wall shelf that is designed to hold a cable box, DVD player, or virtually any other component that needs to be located near a mounted television….







New Era On field Sport Knit Game Hat


New Era On field Sport Knit Game Hat



Root for your team in this 2014 NFL On field Sport knit Game winter hat….