Basic OpenBSD Setup as Desktop (OpenBSD值得研究 ^_^)

4839阅读 0评论2012-06-03 ulovko
分类:BSD

1> 安装 OpenBSD5.1 的准备工作

下载地址:ftp://ftp.openbsd.org/pub/OpenBSD/5.1/amd64/install51.iso
官方最新FAQ:ftp://ftp.openbsd.org/pub/OpenBSD/doc/history/obsd-faq49.pdf
官方最新PF:ftp://ftp.openbsd.org/pub/OpenBSD/doc/history/pf-faq49.pdf
简体中文FAQ:

=== OpenBSD5.1 系统配套歌曲 ===
MP3格式:ftp://ftp.openbsd.org/pub/OpenBSD/songs/song51.mp3
OGG格式:ftp://ftp.openbsd.org/pub/OpenBSD/songs/song51.ogg
=== OpenBSD5.1 系统配套歌曲 ===

2> 请开始安装 OpenBSD5.1

安装教程:

启动计算机开始安装:
重启计算机:
使用刚刚创建的普通用户登陆:
登陆后查看邮件:
切换到root,向dmesg@openbsd.org发送机器信息为社区的发展尽一份心力(PS: 不要老发虚拟机信息)!
# visudo  (如图中所示,允许wheel组使用sudo ^_^)
测试 sudo是否配置成功:

3> 简单认识OpenBSD5.1

  1. # cat /etc/myname        (查看主机名)
  2. obsd5.kotzu.org
  3. # cat /etc/hostname.em0  (查看网卡配置)
  4. dhcp
  5. # cat /etc/hostname.em0  (静态地址会是这样)
  6. 192.168.1.11 255.255.255.0 NONE NONE   (依次是:inet ipaddress netmask broadcastaddress options)
  7. # cat /etc/mygate        (配置网关地址)
  8. 192.168.1.1
  9. # cat /etc/resolv.conf   (配置DNS)
  10. search kotzu.org
  11. nameserver 202.106.46.151
  12. nameserver 202.106.0.20
  13. lookup file bind



4> 关于boot菜单 /etc/boot.conf

  1. boot> set timeout 60      (boot delay, 5 seconds by default)
  2. boot> boot -s             (To boot into single-user mode)
  3. #/bin/sh /etc/netstart    (Start the network while in single-user mode)

  4. boot> boot -s /bsd.old    (To boot an old kernel in single-user mode)
  5. # man boot
  6. FILES
  7.      /usr/mdec/biosboot    first stage bootstrap
  8.      /usr/mdec/pxeboot     PXE bootstrap
  9.      /boot                 system bootstrap
  10.      /etc/boot.conf        system bootstrap's startup file
  11.      /bsd                  kernel image
  12.      /bsd.sp               kernel image for single processor machines
  13.      /bsd.mp               kernel image for multiprocessor machines
  14.      /bsd.rd               kernel image for installation/recovery

  15. EXAMPLES
  16.      Boot the default kernel:

  17.            boot> boot

  18.      Remove the 5 second pause at boot-time permanently, causing boot to load
  19.      the kernel immediately without prompting:

  20.            # echo "boot" > /etc/boot.conf

  21.      Use serial console.  A null modem cable should connect the specified
  22.      serial port to a terminal.  Useful for debugging.

  23.            boot> set tty com0

  24.      Invoke the serial console at every boot:

  25.            # echo "set tty com0" > /etc/boot.conf


