ulovko 发表于 2012-06-04 14:53

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

本帖最后由 ulovko 于 2013-04-06 11:09 编辑

FROM: http://blog.chinaunix.net/uid-25256412-id-3233391.html

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 4.6:
简体中文FAQ 4.8:

=== 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

安装教程:http://www.openbsd.org/faq/faq4.html#InstStart

启动计算机开始安装:








重启计算机:

使用刚刚创建的普通用户登陆:


登陆后查看邮件:
切换到root,向dmesg@openbsd.org发送机器信息为社区的发展尽一份心力(PS: 不要老发虚拟机信息)!

# visudo(如图中所示,允许wheel组使用sudo ^_^)

测试 sudo是否配置成功:


3> 简单认识OpenBSD5.1
# cat /etc/myname      (查看主机名)
obsd5.kotzu.org
# cat /etc/hostname.em0(查看网卡配置)
dhcp
# cat /etc/hostname.em0(静态地址会是这样)
192.168.1.11 255.255.255.0 NONE NONE         (依次是:inet ipaddress netmask broadcastaddress options)
# cat /etc/mygate      (配置网关地址)
192.168.1.1
# cat /etc/resolv.conf   (配置DNS)
search kotzu.org
nameserver 202.106.46.151
nameserver 202.106.0.20
lookup file bind

4> 关于boot菜单 /etc/boot.conf
boot> set timeout 60      (boot delay, 5 seconds by default)
boot> boot -s             (To boot into single-user mode)
#/bin/sh /etc/netstart    (Start the network while in single-user mode)

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

EXAMPLES
   Boot the default kernel:

         boot> boot

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

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

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

         boot> set tty com0

   Invoke the serial console at every boot:

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

5> 使用本地化语言(简体中文)
$ ls /usr/share/locale/zh_
zh_CN.GB18030/         zh_CN.eucCN/      zh_TW.Big5/      zh_TW.eucTW/
zh_CN.UTF-8/         zh_TW.BIG5/         zh_TW.UTF-8/

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

# cd ..
# make && make install && make cleanAbout eucCN: http://zh.wikipedia.org/wiki/EUC

6> 配置PACKAGE & PORTS & SRC

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

$ sudo pkg_add -v axel             (安装axel)
axel-2.4 : libiconv-1.14: ok
axel-2.4 : gettext-0.18.1p1: ok
axel-2.4 : ok
$ axel -V
Axel version 2.4(OpenBSD)
Copyright 2001-2002 Wilmer van der Gaast.

$ sudo pkg_add -v wget             (安装wget)
wget-1.13.4 : libidn-1.22: ok
wget-1.13.4 : ok
$ wget -V
GNU Wget 1.13.4 built on openbsd5.1.
...
...PORTS & SRC:
# axel -a 'ftp://ftp.openbsd.org/pub/OpenBSD/5.1/src.tar.gz'      (下载src)
# axel -a 'ftp://ftp.openbsd.org/pub/OpenBSD/5.1/sys.tar.gz'      (下载sys)
# axel -a 'ftp://ftp.openbsd.org/pub/OpenBSD/5.1/ports.tar.gz'    (下载ports)
# axel -a 'ftp://ftp.openbsd.org/pub/OpenBSD/5.1/xenocara.tar.gz' (里面包含显卡驱动)

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

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

Customizing Download Sources:
# cd /usr/ports/infrastructure/templates
# cp network.conf.template ../db/network.conf
# vi ../db/network.conf      (其实默认的就不错,哥们你看着办吧^_^)


# vim /etc/mk.conf
WRKOBJDIR=/usr/obj/ports
DISTDIR=/usr/distfiles
PACKAGE_REPOSITORY=/usr/packages
FETCH_CMD=/usr/local/bin/axel -a -S4
MASTER_SITE_OVERRIDE=\
      ftp://ftp.openbsd.org/pub/OpenBSD/distfiles/${DIST_SUBDIR}/\
      ftp://ftp.jaist.ac.jp/pub/OpenBSD/distfiles/${DIST_SUBDIR}/
