存档

文章标签 ‘freebsd’

FreeBSD 9.0-STABLE + KMS补丁[分享]

2011年12月4日 16hot 2 条评论

由于kib提供的KMS补丁是基于HEAD版本的,有人提取了9.0-STABLE的版本补丁出来。

下面是原始下载地址:

https://docs.google.com/open?id=0BxbPi2OX4_B-NDcwZGI1OTAtOTQxOC00YmMxLTg5ZjEtNmIxYTY0M2I0OWI5

访问不了docs.google.com 兄弟,可以从下面地址下载:

http://www.16hot.com/tmp/drm-all.12.3-stable9.patch

打补丁:
代码:

# cd /usr/src
# patch -p3 < drm-all.12.3-stable9.patch

之后是编译和安装内核……

注:我已经使用12.3版本一天左右时间,目前没有发现异常。之前是一直用10.3。

分类: BSD/linux 标签: ,

解决FreeBSD下编译LuaJIT的问题

2011年10月29日 16hot 没有评论

在FreeBSD下编译LuaJIT时,报如下错误:

CC lj_err.o
lj_err.c:189:20: error: unwind.h: No such file or directory
lj_err.c:199: error: expected declaration specifiers or '...' before '_Unwind_Action'
lj_err.c:200: error: expected declaration specifiers or '...' before '_Unwind_Exception_Class'
lj_err.c:201: warning: 'struct _Unwind_Context' declared inside parameter list
lj_err.c:201: warning: its scope is only this definition or declaration, which is probably not what you want
lj_err.c:201: warning: 'struct _Unwind_Exception' declared inside parameter list
lj_err.c: In function 'lj_err_unwind_dwarf':
lj_err.c:206: error: '_URC_FATAL_PHASE1_ERROR' undeclared (first use in this function)
lj_err.c:206: error: (Each undeclared identifier is reported only once
lj_err.c:206: error: for each function it appears in.)
lj_err.c:207: error: 'uexclass' undeclared (first use in this function)
lj_err.c:208: warning: implicit declaration of function '_Unwind_GetCFA'
lj_err.c:208: warning: cast to pointer from integer of different size
lj_err.c:210: error: 'actions' undeclared (first use in this function)
lj_err.c:210: error: '_UA_SEARCH_PHASE' undeclared (first use in this function)
lj_err.c:213: error: '_URC_CONTINUE_UNWIND' undeclared (first use in this function)
lj_err.c:218: error: '_URC_HANDLER_FOUND' undeclared (first use in this function)
lj_err.c:220: error: '_UA_CLEANUP_PHASE' undeclared (first use in this function)
lj_err.c:225: error: '_UA_HANDLER_FRAME' undeclared (first use in this function)
lj_err.c:226: warning: implicit declaration of function '_Unwind_DeleteException'
lj_err.c:231: error: '_UA_FORCE_UNWIND' undeclared (first use in this function)
lj_err.c:234: warning: implicit declaration of function '_Unwind_SetGR'
lj_err.c:235: warning: implicit declaration of function '_Unwind_SetIP'
lj_err.c:235: error: '_Unwind_Ptr' undeclared (first use in this function)
lj_err.c:238: error: '_URC_INSTALL_CONTEXT' undeclared (first use in this function)
lj_err.c:246: error: expected ')' before 'lj_vm_unwind_rethrow'
lj_err.c: In function 'err_raise_ext':
lj_err.c:271: error: invalid use of undefined type 'struct _Unwind_Exception'
lj_err.c:271: error: '_Unwind_Exception_Class' undeclared (first use in this function)
lj_err.c:272: error: invalid use of undefined type 'struct _Unwind_Exception'
lj_err.c:273: warning: implicit declaration of function '_Unwind_RaiseException'
gmake: *** [lj_err.o] 错误 1

只需要拷贝一个头文件,并且改名即可:

/usr/src/contrib/gcc/unwind-generic.h /usr/include/unwind.h

分类: BSD/linux, LUA 标签: , ,

FreeBSD下根据进程名称获取PID

2011年10月27日 16hot 没有评论

想通过进程名称来监控进程是否健在,在网上找了一个小例子,改成如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
 * 
 * gcc getproc.c -I/usr/include -I/usr/local/include -L/usr/lib/ -L/usr/local/lib/ -lkvm -o getproc
 */
 
