2015-08-04

Update to FreeBSD 9.3, FreeBSD has now Virtio drivers, remoce deprecated Information

← Older revision

Revision as of 07:48, 4 August 2015

Line 2:

Line 2:

Tweaks and tips for better performance with FreeBSD on KVM.

Tweaks and tips for better performance with FreeBSD on KVM.



:'''Note:''' This has been tested with FreeBSD 9.0-RELEASE and 9.1-RELEASE (and patch levels). Some steps have been removed as they have been deprecated in newer FreeBSD versions.

+

:'''Note:''' This has been tested with FreeBSD 9.3 RELEASE (and patch levels). Some steps have been removed as they have been deprecated in newer FreeBSD versions.

==Create VM==

==Create VM==



* Download the FreeBSD 9.1-RELEASE-amd64 DVD ISO (from [http://www.freebsd.org/where.html here]) and transfer it to your VM server.

+

* Download the FreeBSD 9.3-RELEASE-amd64 DVD ISO (from [http://www.freebsd.org/where.html here]) and transfer it to your VM server.

* Create a new VM:

* Create a new VM:

** CPU: dual-socket or dual-core

** CPU: dual-socket or dual-core

*** '''IMPORTANT:''' As of current PVE releases, you may need to set your CPU to '''qemu64''' rather than '''kvm64''' for FreeBSD to be able to boot.

*** '''IMPORTANT:''' As of current PVE releases, you may need to set your CPU to '''qemu64''' rather than '''kvm64''' for FreeBSD to be able to boot.

** RAM: 2GB (minimum)

** RAM: 2GB (minimum)



** Network: Intel e1000 (bridged)

+

** Network: Intel e1000 (bridged) or Virtio



** Create a 32GB primary disk (scsi, qcow2)

+

** Create a 32GB primary disk (scsi, qcow2) or Virtio

** Add FreeBSD 9.1-RELEASE-amd64 DVD ISO as an optical drive (scsi).

** Add FreeBSD 9.1-RELEASE-amd64 DVD ISO as an optical drive (scsi).

Line 27:

Line 27:

==First Boot==

==First Boot==

* Power on the VM and log in.

* Power on the VM and log in.

+

If you have choosed to use VirtIO devices you can check their existence with dmesg:

+

<pre>

+

dmesg | egrep '(vtnet|vtblk)'

+

vtblk0: <VirtIO Block Adapter> on virtio_pci1

+

vtblk0: 16384MB (33554432 512 byte sectors)

+

vtnet0: <VirtIO Networking Adapter> on virtio_pci2

+

vtnet0: Ethernet address: b2:ae:f1:97:36:52

+

</pre>

* Set the time:

* Set the time:

<pre>

<pre>

Line 37:

Line 45:

</pre>

</pre>

* Reboot

* Reboot



==Update Ports Tree==



Updating your ports tree will ensure that any ports you attempt to install will have the latest patches and download URLs.





* Update the ports tree using [http://www.freebsd.org/doc/handbook/updating-upgrading-portsnap.html portsnap]:



<pre>



portsnap fetch



portsnap extract



</pre>



* After the first run of portsnap, you can use the following command to perform later updates:



<pre>



portsnap fetch update



</pre>





==Enable Virtio==



* Install virtio-kmod:



<pre>



cd /usr/ports/emulators/virtio-kmod && make clean install



</pre>



* When prompted on each required package, accept defaults and OK.



* Add the following to <code>/boot/loader.conf</code>:



** '''Note:''' You may have to create this file.



<pre>



virtio_load="YES"



virtio_pci_load="YES"



virtio_blk_load="YES"



if_vtnet_load="YES"



virtio_balloon_load="YES"



</pre>



* Enable virtio for disk by changing your <code>/etc/fstab</code> entries to use the '''vtbd''' prefix. Example:



<pre>



# Device Mountpoint FStype Options Dump Pass#



/dev/vtbd0p2 / ufs rw 1 1



/dev/vtbd0p3 none swap sw 0 0



</pre>



* Enable virtio for network by changing the <code>ifconfig_em0="DHCP"</code> line in <code>/etc/rc.conf</code> to:



<pre>



ifconfig_vtnet0="DHCP"



</pre>



* Shutdown the VM



<pre>



shutdown -p now



</pre>



* Change VM's network and disk hardware to use virtio.



* Power on the VM.



* Verify that virtio is loading:



<pre>



kldstat





Id Refs Address Size Name



1 12 0xffffffff80200000 11cdab0 kernel



2 5 0xffffffff813ce000 4ca0 virtio.ko



3 1 0xffffffff813d3000 5880 virtio_pci.ko



4 1 0xffffffff813d9000 5010 virtio_blk.ko



5 1 0xffffffff813df000 aeb0 if_vtnet.ko



6 1 0xffffffff813ea000 3210 virtio_balloon.ko



</pre>





==Update Installed Ports==



It is a good idea to keep your installed ports up to date. This section shows you how to do so.



:'''IMPORTANT:''' It is recommended practice to understand how port updates will impact your system. Some port updates can change the way the program works and can break the function of your machine. '''It is wise to do a full backup of your VM before updating installed ports.'''





* Install [http://www.freebsd.org/cgi/url.cgi?ports/ports-mgmt/portmaster/pkg-descr portmaster]:



<pre>



cd /usr/ports/ports-mgmt/portmaster && make clean install



</pre>



* Run portmaster:



:'''Note:''' This step actually updates the installed ports on your system to their current versions. If you run into any errors, you will need to correct them and re-run portmaster to pick up where it left off.



<pre>



portmaster -a



</pre>



==External Links==

+

== Links ==



* [http://viktorpetersson.com/2012/01/16/how-to-upgrade-freebsd-8-2-to-freebsd-9-0-with-virtio/ How to upgrade FreeBSD 8.2 to FreeBSD 9.0 with Virtio] - contains useful information on setting up virtio on freebsd 9.



* [http://www.freshports.org/emulators/virtio-kmod FreshPorts virtio-kmod] page.



* Some pre-built virtio packages can be found [http://people.freebsd.org/~kuriyama/virtio/ here], and a mini-howto [http://dev.n0ll.com/tag/openstack/ here].

* [http://www.freebsd.org/doc/handbook/updating-upgrading-portsnap.html FreeBSD Handbook - Portsnap: a Ports Collection Update Tool]

* [http://www.freebsd.org/doc/handbook/updating-upgrading-portsnap.html FreeBSD Handbook - Portsnap: a Ports Collection Update Tool]

* [http://www.freebsd.org/cgi/url.cgi?ports/ports-mgmt/portmaster/pkg-descr freebsd.org - Port description for ports-mgmt/portmaster]

* [http://www.freebsd.org/cgi/url.cgi?ports/ports-mgmt/portmaster/pkg-descr freebsd.org - Port description for ports-mgmt/portmaster]

Show more