:wq

[*]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:
# cd /usr/ports
# make print-index
# grep -i ^vim INDEX            (Finding Software by Name)
# make search key=vim         (Finding by Keyword)
...
...
Port:        vim-7.3.154p2-no_x11
Path: editors/vim,-main,no_x11
Info:        vi clone, many additional features
Maint: Chris Kuethe<ckuethe@openbsd.org>
Index: editors
L-deps: STEM->=0.10.38:devel/gettext converters/libiconv
B-deps: STEM->=0.10.38:devel/gettext STEM->=1.21:textproc/groff archivers/bzip2
R-deps: STEM->=0.10.38:devel/gettext
Archs:any
...
...
(L-deps->:libraries used by this portB-deps->:lists software that is required to build this port
R-deps->:non-library software that must be present to actually run this port)

# cd editors/vim && make install clean
package安装 VIM:
# man pkg_add
pkg_add can be used to install new packages, to replace existing packages with other flavors
(option -r) or to update packages to newer versions (option -u)

# vi ~/.profile         (注意这里是root,也需要配置!)
export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/5.1/packages/`machine -a`/
export FETCH_PACKAGES=yes
:wq
# exit            (注销生效)

# pkg_add -v vim       (安装VIM)
Ambiguous:vim could be vim-7.3.154p2-no_x11 vim-7.3.154p2-gtk2
(很人性化吧,还有提示的哟!你会发现ports里面抓,和现在都有这么多不同的vim?
OpenBSD称之为Flavors! 其实就是不同的Option罢了^_^, 闲言少叙,书归正转!)

# pkg_add -v vim-7.3.154p2-no_x11
vim-7.3.154p2-no_x11:ok
# vim --version
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Feb 13 2012 07:40:51)
Included patches: 1-8, 11-20, 22-26, 28-34, 38-50, 52-62, 65-78, 80-84, 86, 88-94
...
...
# vim ~/.vimrc
set nomodeline                (这个一定要写,目前有这个安装漏洞)
set nocp
set hls is
set ic
set cindent
set autoindent
set backspace=2
set nobackup
set noswapfile
set shiftwidth=2
set tabstop=2
set softtabstop=2
set expandtab
set ruler
set mouse=v
syntax on
"set bg=dark                (更改背景色调/默认为light, " 为注释!)
:wq                        (详情:vimtutor)

# cp .vimrc ~ko/.vimrc    (给普通用户也送一份)
# chown -R ko:ko ~ko/   (更改为合适的权限)Customizing Alias:
$ vim ~/.profile
#
# sh/ksh initialization

set autolist
alias cl='clear'
alias df='df -h'
alias la='ls -la'
alias lh='ls -lh'
alias lf='ls -FA'
alias ll='ls -l'
:wq
$ exit            (注销生效)
X> Reserved for future use....


Basic FreeBSD Setup as Desktop: http://bbs.chinaunix.net/thread-3751834-1-1.html
Basic NetBSD Setup as Desktop: http://bbs.chinaunix.net/thread-3751787-1-1.html
Basic OpenBSD Setup as Desktop: http://bbs.chinaunix.net/thread-3751016-1-1.html
Basic Debian Setup as Desktop: http://bbs.chinaunix.net/thread-3751791-1-1.html
Basic Ubuntu Setup as Desktop: http://bbs.chinaunix.net/thread-3746337-1-1.html
Basic Fedora Setup as Desktop: http://bbs.chinaunix.net/thread-3761672-1-1.html
Basic PC-BSD Setup as Desktop: http://bbs.chinaunix.net/thread-3751857-1-1.html

ulovko 发表于 2012-06-04 14:53

本帖最后由 ulovko 于 2012-06-09 09:31 编辑

8> 安装 Xfce4
关于Xorg配置 : http://blog.chinaunix.net/uid-25256412-id-2939430.html
# pkg_add -v xfce4-session xfce-utils xfdesktop xfconf xfce4-mixer xfce4-settings xfce4-panel xfce4-terminal xfce4-places xfwm4 xfwm4-themes gamin

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

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