5> 使用本地化语言(简体中文)

  1. $ ls /usr/share/locale/zh_
  2. zh_CN.GB18030/         zh_CN.eucCN/        zh_TW.Big5/        zh_TW.eucTW/
  3. zh_CN.UTF-8/           zh_TW.BIG5/         zh_TW.UTF-8/

  4. $ vim ~/.profile
  5. export LANG="zh_CN.UTF-8"
  6. export LC_CTYPE="zh_CN.UTF-8"         (字符类型)
  7. export LC_COLLATE="zh_CN.UTF-8"         (字符对比规则)
  8. export LC_TIME="zh_CN.UTF-8"         (时间类型)
  9. export LC_NUMERIC="zh_CN.UTF-8"         (数字类型)
  10. export LC_MONETARY="zh_CN.UTF-8" (货币类型)
  11. export LC_MESSAGES="zh_CN.UTF-8" (消息/提示类型)
  12. export LC_ALL="zh_CN.UTF-8"
  13. :wq
  14. $ exit            (注销生效)
  15. 恭喜阁下终于看到母语了^_^
  16. --------------------------------------------4.8之前的版本可能要用zh_CN.eucCN
  1. # cd /usr/src/share/locale/ctype
  2. # vim Makefile
  3. LOCALES += zh_CN.eucCN
  4.  LOCALESRC_zh_CN.eucCN = zh_CN.eucCN
  5. LOCALES += zh_CN.UTF-8
  6.  LOCALESRC_zh_CN.UTF-8 = en_US.UTF-8
  7. :wq
  8. # cd ..
  9. # make && make install && make clean
About eucCN: 

6> 配置PACKAGE & PORTS & SRC

PACKAGE:

  1. $ vi ~/.profile
  2. export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/5.1/packages/`machine -a`/
  3. # export PKG_PATH=ftp://ftp.jaist.ac.jp/pub/OpenBSD/5.1/packages/`machine -a`/
  4. export FETCH_PACKAGES=yes
  5. :wq
  6. $ exit            (注销生效)

  7. $ sudo pkg_add -v axel             (安装axel)
  8. axel-2.4 : libiconv-1.14: ok
  9. axel-2.4 : gettext-0.18.1p1: ok
  10. axel-2.4 : ok
  11. $ axel -V
  12. Axel version 2.4  (OpenBSD)
  13. Copyright 2001-2002 Wilmer van der Gaast.
  14.  
  15. $ sudo pkg_add -v wget             (安装wget)
  16. wget-1.13.4 : libidn-1.22: ok
  17. wget-1.13.4 : ok
  18. $ wget -V
  19. GNU Wget 1.13.4 built on openbsd5.1.
  20. ...
  21. ...
PORTS & SRC:
  1. # axel -a 'ftp://ftp.openbsd.org/pub/OpenBSD/5.1/src.tar.gz'      (下载src)
  2. # axel -a 'ftp://ftp.openbsd.org/pub/OpenBSD/5.1/sys.tar.gz'      (下载sys)
  3. # axel -a 'ftp://ftp.openbsd.org/pub/OpenBSD/5.1/ports.tar.gz'    (下载ports)
  4. # axel -a 'ftp://ftp.openbsd.org/pub/OpenBSD/5.1/xenocara.tar.gz' (里面包含显卡驱动)

  5. # cd /usr/src
  6. # tar -zxvpf ~/src.tar.gz      (Installing the Source Code)
  7. # tar -zxvpf ~/sys.tar.gz      (Installing the Sys Code)

  8. # cd /usr
  9. # tar -zxvpf ~/ports.tar.gz    (Installing the Ports Collection)
  10. # tar -zxvpf ~/xenocara.tar.gz (Installing the Drivers Collection)

Customizing Download Sources:
  1. # cd /usr/ports/infrastructure/templates
  2. # cp network.conf.template ../db/network.conf
  3. # vi ../db/network.conf        (其实默认的就不错,哥们你看着办吧^_^)
  1. # vim /etc/mk.conf
  2. WRKOBJDIR=/usr/obj/ports
  3. DISTDIR=/usr/distfiles
  4. PACKAGE_REPOSITORY=/usr/packages
  5. FETCH_CMD=/usr/local/bin/axel -a -S4
  6. MASTER_SITE_OVERRIDE=\
  7.         ftp://ftp.openbsd.org/pub/OpenBSD/distfiles/${DIST_SUBDIR}/\
  8.         ftp://ftp.jaist.ac.jp/pub/OpenBSD/distfiles/${DIST_SUBDIR}/
  9. :wq
  10. #
  • The working directory of ports. This is controlled by the WRKOBJDIR variable, which specifies the directory which will contain the working directories. 
  • The directory containing distribution files. This is controlled by the DISTDIR variable. 
  • The directory containing newly built binary packages. This is controlled by the PACKAGE_REPOSITORY variable.

7> PKG_ADD & PORTS 安装 VIM

