Friday, August 15, 2008

FreeBSD|Jingshao's FreeBSD Tips

Jingshao's FreeBSD Tips

FreeBSD Tips

Port management

To install application in unix is always not an easy job, but with FreeBSD's port system, this has been changed. It is so powerful and easy to use that installation and upgrading is as easy as in MS Windows (IMHO). It is also much easy to use and understand than Redhat's RPM.

In addition to the original pkg tools, there are many others to do port management in a more user friendly way. portupgrade is one of them.

 cvsup -g -L 2 /root/ports-supfile # keep latest portsdb -Uu                       # after cvsup, keep INDEX INDEX.db up to date make fetchindex                   # above step takes a long time. Use this to                                   # fetch the prebuilt INDEX from the NET. pkgdb -F                          # maintain ports database pkgdb -fu                         # rebuild ports database portversion                       # '=' '<' and '>' portupgrade portupgrade -P                    # using package portupgrade -rR                   # upgrade all dependencies portsclean -D                     # delete unlinked lib pkg_deinstall gdm2                # uninstall a package portsclean -C                     # clean up uncleaned ports 

Use cvsup and portupgrade to upgrade all applications to the latest version is a very good idea. Upgrade to the latest ports after the first installation will save a lot of trouble. Do it every month.

Desktop Envrionment

In 4.8, I chose KDE 3.1.1a. But in 4.9, I switched to GNOME 2.4.1.

KDE is definitly a beautiful desktop envrionment and has many good features. Konqueror integrate file manager and web browser, very fast and usable.

GNOME 2.4 has a lot of improvement over 2.2. Plus many good applications are based on gtk+, and these applications are better than the conterparts in KDE. I feel gtk2's widgets look much more comfortable than Qt's.

FVWM2

I am using fvwm a lot now. Fvwm is one of the most configurable window manager. It may not look pretty but its programmable behavior is really powerful. If you like programming, you definite should try it. Here is my config. I changed it mainly based on the default configure file.

I created a customized theme for FVWM2, which looks quite different from other wm or even FVWM itself. The innovation idea is remove title bar completely. I call it "headless FVWM". Check the screenshots to see the difference. It fully used the screen real estate and look very pretty.

The features in the configure file include:

  1. In order to control the windows without titlebars, 3 buttons are created on the top right corner of the screen.
  2. Left click on the frame to resize the window; right click to move; middle click to pop window options menu.
  3. Sloppy focus is disabled by click focus unfortunately. Because the window have to be focused when pointer is moved to the corner of the screen. If there is a timer for sloppy focus, just as the popup timer, that will be perfect.
  4. Miniature shot of windows are used as icon. This is taken from Tavis Ormandy. I added some code so it combines the icon file with the window snapshot to make an icon.
  5. FvwmIconMan is fully translucent. Combined with xft font and shadow, it creates a "light up" effect when selected, and is easy to see on both light and dark backgrounds.
  6. Dynamically constructs a background selection menu with preview.
  7. Maximized behavior is changed to that when one window is maximized, all other windows are iconified.

For other light weight window manager, fluxbox is very good. I recommend use the fluxbox-devel port. It has the latest translucent and other cool features.

How to enlarge fonts in gtk applications in fvwm or fluxbox?

The fonts of gtk applications looks way too small in FVWM or fluxbox. To change it, create .gtkrc-2.0 under you home directory. Add line gtk-font-name = "Helvetica 12" in it. You can also add include "{path to gtk themes}/gtk-2.0/gtkrc" in it to use an installed gtk theme.

Graphic log in

I am no longer use a graphic log in manager. Since now both gdm and kdm has the same problem - after log in and out a couple of times, screen is locked in power save mode. Try Ctrl-Alt-Backspace to restart X server may fix.

GDM2

When install gdm, the system will say that gdm has serious security holes and is not recommanded by FreeBSD*. Actually as long as XDMP is not enabled, gdm is fine, here is a quote from GDM document.