OR: use gdm as login manager instead of xdm
# pkg_add -v gdm
# vim /etc/rc.conf.local
xdm_flags=NO
rc_scripts="dbus_daemon gdm"
aucat_flags=""               (enable the aucat sound daemon at boot time)
:wq
# aucat -l9> 常用 APP

Chromium/Thunderbird/FileZilla/Empathy(IM Client)/Xchat(IRC Only)/Mplayer/VLC/Audacious
# pkg_add -v chromium             (chrome的表哥)

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

# vim /usr/local/share/application/chromium.desktop

Version=1.0
Type=Application
Categories=Application;Network
Name=Chromium
Comment=Chromium Web browser
Icon=/usr/local/chrome/product_logo_48.png
Exec=chrome %u
Path=
Terminal=false
StartupNotify=false
:wq
---------------------------------
鸟儿:
一些我的小碎碎念;
浏览器这块,如果装firefox的话,要先把locale设置好,不然firefox启动异常,有进程,无界面。
chromium 的话,root用户会报错,必须用下面的命令启动:
chromium --user-data-dir=/yourpath
复制代码
如果你有4核或者主频高的cpu可以在/etc/rc.conf.local(没有建立一个)加入:
apmd="-C" ## Or "-A"
复制代码
深度节能或者让OpenBSD自己管理。man apmd 讲的已经很好懂了。

---------------------------------
# pkg_add -v mozilla-thunderbird   (Email Client)
# pkg_add -v filezilla             (FTP Client)
# pkg_add -v empathy               (IM Client)
# pkg_add -v xchat               (IRC Only)
# pkg_add -v mplayer               (建议安装)
# pkg_add -v vlc                   (VLC media player)
# pkg_add -v audacious-plugins   (Audio Player)
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
# pkg_add -v mousepad            (Text Editor)
# pkg_add -v epdfview            (PDF Viewer)
# pkg_add -v gimp                  (Image Processing)
# pkg_add -v ristretto             (Image Displayer)
# pkg_add -v thunar-archive      (Archive Manager)
# pkg_add -v galculator            (Calculator)
# pkg_add -v libreoffice-i18n-cn libreoffice-java   (Openoffice的表弟)
Add support for .rar archives rar/unrar
# cd /usr/ports/archives/unrar && make install clean(没有binary)
InputMethod : Scim / fcitx
# pkg_add -v scim-pinyin

# wget 'http://fcitx.googlecode.com/files/fcitx-4.2.3.tar.xz'
# wget 'http://fcitx.googlecode.com/files/fcitx-4.2.3_dict.tar.xz'      (带词库方便没有网络连接的机器!)

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

# xz -dk fcitx-4.2.3.tar.xz
# tar -xvf fcitx-4.2.3.tar
OR:
# xzcat fcitx-4.2.3.tar.xz |tar -xvf -
# more fcitx-4.2.3/INSTALL
Basic Install
...
...
# vim ~/.profile
export XIM_PROGRAM=fcitx
export XIM=fcitx
export XMODIFIERS="@im=fcitx"
export QT_IM_MODULE=XIM
export GTK_IM_MODULE=XIM

# vim ~/.xinitrc
exec fcitx &            (注意放到第一位优先执行)
# reboot
NOTE : the OpenBSD developers strongly suggest to use binary packages whenever possible.

10> TIPS
# man afterboot
# man intro
# man 8 intro
# man hier

Manually update the files database so we can use the locate command to look for a file
# /usr/libexec/locate.updatedb
# locate <name>

List installed packages
# pkg_info |more

Search for packages in repository (provided by PKG_PATH)
# pkg_info -Q <search string>

Update all packages on the system
# pkg_add -v -u

# vim /etc/fstab

:wq

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