ports安装 VIM:

  1. # cd /usr/ports
  2. # make print-index
  3. # grep -i ^vim INDEX            (Finding Software by Name)
  4. # make search key=vim           (Finding by Keyword)
  5. ...
  6. ...
  7. Port: vim-7.3.154p2-no_x11
  8. Path: editors/vim,-main,no_x11
  9. Info: vi clone, many additional features
  10. Maint: Chris Kuethe  
  11. Index: editors
  12. L-deps: STEM->=0.10.38:devel/gettext converters/libiconv
  13. B-deps: STEM->=0.10.38:devel/gettext STEM->=1.21:textproc/groff archivers/bzip2
  14. R-deps: STEM->=0.10.38:devel/gettext
  15. Archs:  any
  16. ...
  17. ...
  18. (L-deps->:libraries used by this port  B-deps->:lists software that is required to build this port
  19.  R-deps->:non-library software that must be present to actually run this port)
  20. # cd editors/vim && make install clean


package安装 VIM:

  1. # man pkg_add
  2. pkg_add can be used to install new packages, to replace existing packages with other flavors
  3. (option -r) or to update packages to newer versions (option -u) [PS:这个跟FreeBSD可不同哦!]
  4. # vi ~/.profile           (注意这里是root,也需要配置!)
  5. export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/5.1/packages/`machine -a`/
  6. export FETCH_PACKAGES=yes
  7. :wq
  8. # exit            (注销生效)

  9. # pkg_add -v vim       (安装VIM)
  10. Ambiguous:  vim could be vim-7.3.154p2-no_x11 vim-7.3.154p2-gtk2
  11. (很人性化吧,还有提示的哟!你会发现ports里面抓,和现在都有这么多不同的vim?
  12.  OpenBSD称之为Flavors! 其实就是不同的Option罢了^_^, 闲言少叙,书归正转!)
  13. # pkg_add -v vim-7.3.154p2-no_x11
  14. vim-7.3.154p2-no_x11:  ok
  15. # vim --version
  16. VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Feb 13 2012 07:40:51)
  17. Included patches: 1-8, 11-20, 22-26, 28-34, 38-50, 52-62, 65-78, 80-84, 86, 88-94
  18. ...
  19. ...
  20. # vim ~/.vimrc
  21. set nomodeline (这个一定要写,目前有这个安全漏洞)
  22. set nocp
  23. set hls is
  24. set ic
  25. set autoindent
  26. set backspace=2
  27. syntax on
  28. "set bg=dark (更改背景色调/默认为light, " 为注释!)
  29. :wq (详情:vimtutor)

  30. # cp .vimrc ~ko/.vimrc    (给普通用户也送一份)
  31. # chown -R ko:ko ~ko/     (更改为合适的权限)


Customizing Alias:

  1. $ vim ~/.profile
  2. #
  3. # sh/ksh initialization

  4. set autolist
  5. alias cl='clear'
  6. alias df='df -h'
  7. alias la='ls -la'
  8. alias lh='ls -lh'
  9. alias lf='ls -FA'
  10. alias ll='ls -l'
  11. :wq
  12. $ exit            (注销生效)


8> 安装 Xfce4
关于Xorg配置 : http://blog.chinaunix.net/uid-25256412-id-2939430.html

  1. # pkg_add -v xfce4-session xfce-utils xfdesktop xfconf xfce4-mixer xfce4-settings xfce4-panel xfce4-terminal xfce4-places xfwm4 xfwm4-themes gamin

  2. # cat >>/etc/rc.conf.local<
  3. rc_scripts="dbus_daemon"
  4. EOF
  5. $ echo >~/.xinitrc startxfce4
  6. $ startx

  7. echo >>/etc/rc.conf.local xdm_flags=""
  8. # exit
  9. $ echo >~/.xsession startxfce4                (如果使用xdm)
  10. # reboot

  11. OR: use gdm as login manager instead of xdm
  12. # pkg_add -v gdm
  13. # vim /etc/rc.conf.local 
  14. xdm_flags=NO
  15. rc_scripts="dbus_daemon gdm"
  16. aucat_flags=""               (enable the aucat sound daemon at boot time)
  17. :wq
  18. # aucat -l


9> 常用 APP

