存档

‘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, 转载 标签: , ,

Root On ZFS @ FreeBSD-Current(转载)

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

The new bsdInstaller is here but unfortunately as we saw it still doesn’t support a full ZFS installation. Also, due to the new layout of the installer the traditional way of installing from <FIXIT> doesn’t work anymore. The installation files are now located under /usr/freebsd-dist and the new “Live CD” option doesn’t create any kind of live fs. Therefore we have to improvise.

For the purpose of this demonstration am using a 9-Current that I created on April 29th. Boot with your 9-Current and choose “Lice CD” when prompted.

The first thing we need to do is to make /tmp writable so that we can store the zpool.cache file.

umount /dev/md1
mdmfs -s 512M md1 /tmp

That should be enough. Now,  lets partition our drive. I will be using a GPT scheme and create a native swap partition of 4 GB Ram, the rest will be allocated to ZFS. This guide installs FreeBSD on a single disk but this could be easily reproduced for a mirror or a raidz1 pool.

gpart create -s gpt ada0
gpart add -b 34 -s 64k -t freebsd-boot ada0
gpart add -s 4G -t freebsd-swap -l swap0 ada0
gpart add -t freebsd-zfs -l disk0 ada0
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0

My disk is now ready so I will create a pool and call it zroot and then mount it under /mnt. During this procedure some error messages will appear “can not mount, failed to create mount point”. The reason for those is that /mnt is read only but you can safely ignore them since we will export and import back our pool.

zpool create zroot /dev/gpt/disk0
zpool set bootfs=zroot zroot
zfs set checksum=fletcher4 zroot

Now lets create the file system layout. You can safely ignore the error messages about mounting  again since the pool hasn’t been exported/imported yet.

zfs set mountpoint=/mnt zroot
zfs create zroot/usr
zfs create zroot/var
zfs create -o compression=on -o exec=on -o setuid=off zroot/tmp
zfs create -o compression=lzjb -o setuid=off  zroot/usr/ports
zfs create -o compression=off -o exec=off -o setuid=off zroot/usr/ports/distfiles
zfs create -o compression=off -o exec=off -o setuid=off zroot/usr/ports/packages
zfs create -o compression=lzjb -o exec=off -o setuid=off  zroot/usr/src
zfs create -o compression=lzjb  -o exec=off     -o setuid=off   zroot/var/crash
zfs create -o exec=off -o setuid=off zroot/var/db
zfs create -o compression=lzjb  -o exec=on -o setuid=off  zroot/var/db/pkg
zfs create -o exec=off -o setuid=off   zroot/var/empty
zfs create -o compression=lzjb  -o exec=off -o setuid=off  zroot/var/log
zfs create -o compression=gzip -o exec=off -o setuid=off zroot/var/mail
zfs create -o exec=off -o setuid=off   zroot/var/run
zfs create -o compression=lzjb  -o exec=on -o setuid=off   zroot/var/tmp

Now at this point I will export the pool, import back while preserving the zpool.cache in /tmp

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

The pool is now mounted under /mnt and we can now proceed with the final steps.

chmod 1777 /mnt/tmp
cd /mnt ; ln -s /usr/home home
chmod 1777 /mnt/var/tmp
cp /tmp/zpool.cache /mnt/boot/zfs/zpool.cache

Next we need to install FreeBSD. Like I said things have changed therefore the procedure is different. This guide assumes that you also want to install source and ports. For a minimal installation only base.txz lib32.txz kernel.txz are necessary.

sh
cd /usr/freebsd-dist
export DESTDIR=/mnt
for file in base.txz lib32.txz kernel.txz doc.txz ports.txz src.txz;
do (cat $file | tar --unlink -xpJf - -C ${DESTDIR:-/}); done

Done! Now, all that is left is to create the rc.conf, loader.conf and fstab.

echo 'zfs_enable="YES"' >> /mnt/etc/rc.conf
echo 'zfs_load="YES"' >> /mnt/boot/loader.conf
echo 'vfs.root.mountfrom="zfs:zroot"' >> /mnt/boot/loader.conf
cat << EOF > /mnt/etc/fstab
# Device                       Mountpoint              FStype  Options         Dump    Pass#
/dev/gpt/swap0                 none                    swap    sw              0       0
EOF

Final steps

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

If you get a device busy message try umount -f /mnt

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

Reboot, adjust time zone info, add a password for root, add a user and enjoy!!!

附一个连接:

http://forums.freebsd.org/showthread.php?t=12082

分类: BSD/linux, 转载 标签: ,

好消息,KMS/GEM 出patch了

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

KMS/GEM出patch了。虽然现在只是在 HEAD代码中应用,并且还不是正式测试版。但是也可以看到了进展,看到了曙光。

http://www.phoronix.com/scan.php?page=news_item&px=OTYzMA

http://wiki.freebsd.org/Intel_GPU

分类: BSD/linux 标签:

FreeBSD 引导扇区修复(转)

2011年6月26日 16hot 没有评论

实际上,在FreeBSD中有这样一个工具:boot0cfg,其man手册说这是一个 boot managerinstallation/configuration utility,通过这个工具可以修改硬盘的MBR(也就是引导扇区)。这不就是我们所需要的么?作者仔细阅读了boot0cfg的man手册,详细了解 了其各项参数的意义。最后给出了本文将要说明的这种修复MBR的方案:

1、  通过FreeBSD引导光盘启动FreeBSD的Fixit控制台,在这个控制台下可以使用各种系统工具——这些系统工具都位于引导光盘上,而引导光盘则 被自动挂载到了/mnt2上,使用者也不需要修改PATH环境变量,因为PATH环境变量也被自动地做了修改,使得不用给出绝对路径就可以使用各种系统工 具,这其中自然也包括boot0cfg。

2、  通过下列命令修复MBR(也即硬盘的引导扇区),关于boot0cfg的这几个命令行选项,这里仅做简要说明,感兴趣的读者请参考[1]。以下命令需要root权限(这句是废话,通过Fixit控制台进入系统自然就是root用户):

boot0cfg -B -v -o noupdate -t 185 ad0

简要的说明一下:

-B选项:指明要在硬盘上安装引导程序

-v选项:给出详细信息

-o noupdate选项:避免在某些平台上出现问题(这些平台带有反病毒硬件,不允许修改MBR)

-t 185选项:启动时暂停10秒(近似值),以允许用户选择要启动的系统

分类: BSD/linux 标签: ,

用上ZFS了

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

早就拜读有关ZFS的资料,得知ZFS是一个很棒的文件系统。而且FreeBSD也支持ZFS,但是一直没有机会使用。

趁这次服务器换成1T的硬盘,干脆直接用上ZFS文件系统。

分类: BSD/linux 标签: ,

FreeBSD为文件加密与解密

2011年4月14日 16hot 没有评论

加密命令:
cat {想要加密的文件名} | crypt {想要设置的密码} > {新文件名/*也可以是源文件名*/}

解密命令:
crypt { 密码} <被加密文件的文件名> <解密后生成新文件的名称/*这里决不可使用被加密的文件名*/>

现有一个文档“ricky1”
#cat ricky1 | crypt 1234 > ricky1
这样一来“ricky1”就被加密了

要想将ricky1解密则使用下面的命令
#crypt 1234 <ricky1> ricky2

分类: BSD/linux, 转载 标签: ,