Creating & Installing FreeBSD 8 / KDE 4 Guest VMware Virtual Machine

Photobucket

[Click to enlarge: FreeBSD 8 running KDE 4.3.5. Linux htop, sudo wireshark, youTube Flash video]

Steps to install a VMware virtual machine running FreeBSD 8 running KDE 4 and Firefox with Flash 10 support.  I don’t really go into the reasons behind the steps so it’ll be helpful if you already have prior experience with installing and setting up FreeBSD systems.

VIRTUAL MACHINE CREATION
Select other OS: freebsd
Make a 50GB file. 50 GB should provide enough space to compile ports.
>2GB RAM reserved for VM
Set the VM cdrom to load the FreeBSD 8 installation ISO file.

START INSTALLING OS AND REST OF SYSTEM
Start CDROM installation
Initialize filesystem with following suggested settings
Use whole slice for FreeBSD then create following paritions:

[Good BSD partition scheme for a virtual machine]
/    2G
swap 2GB
/var 10G
/tmp 2G
/usr >30G  (compiling KDE4 port will consume a peak of 17GB hard drive space)

Install the standard boot manager (directly to FreeBSD)

Install custom from CDROM, select base, src, etc (but not ports since will be installed later).
Avoid installing any packages at this point, will be using the awesome ports system instead.
Set up the system config stuff like timezone, network config, mouse, etc

After reboot:

Adding the user to wheel group (so can su)
pw group mod wheel -m jared

Edit /etc/hosts to include hostname
127.0.0.1               yourhost yourhost.jared.com

SETTING UP THE FREEBSD KERNEL
Copy the working default kernel in a safe place so can load it if end up with a bad kernel after a kernel compile.
cp -R /boot/kernel /boot/kernel.good

cvsup no longer necessary- use csup, included in base system now.
mkdir -p /usr/local/etc/cvsup
cp /usr/share/examples/cvsup/standard-supfile  /usr/local/etc/cvsup
Edit /usr/local/etc/cvsup/standard-supfile  (I usually use cvsup2.us.freebsd.org)

GET LATEST KERNEL VERSION AND UPDATING FREEBSD KERNEL
cd /usr/src
csup /usr/local/etc/cvsup/standard-supfile (while this is running, can do the portsnap fetch/extract step below to save some time)
make update   (to update kernel files)

mkdir /root/kernels
cd /usr/src/sys/i386/conf
cp GENERIC CUSTOM
mv GENERIC /root/kernels
mv CUSTOM /root/kernels
ln -s /root/kernels/GENERIC GENERIC
ln -s /root/kernels/CUSTOM CUSTOM
vi /root/kernels/CUSTOM and edit
Inlude these options for a high-res console:
options VESA            # for high resolution screen
options SC_PIXEL_MODE   # for high resolution screen