- Do _NOT_ use /etc/ttys to start gdm at boot time. This will result in gdm hanging or restarting constantly. Instead, copy the included gdm.sh.sample script to gdm.sh, and restart. This script is found, by default, in /usr/X11R6/etc/rc.d. Changing the contents of the 'Enable' variable to 0 in the gdm configuration file (often /etc/X11/gdm/gdm.conf) will eliminate this vulnerability.

GDM2 configure

Edit /usr/X11R6/etc/gdm/gdm.conf and add these to avoid an error message from gdm. "No server were defined in the configration file and XDMCP was disabled"

 [server-Standard] name=Standard server command=/usr/X11R6/bin/X flexible=true  [servers] 0=Standard 

Web browser

FireFox 1.0 is really a very good brower. Mozilla 1.7 is very good too. The advantage of Mozilla is it comes with Email, but FireFox has a better UI.

Firefox Icon

Replace the file default.xpm in /usr/X11R6/lib/firefox/chrome/icons/default with a nice one (png works too).

Firefox keybinding

I would like to use Ctrl-u to clear the location field. To enable that, add this line into ~/.gtkrc-2.0:
gtk-key-theme-name = "Emacs"

Where is firefox's re/buildin folder?

To change the keybindings, user need to modify the userHTMLBindings.xml or the platformHTMLBindings.xml in this directory. For FreeBSD, it is at:
/usr/X11R6/lib/firefox/res/builtin

Email

Client

For text email client, I use mutt with Chinese enabled. Here is my .muttrc

For gui, I prefer mozilla-mail or thunderbird.

MTA

Sendmail

Sendmail is the default mta shipped with FreeBSD. To configure it to use smtp to send email instead of using itself, do the following: (mutt use it to send email)

 cd /etc/mail vi sendmail.cf 

locate line

 # "Smart" relay host (may be null) DS 

and append your smtp server after DS

Postfix

Alternative MTA is Postfix. Edit /usr/local/etc/postfix/main.cf

  mydomain = {PUT YOUR DOMAIN HERE}   myorigin = $mydomain  relayhost = {PUT YOUR RELAY HOST HERE} 

Office Suite

Office suite is the most weak part in Unix. Especially when it has to be compatible with MS office. My overall choice is OpenOffice. OpenOffice, especially version 1.1.3 is very good.

The best way to install it is via package. Compiling such a big port is not worth the efforts. A google search for "OpenOffice Freebsd package" gave me some links to download the OpenOffice prebuild package. I used oootranslation.services.openoffice.org to download the latest stable one.

To setup printer in openoffice, run openoffice-1.1.3-spadmin

If OO is too slow/big for you, try these alternative ones:

  • Word processor: KWord or AbiWord
  • Vector Graphic: dia and inkscape
  • Spread Sheet: gnumeric

DVD playback

I am using Mplayer. I used to use ogle, but since I found this link: Installing Mplayer With Quicktime Support from bsdhound, I installed Mplayer and am suprised to see how cool it is. Also do a search on "bsdhound mplayer" will give some other good documents on that site.

At first, mplayer didnot display the pictures on my monitor when the laptop was in dock station. After I change the -vo option to x11, it shows. Actually, do a mplayer -vo help lists all available video output drivers. "xv" did not work for me, but "x11, gl, gl2" all work.

Notes for ogle

Under kde, ogle need to be run as "artsdsp ogle". But the quaulity is unacceptable.

Under gnome or fluxbox, ogle plays DVD without noticable drops. one bug is stop button does not work. Another bug is sometimes, ogle lose the track of sound and playback lose synchronize. Close it and play again may fix it. (under linux, due to the poor implementation of css, DVD playback is not as good. But there is ALSA promising a solution. I failed to install ALSA however)

CD-RW

cdrecord -scanbus cdrecord -v -eject speed=4 dev=0,3,0 xxx.iso 

Accessing unix box