(Soft update, or "softdep," mounts organize and arrange disk writes so that the file system metadata
on the disk remains consistent, and it comes close to giving the performance of an "async"
mount with the reliability of a "sync" mount.)
11> Systrace
One of the more exciting features in OpenBSD is systrace(1), a system call access manager.
With systrace, a system administrator can say which system calls can be made by which programs,
and how those calls can be made.
Proper use of systrace can greatly reduce the risks inherent in running poorly written
or exploitable programs.
12> Insecure Console (Single-user mode)


When you boot FreeBSD in single-user mode, you get a root command
prompt. This is fine for your laptop and works nicely for servers in your
corporate datacenter, but what about machines in untrusted facilities?
# man /etc/ttys
/secure
secure   If on is also specified, allows users with a UID of 0 to log in
         on this line.   If set for the console entry, then init(8) will
         start a single-user shell without asking for the superuser password.
To make the console require a root login when booted into single-usermode,
change the secure to insecure.
# vim /etc/ttys
#
#      $OpenBSD:ttys,v 1.2 2008/01/09 17:39:42 miod Exp $
#
# namegetty                            type    status          comments
#
console "/usr/libexec/getty std.9600"    vt220   offinsecure
:wq
# reboot
>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: http://bbs.chinaunix.net/thread-1305553-1-1.html (wosl2001)
#!/bin/sh
typeset -i10 HDDCUR
typeset -i10 HDDMAX
typeset -i10 HDDMIN
typeset -i10 CPU
typeset -i10 MainBOARD
typeset -i10 FAN
RAWTEMP=`atactl /dev/sd0c readattr | grep Temperature | cut -f 5`
HDDCUR=`echo $RAWTEMP | sed -e 's/0x.\{10\}/0x/'`
HDDMAX=`echo $RAWTEMP | sed -e 's/0x.\{2\}/0x/' | sed -e 's/.\{8\}$//'`
HDDMIN=`echo $RAWTEMP | sed -e 's/0x.\{6\}/0x/' | sed -e 's/.\{4\}$//'`
CPU=`sysctl hw.sensors.it0.temp0 | cut -d '=' -f2 | cut -c1-2 `
MainBOARD=`sysctl hw.sensors.it0.temp1 | cut -d '=' -f2 | cut -c1-2 `
FAN=`sysctl hw.sensors.it0.fan0 | cut -d '=' -f2 | cut -c1-4 `
echo "Current HDD Temp $HDDCUR degC (Min/Max $HDDMIN/$HDDMAX)"
echo "Current CPU Temp $CPU degC"
echo "Current MainBOARD Temp $MainBOARD degC"
echo "Current CPU FAN $FAN rpm"

16> Reserved for future use....

ulovko 发表于 2012-06-04 14:54

本帖最后由 ulovko 于 2012-06-04 15:14 编辑

编辑的时候很整齐,结果显示的时候就变了:emn31:

wosl2001 发表于 2012-06-04 15:14

呵呵 好好写吧 不行写在wiki上

ulovko 发表于 2012-06-04 15:15

回复 4# wosl2001


    也行!:emn31:

obsd178 发表于 2012-06-04 16:13

真的是好详细 {:2_178:}楼主辛苦了

zeissoctopus 发表于 2012-06-04 20:29

謝謝分享~~

jvvt 发表于 2012-06-04 23:51

这些操作楼主都一一实践过么?
fcitx不修改源代码,在OpenBSD上能直接编译通过?
将LANG设置为zh_CN.UTF-8后,perl不会给出错误提示?:em17:

鸟儿 发表于 2012-06-05 07:29

一些我的小碎碎念;
浏览器这块,如果装firefox的话,要先把locale设置好,不然firefox启动异常,有进程,无界面。
chromium 的话,root用户会报错,必须用下面的命令启动:chromium --user-data-dir=/yourpath如果你有4核或者主频高的cpu可以在/etc/rc.conf.local(没有建立一个)加入:apmd="-C" ## Or "-A"深度节能或者让OpenBSD自己管理。man apmd 讲的已经很好懂了。

zenws 发表于 2012-06-05 09:11

很不错,谢谢
页: [1] 2 3 4
查看完整版本: Basic OpenBSD Setup as Desktop (OpenBSD值得研究 ^_^)