Chromium/Thunderbird/FileZilla/Empathy(IM Client)/Xchat(IRC Only)/Mplayer/VLC/Audacious

  1. # pkg_add -v chromium             (chrome的表哥)

  2. There are some things to do for Chromium to be a bit functional :
  3. # echo >>/etc/sysctl.conf kern.shminfo.shmall=32768
  4. # vim /etc/login.conf
  5. in the default section:
  6. add
  7. penfiles-max=400:\                (重启生效)

  8. # vim /usr/local/share/application/chromium.desktop
  9. [Desktop Entry]
  10. Version=1.0
  11. Type=Application
  12. Categories=Application;Network
  13. Name=Chromium
  14. Comment=Chromium Web browser
  15. Icon=/usr/local/chrome/product_logo_48.png
  16. Exec=chrome %u
  17. Path=
  18. Terminal=false
  19. StartupNotify=false
  20. :wq
  21. ---------------------------------
  22. 鸟儿:
  23. 一些我的小碎碎念;
  24. 浏览器这块,如果装firefox的话,要先把locale设置好,不然firefox启动异常,有进程,无界面。
  25. chromium 的话,root用户会报错,必须用下面的命令启动:
  26. chromium --user-data-dir=/yourpath

  27. 如果你有4核或者主频高的cpu可以在/etc/rc.conf.local(没有建立一个)加入:
  28. apmd="-C" ## Or "-A"
  29. 深度节能或者让OpenBSD自己管理。man apmd 讲的已经很好懂了。
  30. ---------------------------------

  31. # pkg_add -v mozilla-thunderbird   (Email Client)
  32. # pkg_add -v filezilla             (FTP Client)
  33. # pkg_add -v empathy               (IM Client)
  34. # pkg_add -v xchat                 (IRC Only)
  35. # pkg_add -v mplayer               (建议安装)
  36. # pkg_add -v vlc                   (VLC media player)
  37. # pkg_add -v audacious-plugins     (Audio Player)
  38. PS: To have sound output in Audacious, be sure to select “Sndio output plugin” in preferences/audio.

Mousepad/epdfview/GIMP/Ristretto/Thunar-archive/Galculator/LibreOffice

  1. # pkg_add -v mousepad              (Text Editor)
  2. # pkg_add -v epdfview              (PDF Viewer)
  3. # pkg_add -v gimp                  (Image Processing)
  4. # pkg_add -v ristretto             (Image Displayer)
  5. # pkg_add -v thunar-archive        (Archive Manager)
  6. # pkg_add -v galculator            (Calculator)
  7. # pkg_add -v libreoffice-i18n-cn libreoffice-java     (Openoffice的表弟)
  8. Add support for .rar archives rar/unrar
  9. # cd /usr/ports/archives/unrar && make install clean  (没有binary)

InputMethod : Scim / fcitx 

  1. # pkg_add -v scim-pinyin

  2. # wget ''
  3. # wget ''      (带词库方便没有网络连接的机器!)

  4. 由于OpenBSD默认安装比较干净,所以来安装一下xz ^_^
  5. # pkg_add -v xz
  6. xz-5.0.3p1 : ok

  7. # xz -dk fcitx-4.2.3.tar.xz
  8. # tar -xvf fcitx-4.2.3.tar
  9. OR:
  10. # xzcat fcitx-4.2.3.tar.xz |tar -xvf -
  11. # more fcitx-4.2.3/INSTALL
  12. Basic Install
  13. ...
  14. ...
  15. # vim ~/.profile
  16. export XIM_PROGRAM=fcitx
  17. export XIM=fcitx
  18. export XMODIFIERS="@im=fcitx"
  19. export QT_IM_MODULE=XIM
  20. export GTK_IM_MODULE=XIM

  21. # vim ~/.xinitrc
  22. exec fcitx &            (注意放到第一位优先执行)
  23. # reboot


NOTE : the OpenBSD developers strongly suggest to use binary packages whenever possible.