I like ssh. It replaces rsh, rcp, rlogin, telnet, ftp. It is secure, easy to use and very powerful (local and remote port forwarding).

 ssh [UNIX MACHINE]  xterm -tn dtterm -T "REMOTE UNIX" -e ssh -Y -t "REMOTE UNIX" tcsh scp [UNIX MACHINE]:~/doc/abc.doc . scp abc.doc [UNIX MACHINE]:~/doc/abc.doc 

To allow x sessions from unix box

Need -Y in ssh options.

How to make X look better?

Use XFree86 version 4.3.0 and up

XFree86 -version will show the version.

Enable true type font support

Add this line: load "freetype" under Section "Module" in /etc/X11/XF86config file.

Copy true type fonts from windows

  • Make a directory under /usr/X11R6/lib/X11/fonts/, say TrueType.
  • Copy all ".ttf" files from windows (Normally under WINNT/Fonts) to /usr/X11R6/lib/X11/fonts/TrueType.
  • Run mkfontscale and ttmkfdir.
         cd /usr/X11R6/lib/X11/fonts/TrueType     mkfontscale     ttmkfdir > fonts.dir    
  • Add this line: FontPath "/usr/X11R6/lib/X11/fonts/TrueType/" in /etc/X11/XF86config under Section "Files".

If Window2000 is installed on the same machine, and is on ad0s1, add this line in /etc/fstab to mount it. (/windows must be create by root at first)

/dev/ad0s1    /windows   ntfs  ro 0       0 

Fine Tune anti-alias

It should be much better now. However, to make regular fonts look more sharp, need to disable anti-alias for fonts less than 16 points.

Modify local.conf under /usr/X11R6/etc/fonts (create one if not exist) like this:

 <?xml version="1.0"?> <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <fontconfig> <!-- Enable sub-pixel rendering         <match target="font">                 <test qual="all" name="rgba">                         <const>unknown</const>                 </test>                 <edit name="rgba" mode="assign"><const>rgb</const></edit>         </match>          -->         <match target="font">             <test name="size" compare="less">                 <double>16</double>             </test>             <edit name="antialias" mode="assign">                 <bool>false</bool>             </edit>         </match> </fontconfig> 

Install cool themes for gnome

http://art.gnome.org

Enable mouse scroll wheel support in X

Add Option "ZAxisMapping" "4 5" under Section "InputDevice" in /etc/X11/XF86config.

Chinese

Chinese is supported very well in GNOME, KDE and XFCE. When using Fluxbox, icewm, windowmaker or fvwm, make sure to either comment all font configure in configure (theme) file, or specify the fonts with gb2312.1980-0 encoding. -*-*-*-*-*-*-*-*-*-*-*-*-gb2312.1980-0 or -*-simsun-*-*-*-*-12-*-*-*-*-*-gb2312.1980-0 will be ok. I am using GB encoding.

Tools for Chinese are (all except rxvt are under /usr/ports/chineses):

  • Chinese input: fcxit
  • Chinese terminal: rxvt (WITH_ENCODING=gb)
  • Text email client: zh-mutt
  • Vi like chinese text editor: celvis

Settings

It is very straitforward. If you are using startx to start your desktop,

  1. add these lines into your .login_conf:
     me:\         :charset=zh_CN.EUC:\         :lang=zh_CN.EUC 
  2. Add these lines into .cshrc (if you use bash, set the environment virables in .profile):
     setenv XMODIFIERS "@im=fcitx" setenv XIM fcitx setenv XIM_PROGRAM fcitx setenv LANG zh_CN.EUC setenv LC_CTYPE zh_CN.EUC 

If you are using GDM to start your desktop, you need to modify this file: /usr/X11R6/etc/gdm/Xsession. Find these lines:

 # Normalize languages, some places/distros screw us up in /etc/profile, # so in case the user did select a language if [ -n "$GDM_LANG" ]; then   LANG="$GDM_LANG"   export LANG 

and add these lines after export LANG to set X input environment virables.

 if [ "x$LANG" = "xzh_CN.EUC" ]; then     XMODIFIERS="@im=fcitx";  export XMODIFIERS     XIM=fcitx;               export XIM     XIM_PROGRAM=fcitx;       export XIM_PROGRAM     LC_CTYPE=$LANG;          export LC_CTYPE fi 