#include <stdio.h>   
#include <string.h>   
#include <err.h>   
#include <kvm.h>   
#include <sys/param.h>   
#include <sys/sysctl.h>   
#include <sys/user.h>   
#include <sys/param.h>   
#include <fcntl.h>   
#include <stdlib.h>   
#include <sysexits.h>    
static int  
get_pid_of_process(char *process_name)   
{   
 static kvm_t *kd = NULL;   
 struct kinfo_proc *p;   
 int i, n_processes, processes_found;   
 processes_found = 0;   
 
 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY, "kvm_open")) == NULL)    
    (void)errx(1, "%s", kvm_geterr(kd));   
 else {   
  p = kvm_getprocs(kd, KERN_PROC_PROC, 0, &n_processes);   
  for (i = 0; i < n_processes; i++)   
   if (strncmp(process_name, p[i].ki_comm, COMMLEN+1) == 0) {   
    (void)printf("progame: %s, pid: %d \n", process_name, (int)p[i].ki_pid);   
    processes_found++;   
   }   
//~ if (p[i].ki_pid == pid){
  //~ (void)printf("%s ", p[i].ki_comm);
  //~ processes_found++;
 //~ }
  kvm_close(kd);   
 }
 return processes_found;   
}   
 
 
int main( int argc, char **argv ) {
    int pf = 0;
 
    if ( argc < 2 ) {
        printf( "Please input a process name!\n" );
        exit(0);
    }
 
    pf = get_pid_of_process( (argv[1]) );
 
    printf( "have found %d proess\n", pf );
    return 0;
}
分类: BSD/linux, C/C++ 标签: ,

升级内存!!

2011年8月31日 16hot 没有评论

笔记本一直在用4G的内存,用FreeBSD 8的时候,没有用ZFS,4G内存就足够了。

自从换成FreeBSD9,用ZFS后,内存就很紧张。常常要用上交换分区,系统就变得特别慢。太痛苦了!!

最近内存价格降得很厉害,犹豫再三后,决定再买条4G的内存换上去。想在是6G内存了。呵呵

观测看看,还会不会内存不够用,再不够,再换成8G内存。

分类: 16hot 杂记 标签: ,

关注FreeBSD下的新版CARP

2011年8月18日 16hot 没有评论

http://lists.freebsd.org/pipermail/freebsd-net/2011-August/029539.html

http://people.freebsd.org/~glebius/newcarp/README

  Hello networkers,

  I'd like to present for review and early testing (for brave ones)
a new CARP implementation. The reason for this rewrite was that CARP
protocol actually doesn't bring a new interface, but is a property of
interface address. Rewriting it in this way helps to remove several
hacks from incoming packet processing[1], simplifies some code, makes
CARP addresses more sane from viewpoint of routing daemons such as
quagga/zebra. It also brings support for a single redundant address
on the subnet, the thing that is called "carpdev feature" in OpenBSD,
long awaited in FreeBSD.

More info and the patch itself is available here:

http://people.freebsd.org/~glebius/newcarp/README

I'm glad to here comments.
分类: BSD/linux 标签: ,

关注KMS/GEM进展

2011年7月24日 16hot 没有评论

已经有人在做需要KMS支持的X相关的ports了。

http://trillian.chruetertee.ch/ports/browser/branches/xorg-dev

https://trillian.chruetertee.ch/svn/ports/branches/xorg-dev/

分类: BSD/linux 标签: ,

FreeBSD-9 Current ZFS安装

2011年7月19日 16hot 没有评论

最近特别忙,先将安装部分帖上,迟些整理完KMS/GEM部分,再帖到WIKI上。

下载
从FreeBSD官方的目录没有找到AMD64版本的,从下面地址找:

http://pub.allbsd.org/FreeBSD-snapshots/

http://pub.allbsd.org/FreeBSD-snapshots/amd64-amd64/9.0-HEAD-20110711-JPSNAP

安装

用光盘启动后,选择模式,提示login: 的时候,直接输入root回车就可以了。

创建分区

如果是旧硬盘,里面有数据,需要擦除的话,可以使用如下方法:
如果需要,此时用dd抹除硬盘内容,
例如 dd if=/dev/zero of=/dev/ada0 bs=1m count=1

代码:
gpart create -s gpt ada0 (重复此步直到所有硬盘皆包含GPT分区表)
gpart add -s 64K -t freebsd-boot ada0 (实际上只有启动盘需要,不过64K空间对现代硬盘来说基本上可以忽略不计)
gpart add -s 4G -t freebsd-swap -l swap0 ada0 (根据需要酌情配置)
gpart add -t freebsd-zfs -l zdisk ada0
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0

接下来是创建ZFS pool了。这时候有个关键点。如果硬盘支持4k扇区,那将zpool设置为4k扇区支持,磁盘性能将提升一倍。具体参考dj的文章:https://blog.delphij.net/2011/01/-neptune-zfs.html

代码:
硬盘支持4k扇区时的:
gnop create -S 4096 /dev/gpt/zdisk
zpool create -f zdisk /dev/gpt/zdisk.nop

代码:
如果硬盘不支持4K扇区,方法如下
zpool create -f zdisk /dev/gpt/zdisk

注意:创建zpool时会提示“cannot mount ‘/zdisk’: failed to create mountpoint”,直接忽略它。

代码:

zpool set bootfs=zdisk zdisk
zfs set checksum=fletcher4 zdisk
zfs set mountpoint=/mnt zdisk

zfs create zdisk/var
zfs create zdisk/usr
zfs create zdisk/home
zfs create zdisk/tmp

注意:创建分区时提示“cannot mount ‘/mnt/usr’: failed to create mountpoint
filesystem successfully create, but not mounted”
这些信息直接忽略。

更多的分区,可以根据自己的需要创建,设置可以使用ZFS的更多特性,如压缩等。

接下来是导出和导入ZFS分区:
代码:

zpool export zdisk
zpool import -o cachefile=/tmp/zpool.cache zdisk

安装系统

安装基本系统
代码:
sh
cd /usr/freebsd-dist
export DESTDIR=/mnt
for file in base.txz lib32.txz kernel.txz doc.txz src.txz;
do (cat $file | tar –unlink -xpJf – -C ${DESTDIR:-/}); done

拷贝zpool.cache文件
cp /tmp/zpool.cache /mnt/boot/zfs/zpool.cache
提示:这步一定要做,否则启动时找不到分区。

配置ZFS相关设置
代码:
cat < /mnt/etc/rc.conf
zfs_enable=”YES”
hostname=”gptzfsboot.16hot.com”
defaultrouter=”192.168.56.1″
ifconfig_em0=”inet 192.168.56.13 netmask 255.255.255.0″
EOF

提示: zfs_enable=”YES”这行是必须的,下面的配置主机名、网络部分,可以启动后配置。

代码:

cat < /mnt/boot/loader.conf
zfs_load=”YES”
vfs.root.mountfrom=”zfs:zdisk
vfs.root.mountfrom.options=”rw”
vfs.zfs.prefetch_disable=0
EOF

cat < /mnt/etc/fstab
# Device Mountpoint FStype Options Dump Pass#
/dev/gpt/swap0 none swap sw 0 0
EOF

代码:

zfs set readonly=on zdisk/var/empty
zfs unmount -a

zfs set mountpoint=legacy zdisk
zfs set mountpoint=/tmp zdisk/tmp
zfs set mountpoint=/usr zdisk/usr
zfs set mountpoint=/var zdisk/var

至此已经安装完基本系统了。直接reboot 重启就行。

如果重启过程有异常,不能正常启动,那得从头检查看看是那个环节出错了。我也因为某个环节出错,反复尝试,折腾了一整个下午才搞定。

应用KMS/GEM

重启后,为了使用KMS/GEM补丁,接下来就需要自己更新源码和重新编译系统和内核了。
在开始这部分之前,最好仔细看看 http://wiki.freebsd.org/Intel_GPU 。目前这个补丁还是内部开发过程,还不是正式测试阶段,功能还不完善,而且难免还有很多未知BUG。
代码:

cat < /root/stable-supfile
*default host=cvsup10.tw.freebsd.org
*default base=/usr
*default prefix=/usr
*default release=cvs tag=.
*default delete use-rel-suffix
*default compress
src-all
EOF

csup /root/stable-supfile

下载KMS补丁
到 http://people.freebsd.org/~kib/drm/ 找个最新的版本。
我当时最新的是 all.5.6.patch ,因此我下载的是 all.5.6.patch 。

代码:
cd /usr/src
mkdir drm
cd drm
fetch http://people.freebsd.org/~kib/drm/all.5.6.patch
fetch http://people.freebsd.org/~kib/drm/libdrm.1.patch

打补丁
cd /usr/src
patch -p1 < ./drm/all.5.6.patch

代码:
cat < /usr/src/mk.sh
#!/bin/sh
cd /usr/src
make -j2 buildworld && make -j2 buildkernel && make installworld && make installkernel
EOF

chmod +x /usr/src/mk.sh

time /usr/src/mk.sh

接下来就是等着编译完成,然后重启到新系统了。这里没有配置内核,因为使用KMS补丁不需要进行什么特定的内核配置。如果自己需要,可以根据自己的情况配置下。

分类: BSD/linux 标签: , ,

用上FreeBSD9-current + KMS/GEM 补丁了

2011年7月16日 16hot 4 条评论

由于FreeBSD8.x还没有支持KMS/GEM,而无法使用intel的最新显卡驱动程序,无法很好的驱动X201i的集成显卡。使用Vesa驱动虽然能使用Xorg ,但是性能很差,屏幕刷新稍微快些,就耗CPU 100%。而且另外还有个很严重的问题,就是不支持外接显示器,更别说用投影仪了。

后来在2月份,看到freebsd官方公告说支持KMS/GEM项目研发。而7月初,KMS/GEM的补丁出来了,虽然还不是正式的测试版本。

居于上面的两点,一个是性能,一个是不能用投影。特别是不能使用投影仪,对日常工作多少有些影响,带来不便,特别是要给客户做演示的时候,只能使用同事的电脑,极其不便。看到KMS/GEM补丁之后,就开始动心了。

可是KMS/GEM补丁只能在FreeBSD9上使用,而FreeBSD9又没有进入Beta版,还是处于开发阶段。对于其稳定性实在没有什么把握,于是买了块新的500G笔记本硬盘用于安装FreeBSD9。原来的硬盘安装的FreeBSD-8-stable保留起来,可以随时切换。

这次安装FreeBSD9,直接使用ZFS文件系统。回头再写个安装文档。

使用KMS/GEM补丁,参考FreeBSD的wiki上的文档 http://wiki.freebsd.org/Intel_GPU 。不过intel的显卡驱动,从git获取的源码编译不通过,单独下了个xf86-video-intel-2.15.0版本使用。

安装配置好后,按平时的使用检测了下。性能确实提升很大,开启gnome2,编译东西时不再卡。而且用Vbox下用PPS看高清电影,也不卡了。而且CPU使用率只在20-30%。以前得80%以上。

其次,可以使用外接显示器了。

不过目前的KMS/GEM补丁还没有进入正式测试阶段,还是属于内部研发阶段,BUG是避免不了的。目前我遇到的问题是,启动X后,切换不回去终端界面了,被模糊的图形覆盖了。

总体而言,FreeBSD9支持KMS/GEM后,在笔记本上使用,更爽了。期待早日发布稳定版本。

分类: BSD/linux 标签: ,

磁盘分区挂载表

2011年7月12日 16hot 没有评论

FreeBSD系统下的分区挂载表。

% cat /etc/fstab
# Device        Mountpoint    FStype    Options        Dump    Pass#
/dev/ada0s1b        none        swap    sw        0    0
/dev/ada0s1a        /        ufs    rw        1    1
/dev/ada0s3e        /opt        ufs    rw        2    2
/dev/ada0s2e        /opt/data        ufs    rw        2    2
/dev/ada0s2d        /opt/vm1        ufs    rw        2    2
/dev/ada0s3d        /opt/vm2        ufs    rw        2    2
/dev/ada0s1d        /tmp        ufs    rw        2    2
/dev/ada0s1f        /usr        ufs    rw        2    2
/dev/ada0s1e        /var        ufs    rw        2    2
/dev/cd0        /cdrom        cd9660    ro,noauto    0    0
proc            /proc       procfs  rw 0 0
linprocfs /compat/linux/proc linprocfs rw 0 0

如何在linux中mount ufs2文件系统?

FreeBSD的默认文件系统是ufs2。 可以用:

mount -r -t ufs -o ufstype=ufs2 /dev/hda10 /mnt

这样的命令来挂载。

前提:Linux内核中必须启用ufs和bsd disk label支持. 即

CONFIG_BSD_DISKLABEL=y
CONFIG_UFS_FS=y
CONFIG_UFS_FS_WRITE=y
分类: BSD/linux 标签: , ,

pf rtables and setfib in FreeBSD

2011年7月9日 16hot 没有评论

If one has multiple outgoing links to which one would like to use different routing tables the FreeBSD provides possibility through the setfib command but in order to have multiple routing tables one has to first compile a custom kernel with option ROUTETABLES in example simple kernel config:

include GENERIC
options         ROUTETABLES=4

After the kernel has been built and rebooted the different routing tables can be accessed as shown in the setfib(1) man page by issuing command setfib 0 netstat -rn. 0 is the default routing table.

After this one has to create the second routing table by prepending every route add command with setfib 1 route add… e.g:

# setfib 1 route add -net default 10.0.0.1

With packet filter one can control how the routing table is selected by using rtable option but it should be noted that this selection can only be done on the input of the packets as the routing decision is done at the input not at the output. Here is an example of very simple pf.conf that uses rtable rules and NATs everything to the external interface address:

#
# Macros
#
INT_IF = "em0"
EXT_IF = "bge0"
EXT_IF2 = "bge1"

table <private_nets> persist { 127/8, 172.16/12, 192.168/16, 169.254/16 }

#
# Options and default policy
#
set block-policy drop
set state-policy if-bound

#
# Packet normalization
#
scrub in                          all
scrub out on $EXT_IF all random-id
scrub        on $EXT_IF all reassemble tcp

#
# NAT/redirects
#

# NAT
nat on $EXT_IF from <private_nets> to any -> ($EXT_IF)
nat on $EXT_IF2 from <private_nets> to any -> ($EXT_IF2)

#
# Filter rules
#
pass all
pass in from 192.168.100.0/24 to any rtable 0
pass in from 192.168.150.0/24 to any rtable 1
分类: BSD/linux, 转载 标签: , ,