10> TIPS

  1. # man afterboot
  2. # man intro
  3. # man 8 intro
  4. # man hier
  5. Manually update the files database so we can use the locate command to look for a file
  6. # /usr/libexec/locate.updatedb
  7. # locate
  8. List installed packages
  9. # pkg_info |more
  10. Search for packages in repository (provided by PKG_PATH)
  11. # pkg_info -Q
  12. Update all packages on the system
  13. # pkg_add -v -u

  14. # vim /etc/fstab
  15. :wq

  16. (FFS records the last time a file was accessed, meaning the last time it was executed or
  17.  read by any means. These updates consume a small but measurable amount of time and disk performance.
  18. "noatime" is very useful the hard disk and the screen are the two most power-hungry devices on a laptop
  19. and if you can reduce the amount of time your laptop's hard drive spins you will extend battery life.)

  20. (Soft update, or "softdep," mounts organize and arrange disk writes so that the file system metadata 
  21. on the disk remains consistent, and it comes close to giving the performance of an "async" 
  22. mount with the reliability of a "sync" mount.)

11> Systrace

  1. One of the more exciting features in OpenBSD is systrace(1), a system call access manager. 
  2. With systrace, a system administrator can say which system calls can be made by which programs, 
  3. and how those calls can be made. 
  4. Proper use of systrace can greatly reduce the risks inherent in running poorly written 
  5. or exploitable programs.
 
12> Insecure Console (Single-user mode)

  1. When you boot FreeBSD in single-user mode, you get a root command
  2. prompt. This is fine for your laptop and works nicely for servers in your
  3. corporate datacenter, but what about machines in untrusted facilities?
  4. # man /etc/ttys
  5. /secure
  6. secure   If on is also specified, allows users with a UID of 0 to log in
  7.          on this line.   If set for the console entry, then init(8) will
  8.          start a single-user shell without asking for the superuser password.
  9. To make the console require a root login when booted into single-usermode,
  10. change the secure to insecure.
  11. # vim /etc/ttys
  12. #
  13. #      $OpenBSD:  ttys,v 1.2 2008/01/09 17:39:42 miod Exp $
  14. #
  15. # name  getty                            type    status          comments
  16. #
  17. console "/usr/libexec/getty std.9600"    vt220   off  insecure
  18. :wq
  19. # reboot
  20. >boot -s


13> PF Basic Setup
详见 CU Blog: http://blog.chinaunix.net/uid-25256412-id-3223143.html


14> Basic FreeBSD Setup
详见 CU Blog: http://blog.chinaunix.net/uid-25256412-id-2939430.html

15> OpenBSD 下显示CPU 硬盘 主板温度 CPU风扇转速脚本
FROM:  (wosl2001)

  1. #!/bin/sh
  2. typeset -i10 HDDCUR
  3. typeset -i10 HDDMAX
  4. typeset -i10 HDDMIN
  5. typeset -i10 CPU
  6. typeset -i10 MainBOARD
  7. typeset -i10 FAN
  8. RAWTEMP=`atactl /dev/sd0c readattr | grep Temperature | cut -f 5`
  9. HDDCUR=`echo $RAWTEMP | sed -e 's/0x.\{10\}/0x/'`
  10. HDDMAX=`echo $RAWTEMP | sed -e 's/0x.\{2\}/0x/' | sed -e 's/.\{8\}$//'`
  11. HDDMIN=`echo $RAWTEMP | sed -e 's/0x.\{6\}/0x/' | sed -e 's/.\{4\}$//'`
  12. CPU=`sysctl hw.sensors.it0.temp0 | cut -d '=' -f2 | cut -c1-2 `
  13. MainBOARD=`sysctl hw.sensors.it0.temp1 | cut -d '=' -f2 | cut -c1-2 `
  14. FAN=`sysctl hw.sensors.it0.fan0 | cut -d '=' -f2 | cut -c1-4 `
  15. echo "Current HDD Temp $HDDCUR degC (Min/Max $HDDMIN/$HDDMAX)"
  16. echo "Current CPU Temp $CPU degC"
  17. echo "Current MainBOARD Temp $MainBOARD degC"
  18. echo "Current CPU FAN $FAN rpm"



16> pcidump /dmesg

  1. # 关于音频设备: 




17> Reserved for future use....

18> Reserved for future use....


上一篇:SMS Abbreviations / Abbreviations in the Net
下一篇:SecureCRT设置vim显示颜色