Then when you login through GDM, choose Chinese (Simplified) from the language option.

To invoke Chinese input, type fcitx from a terminal

Dictionary

stardict is a very good dictionary.

pppoe configure

 more /etc/ppp/ppp.conf default:  set log Phase Chat LCP IPCP CCP tun command  set ifaddr 10.0.0.1/0 10.0.0.2/0 255.255.255.0 0.0.0.0 sbc:  set device PPPoE:fxp0  set authname username  set authkey ********   set dial  set login  enable dns  add default HISADDR                    # Add a (sticky) default route 

To launch pppoe, ppp -ddial sbc as root.

To start pppoe at boot, add the following to /etc/rc.conf file:

 ppp_enable="YES" ppp_mode="ddial" ppp_nat="YES" # if you want to enable nat for your local network, otherwise NO ppp_profile="name_of_service_provider" 

Instant Messenger

I use Gaim. It can handle MSN messenger.

Image manipulate

I use gimp + inkscape for manual editing and ImageMagick for command line.

Sound manipulate

 cat chinaanthem.au > /dev/audio sox chinaanthem.au chinaanthem.wav trim 00:00:1 00:00:6 play chinaanthem.wav 

A good practice is to change GNOME startup melody:

 cd music sox -v 2 chinaanthem.au -r 44100 chinaanthem.wav mask fade 0 6 3 trim 00:00:1.5 play chinaanthem.wav Applications --> Desktop Pereference --> Sound --> login 

Wireless

Use ancontrol ... After this, do "ifconfig" you will see the status of an0 is associated.

Then you may need to reset dhclient to change the default gateway via the wireless interface.

 dhclient -r fxp0 dhclient an0 

Also, Cisco Aironet 350 need firmware 5.00.20 to work under FreeBSD.Downgrade the firmware is needed.

Home freebsd nat ipfw rules

I use a PentiumII 350 at home as a gateway. It is configured with ipfw. For ipsec VPN to tunnel through, rule 500 to 504 are set.

00050 divert 8668 ip from any to any via tun0 00100 allow ip from any to any via lo0 00110 allow ip from 192.168.0.0/24 to any via vr0 00150 allow udp from any to any dst-port 53 keep-state 00151 allow udp from any 53 to any 00162 allow tcp from any to any out via tun0 keep-state 00200 deny ip from any to 127.0.0.0/8 00300 deny ip from 127.0.0.0/8 to any 00400 allow tcp from any to any established 00500 allow udp from any to any dst-port 137 00501 allow udp from any to any dst-port 62514 via tun0 00502 allow udp from any to any dst-port 500 00503 allow ip from any to any frag 00503 allow udp from any to any dst-port 10000 65535 deny ip from any to any 

VPN

VPN with my company is not easy. The only way to do so is through ssh port forwarding.

 ssh -R 2222:localhost:22 -N company.host  -R port:host:hostport         Open port on remote machine. All traffic on remote         machine to this port will be forward through the ssh tunnel to local,        then forwarded from local to host:hostport  -N             Do not execute a remote command. 

Later, on company.host, I just need to do an ssh -p 2222 localhost to access back my home PC.

Useful Unix tips

How to find the largest files in current directory?

Use this :

find . -type f -print0 | xargs -0 ls -l | sort -r -n -k 5,5 | head 

How to find broken symbolic links?

( find . -type l -print0 | xargs -0 file ) | grep 'broken symbolic link' 

NOTE: in find, use -print0 instead of -print gives \0 terminated strings, this preserves space in such as file names so xargs -0 will not provide truncated arguments to command.

How to use memory key

mount -t msdos /dev/da0s1 /mnt

How to find a key name?

Use xev to find out what is the keycode and keysym.
Key names are defined in the key symbol def file: /usr/X11R6/include/X11/keysymdef.h discard the "XK_" part.

Nothing

I wish I was back in university ...UM

No comments: