# migrate a physical FreeBSD Server to Virtual (VMware)



## levros (Aug 29, 2011)

Hi,

I'm trying to migrate a physical FreeBSD Server to a Virtual Machine. I understand it can be done by installing a basic FreeBSD on the VM and then using the dump and restore commands. I also believe it is possible using third party software such as CloneZila. The problem is I don't know how to use the FreeBSD system.

Does anyone know a way to migrate/clone/duplicate a physical FreeBSD server to a virtual machine (running on VMware ESX/ESXi) with minimum configuration at the FreeBSD system?

Thank you.


----------



## wblock@ (Aug 29, 2011)

It can be done brute-force, just binary-copy the FreeBSD hard drive (dd(8) or whatever tool is handy) and use that as a raw image for the VM.  It'll waste disk space, but should be fine otherwise.

The disk and Ethern device names will probably be different on the VM, so /etc/fstab and /etc/rc.conf will need to be adjusted.


----------



## vizkr (Aug 30, 2011)

*test test test first*

Suggest you do several new installs first to ensure that you've gotten the drive labels and device names riddled out. Also your ethernet devices need to be properly configured. You can always try to use the ethernet renaming feature to finagle the interfaces (see Renaming ethernet interfaces under FreeBSD http://bit.ly/q1d1hI).

In either case the point I trying to make is that you should do a few new installation dry runs first to get familiar with FreeBSD running under virtualization before you do a full on migration.

Cheers,
m!


----------



## levros (Aug 30, 2011)

I used Acronis to back up the physical server and then restored the virtual machine but I get the following error when the virtual machine boots: 
	
	



```
ROOT MOUNT ERROR
```


----------



## wblock@ (Aug 30, 2011)

That's because the drive number changed, like ad0 became ad4.  Figure out what it changed to, enter that manually at the prompt (ufs:/dev/ad4s1a) and it will boot into single user mode.  Then mount the other partitions, edit /etc/fstab for the new drive numbers, and it'll be fixed.

Labels avoid all that.


----------



## levros (Aug 31, 2011)

Thanks wblock,

I entered the drive number and was able to get into single user mode but I don't know how to edit /etc/fstab.

When I write: `/etc/fstab` I receive a message: 
	
	



```
permission denied
```


----------



## wblock@ (Aug 31, 2011)

Single user mode only mounts /, and read-only.  So remount it:
`# mount -u /`

Then look at /etc/fstab:
`# cat /etc/fstab`

Manually mount the /var, /tmp, and /usr partitions, making the drive number adjustment when you do.  Then you'll be able to edit /etc/fstab and change those numbers.

But since you're going to all that trouble, you might as well fix it so it doesn't care about drive numbers or device names: FreeBSD Labeled Filesystems.


----------



## DutchDaemon (Aug 31, 2011)

(and in case you hadn't noticed: /etc/fstab is a file, not a command)


----------



## levros (Sep 1, 2011)

Thanks again,

I managed to do the [cmd=]mount -u /[/cmd] and the [cmd=]cat /etc/fstab[/cmd] commands. Then I received a list with "device" , "mountpoint", "fstype" ....(attached file)

How do I manually mount the /var, /tmp, /usr partitions? Is it something like:
[cmd=]mount rw /dev/ad0s1d /var[/cmd]
?

After that how do I edit the fstab file and save the changes?

Sorry about my questions, it's because I started to work with FreeBSD only a week ago 

So any help will be appreciated.


----------



## levros (Sep 1, 2011)

Please ignore the line : "After that how do i edit the fstab file and save the changes".

I understood that it's like in linux (vi filename...)


----------



## wblock@ (Sep 1, 2011)

levros said:
			
		

> How do I manually mount the /var , /tmp , /usr partitions? Is it something like:
> "mount rw /dev/ad0s1d /var"



See mount(8).  The rw option is default, and not entered that way.  So just
`# mount /dev/ad0s1d /var`
(Assuming that's the right device.  I didn't download and extract the zip file, next time just use plain text.)



> After that how do i edit the fstab file and save the changes?



Run a text editor on it.  There are two editors that come stock, ee(1) and vi(1).  The first is easier if you've never used either.


----------



## levros (Sep 1, 2011)

Thank you very much wblock,

I mounted the partitions and then edited the fstab, after that I rebooted the system and everything works 

There is only one more issue I want to ask you:

Is there a command the zeroes the unused space of the disk? For example: the slice is 50GB but only 5GB are used. When I back up the system using Acronis I get a file of ~5GB but when I try to restore that file on a different server I can't do it unless the destination hard disk is 50GB or more.

I tried the following command: [cmd=]dd if=/dev/zero/ of=filler bs=1m; rm filler[/cmd] and I got the error:

```
"dd: /dev/zero/: not a directory"
"rm: filler: no such file or directory"
```


----------



## wblock@ (Sep 1, 2011)

Anything that does a binary backup will waste a lot of time and space.  Even with compressible zeros filling the empty space, they still have to be read.  So I suggest you look up dump(8) and restore(8).  I have an article on that: Backup Options For FreeBSD.

The problem with the command is one too many / characters.  /dev/zero is a device, not a directory.


----------



## wblock@ (Sep 1, 2011)

Rereading post #12 makes me realize that I didn't answer the question.

Acronis reads every disk block on the 50G slice and puts them into a compressed file.  It doesn't know the UFS filesystem, so it doesn't know which of the blocks are actually in use.  So it has to copy every block, all 50G.  No matter how big the resulting compressed backup file, the restore has to be to an identically-sized slice.

dump(8) and restore(8) are backup and restore programs that understand the layout of a UFS filesystem.  dump only backs up used blocks, so backups are much smaller.  restore writes files, not blocks, and can restore to a smaller or larger filesystem.

Note that the boot block and disk partition table are not part of a filesystem.  dump won't back them up, and a disk without them won't boot.  Disk Setup On FreeBSD shows how to set up a blank disk from scratch.


----------



## levros (Sep 7, 2011)

thanks wblock.
its solved my problems.


----------

