Saturday, August 18, 2012

FreeBSD make.conf example

make.conf stores system-wide build settings that apply each time you run make. Copy example:
cp /usr/share/examples/etc/make.conf /etc
Compile the source code specific to your CPU:
CPUTYPE?=native
It is recommended uncomment the following: CFLAGS, CXXFLAGS, COPTFLAGS.
# 2 jobs per CPU
MAKE_JOBS_NUMBER=4

# KNOBS -- A list of popular knobs and their descriptions
# http://svn.freebsd.org/ports/head/KNOBS?view=markup

# Do not to compile X11 support
WITHOUT_X11=
# Include python support, e.g. in Vim
WITH_PYTHON=
# Do not build and install the doc, examples, mans
WITHOUT_EXAMPLES=
WITHOUT_DOCS=
NOPORTDOCS=
NOPORTEXAMPLES=
NO_INSTALL_MANPAGES=

How to setup HTTP Proxy in FreeBSD

The HTTP proxy is set through environment variable HTTP_PROXY. Environment variables can be controlled during user login. Assuming the proxy is proxy.somewhere.net:3128 ensure the following in /etc/login.conf:
:setenv=HTTP_PROXY=http\c//proxy.somewhere.net\c3128:\
Update login capability database:
cap_mkdb /etc/login.conf
Re-login and ensure it is properly set:
env | grep HTTP_PROXY

How to SU with no password in FreeBSD

You can allow user to switch to root account without password. You need to add user to wheel group:
pw usermod john -G wheel
and change pam policy (file /etc/pam.d/su):
#auth            requisite       pam_group.so            no_warn group=wheel root_only fail_safe ruser
auth            sufficient      pam_group.so            no_warn group=wheel root_only fail_safe ruser
It is necessary to re-login so new group membership take place. Issue the following command to check user group:
$ id
uid=1001(john) gid=1001(john) groups=1001(john),0(wheel)

FreeBSD C Shell Tricks

C shell is default shell for root account in FreeBSD. You can control settings through the following configuration files:

~/.cshrc - user specific settings
/etc/csh.cshrc - global settings

Color Prompt: display hostname in red color for shell prompt (read more here):
set prompt="%{\033[1;31m%}%m %{\33[34m%}%. %{\033[0m%}%# "
set promptchars = "%#"
or if above doesn't work:
alias setprompt 'set prompt="%{\033[1;31m%}`/bin/hostname -s` %{\33[34m%}$cwd:t %{\033[0m%}# "'
setprompt
alias cd 'chdir \!* && setprompt'
List directories in color:
alias ls        ls -G
Del Key In Terminal:
bindkey ^[[3~ delete-char

FreeBSD Bourne Shell Tricks

Bourne shell is default shell for user account in FreeBSD. You can control settings through the following configuration files:

~/.shrc - user specific settings
/etc/profile - global settings

Color Prompt: display hostname in green color for shell prompt (read more here):
# vi ^[: ctrl+v and then Esc
#PS1="^[[32m$^[[0m "
PS1="^[[1;32m`whoami`@\h ^[[34m\W ^[[0m$ "
List directories in color:
alias ls='ls -G'
Color case insensitive grep:
export GREP_OPTIONS='-i --color=auto'

FreeBSD Virtual Machine Loader Settings

It is recommended to lower kernel internal timer rate and delay before auto booting: Add the following to /boot/loader.conf:
kern.hz=100 # The kernel interval timer rate
autoboot_delay=3 # Delay in seconds before autobooting
Read more here.