(side note regarding hi-res console: after rebooting into the new kernel, you can run:

add to /etc/rc.conf to enable high resolution console if desired
allscreens_flags=”MODE_279″

To see what modes are available.
vidcontrol -i mode

Test the screen mode
vidcontrol MODE_279

Check out file /usr/src/UPDATING for any special information

make -j4 buildworld
make buildkernel KERNCONF=CUSTOM
make installkernel KERNCONF=CUSTOM

reboot and at boot screen, go to single user mode

(Note: if new kernel is bad and causes a lot of problems:
Reboot and select the “Escape to a loader prompt” option, number six. At the prompt, type unload kernel and then type boot /boot/kernel.good/kernel  You can then proceed to fix the new kernel problems and do another kernel compile.)

To install new world:
Once in single user mode:
fsck –p
mount –u /
mount –a –t ufs
swapon –a
adjkerntz –i

cd /usr/src
mergemaster –p
use new file, merge with current file, or delete new file
make installworld KERNCONF=CUSTOM
mergemaster
use new file, merge with current file, or delete new file
reboot

RUN PORTSNAP TO EXTRACT/INSTALL LATEST PORTS.

An useful tip after installing new programs from the ports:
Depending on your shell, rehash or hash -r will refresh your current environment and be able to find the newly installed programs. No need to log out and log back in to get at the new commands.

cd /usr/ports
Portsnap is included as of FreeBSD 6.2. No need to install from packages or ports
Edit /etc/portsnap.conf (make sure two REFUSE foreign languages lines aren’t commented out)
portsnap fetch  (downloads a huge file >60MB)
Only do this once for the first time: portsnap extract.
Do a ‘portsnap update’ when updating ports again in future.

install the port for portsupgrade (which includes portsdb).
cd /usr/ports/ports-mgmt/portupgrade
make config-recursive
make install clean

CHECK TO SEE IF ANY INSTALLED PROGRAMS NEEDS AN UPDATE AND PERFORM THE UPDATES
cd /usr/ports
make fetchindex
portsdb –u
portversion –v –l “<”
Check /usr/ports/UPDATING for information you need to do before portupgrading
portupgrade –varR
(if there are problems with a port, i.e. may have been moved, do a portupgrade -f [port])

ENABLING LINUX BINARY COMPATIBILITY

/etc/rc.conf
linux_enable=”YES”

kldload linux
kldstat to make sure linux.ko shows up

/etc/make.conf
OVERRIDE_LINUX_BASE_PORT=f10
OVERRIDE_LINUX_NONBASE_PORTS=f10

/etc/sysctl.conf
compat.linux.osrelease=2.6.16

sysctl compat.linux.osrelease=2.6.16

/etc/fstab
linproc   /usr/compat/linux/proc    linprocfs    rw   0    0

mkdir -p /usr/compat/linux/proc
mount /usr/compat/linux/proc

cd /usr/ports/emulators/linux_base-f10/
make config-recursive
make install clean

INSTALL VMWARE GUEST TOOLS FROM THE ISO IMAGE
(VMware workstation 7 has vmtools ISO for FreeBSD 8)
Load vmware’s freebsd.iso in CDROM or VMware menu, install VMware Tools.

cd /usr/ports/misc/compat6x
make install clean

mount /cdrom
cd /tmp
tar zxf /cdrom/vmware-freebsd-tools.tar.gz
umount /cdrom

Run the VMware Tools installer.
cd vmware-tools-distrib
./vmware-install.pl

Run the configuration program and accept default values.
vmware-config-tools.pl

SET UP NTPD
in /etc/ntp.conf:
make sure this isn’t commented out:

restrict 127.0.0.1

in /etc/rc.conf:
# Allow clock to be constantly updated
ntpd_enable=”YES”

BETTER VIRTUAL MACHINE PERFORMANCE
add kern.hz=50 to /boot/loader.conf

INSTALL BASH
cd /usr/ports/shells/bash
make install clean

SETUP CONVENIENT SHORTCUTS IN .BASHRC
# .bashrc – Bourne Again SHell configuration file for interactive shells.
# file permissions: rwxr-xr-x
umask 022
HISTFILESIZE=2000
HISTSIZE=2000

#Limit core files to 0
ulimit -c 0

BLOCKSIZE=K; export BLOCKSIZE
#EDITOR=/usr/local/bin/vim; export EDITOR
PAGER=/usr/bin/less; export PAGER
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin:/usr/local/kde4/bin:$HOME/bin:. ; export PATH

# some useful aliases
alias updatelocate=’/usr/libexec/locate.updatedb’
alias down=’shutdown -h now’
alias h=’fc -l’
alias j=jobs
alias m=$PAGER
alias g=’egrep -i’
alias renew=’source ~/.bashrc’

alias disksize=’df -kh’
alias dirsize=’du -h -d 1 .’
alias free=’top -d1 | head -5 | tail -2′
alias showpath=’echo $PATH | tr -s ”:” ”\\012”’
alias listpkgs=’pkg_info | less’
alias gowww=’cd /usr/local/www/data’
alias editphp=’vi /usr/local/etc/php.ini’
alias editphpini=’vi /usr/local/etc/php/extensions.ini’

# checking RAID disks
#alias checkdisk0=’smartctl -a –device=3ware,0 /dev/twe0′
#alias checkdisk1=’smartctl -a –device=3ware,1 /dev/twe0′
#alias runcheckdisk0=’smartctl -t long –device=3ware,0 /dev/twe0′
#alias runcheckdisk1=’smartctl -t long –device=3ware,1 /dev/twe0′
#alias checkraid=’tw_cli /c0 show’

# set prompt
PS1=”[\u]:\w $ ”
PS2=”>”

#Web control shortcuts

alias restartwww=’/usr/local/etc/rc.d/apache22 restart’
alias editwww=’vi /usr/local/etc/apache22/httpd.conf’
alias editvhosts=’vi /usr/local/etc/apache22/extra/httpd-vhosts.conf’

# MySQL/Postgresql control shortcuts
alias restartmysql=’/usr/local/etc/rc.d/mysql-server restart’
alias editpg=’vi /usr/local/pgsql/data/postgresql.conf’
alias editpgaccess=’vi /usr/local/pgsql/data/pg_hba.conf’
alias restartpg=’su -l pgsql -c “pg_ctl restart -D /usr/local/pgsql/data”‘

# finding filenames in current directory and subdirectories – Bash
function findfile() { find . -type f -iname ‘*’$*’*’ -ls ;}

# finding a text string in files in current directory and sub-directories – Bash
function findtext() { find . -exec egrep $* \{\} /dev/null \; ; }

# finding a directory in sub-directories – Bash
function finddir () { find . -type d -iname ‘*’$*’*’ -ls ; }

#function httpconnections () { netstat -la | grep http | sort | awk -F” ” ‘{ printf “%-50s %s\n”, $5, $6 }’ ; }

#function httpwho() { netstat -la | grep zeus\.http | sort | awk -F” ” ‘{ printf “%-50s\n”, $5}’ | sed ‘s/.[0-9][0-9][0-9][0-9][0-9]//’ | sed ‘s/.[0-9][0-9][0-9][0-9]//’ | uniq | grep -v zeus ; }

# Detecting Emacs sub-shell in Bash shell
[ "$EMACS" == 't' ] && PS1=”[\u]:\w $ ”
[ "$TERM" == "screen" ] && PS1=”s[\u]:\w $ ”

# Colorized ls
# FILE-TYPE =fb
# where f is the foreground color
# b is the background color
# So to setup Directory color blue setup DIR to ex
# Default for all
# Color code (fb)
# a black
# b red
# c green
# d brown
# e blue
# f magenta
# g cyan
# h light grey
# A bold black, usually shows up as dark grey
# B bold red
# C bold green
# D bold brown, usually shows up as yellow
# E bold blue
# F bold magenta
# G bold cyan
# H bold light grey; looks like bright white
# x default foreground or background

# search path for cd(1)
# CDPATH=.:$HOME
# Colour code
DIR=Dx
SYM_LINK=Gx
SOCKET=Fx
PIPE=dx
EXE=Cx
BLOCK_SP=Dx
CHAR_SP=Dx
EXE_SUID=hb
EXE_GUID=ad
DIR_STICKY=Ex
DIR_WO_STICKY=Ex
# Want to see fancy ls output? blank to disable it
ENABLE_FANCY=”-F”

export LSCOLORS=”$DIR$SYM_LINK$SOCKET$PIPE$EXE$BLOCK_SP$CHAR_SP$EXE_SUID$EXE_GUID$DIR_STICKY$DIR_WO_STICKY”

[ "$ENABLE_FANCY" == "-F" ] && alias ls=’ls -GF’ || alias ls=’ls -G’

# now some handy stuff
alias l=’ls’
alias ll=’ls -laFo’
alias lm=’ll|less’
alias lsize=’ls -alhSr’
alias llc=’echo Total number of files `ll | wc -l` in `pwd`’

alias del_mailqueue=’postsuper -d ALL’

alias banipshow=’pfctl -t bruteforce -T show’
alias banipshowperm=’pfctl -t permanentban -T show’
alias banipclear=’pfctl -t bruteforce -T flush’
alias banipclearperm=’pfctl -t permanentban -T flush’

function banip() { pfctl -t bruteforce -T add $@ ; }
function banipperm() { pfctl -t permanentban -T add $@ ; }

alias listsockets=’sockstat -4′

#alias vi=vim
alias c=clear
alias d=”ls -l”

Add above the last ‘endif’ and inside the if ($?prompt) block of .cshrc:
[ -x /usr/local/bin/bash ] && exec /usr/local/bin/bash
Reason for this: if boot into single mode without mounting, need to skip loading of bash shell.

For regular users, change to csh shell, which will in turn start a bash shell:
chsh jared
Shell: /bin/csh

SETTING UP A KDE4 ENVIRONMENT
Excellent instructions here at ( http://bit.ly/cmWJmg )

install x11/xorg port

/etc/rc.conf
hald_enable=YES”
dbus_enable=”YES”

Run vmware-config.pl again to properly set up /etc/X11/xorg.conf

startx (to test)
type exit in all xterm windows to return to command prompt.

install x11/kde4 port (warning: takes a LONG time!!!)

Inside ~/.xinitrc
PATH=/usr/local/kde4/bin:$PATH
export PATH
exec startkde

Install few more nice-looking fonts for Xorg:
cd /usr/ports/x11-fonts/urwfonts
make install clean

Add sound support to /boot/loader.conf (prevents KDE4 from complaining)
snd_es137x_load=”YES”

kldload snd_es137x

startx

After KDE4 working, install ports for firefox with flash10 support:
( http://www.freebsd.org/doc/handbook/desktop-browsers.html )

www/firefox

Add to /boot/loader.conf
sem_load=”YES”

www/nspluginwrapper
www/linux-f10-flashplugin

Exit superuser mode and return to normal user:
nspluginwrapper -v -i /usr/local/lib/npapi/linux-f10-flashplugin/libflashplayer.so

Unfortunate warning: Flash10 doesn’t have strong support in FreeBSD. Expect Firefox to freeze for few seconds once in a while before resuming normal operations. (npviewer.bin core dumps). Not a show-stopper but is a bit annoying.

AUTOMATICALLY BOOT INTO KDE AT SYSTEM STARTUP

Inside /etc/ttys

Add this line:
ttyv8 “/usr/local/kde4/bin/kdm -nodaemon” xterm on secure

SETTING UP PASSWORD-PROTECTED SUDO FOR USERS IN WHEEL GROUP
Useful when starting programs such as wireshark which will not run as superuser in X display environment.

cd /usr/ports/security/sudo
make install clean

edit /usr/local/etc/sudoers and uncomment this line:
%wheel ALL=(ALL)  ALL

add user to the wheel group
pw user mod jared -G wheel

This entry was posted in FreeBSD. Bookmark the permalink.