存档

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

FreeBSD: Redundant DNS with CARP

2010年12月11日 16hot 没有评论

http://zi0r.com/2010/02/28/freebsd-redundant-dns-with-carp.html

Improve reliability with CARP and redundant DNS on two boxes. Almost everyone already has (at least) two nameservers, so why not add CARP into the mix to make it appear as if they’re always available?

This setup assumes two nameservers. Both nameservers will have a total of 3 IPs assigned to them, two of which are the floating CARP IPs and one of which is a unique management IP for each box. Each nameserver will be the CARP backup for the other nameservers primary nameserver IP. If one goes down, the other will assume responsibility for the IP.

You’ll need to assign your nameservers two new IPs (to be used for management) and take the original pair of IPs and we’ll use those for the carp interfaces.

1. Rebuild/install your kernel with:
device carp

2. Edit /etc/rc.conf to add:
cloned_interfaces=“carp0 carp1”
ifconfig_carp0=“create”
ifconfig_carp1=“create”

3. Setup the CARP interfaces:

I set the vhid’s to be the last octet of the floaty IP, however, you can set them to be whatever you want as long as they match on both boxes.

On ns1:
Create /etc/start_if.carp0 with the following:
#!/bin/sh
ifconfig carp0 vhid XX advbase 1 advskew 10 pass supersecretpasswordhere netmask

Create /etc/start_if.carp1 with the following:
#!/bin/sh
ifconfig carp1 vhid YY advbase 2 advskew 10 pass othersupersecretpasswordhere netmask

Then run:
chmod go-rwx /etc/start_if.carp*;chmod +x /etc/start_if.carp*

On ns2:
Create /etc/start_if.carp0 with the following:
#!/bin/sh
ifconfig carp0 vhid YY advbase 1 advskew 10 pass supersecretpasswordhere netmask

Create /etc/start_if.carp1 with the following:
#!/bin/sh
ifconfig carp1 vhid XX advbase 2 advskew 10 pass othersupersecretpasswordhere netmask

Then run:
chmod go-rwx /etc/start_if.carp*;chmod +x /etc/start_if.carp*

  • carp0 on both boxes will be its PRIMARY IP whereas carp1 will be the SECONDARY IP on both. In a non-failover scenario, this means that carp0 on both boxes should show up as MASTER and carp1 should show up as BACKUP.

4. Ensure named is configured to bind to the management IP (for zone transfers, etc.), ns1.ip and ns2.ip (on both boxes!) or ensure that it listens on *.

5. Add net.inet.carp.log=2 to /etc/sysctl.conf for some extra logging info.

6. Reboot. Your primary box should come up with ns1.ip as MASTER and ns2.ip as BACKUP. Your secondary box should come up with ns2.ip as MASTER and ns1.ip as BACKUP. Check ifconfig and dmesg to confirm.

  • Note: CARP traffic is multicast and you may need to alter firewalls as appropriate to allow it. The destination is VRRP.MCAST.NET/224.0.0.18.
    For defining masters/slaves, etc. in bind you will want to reference the management IPs of the boxes, not the floating CARP addresses.
  • Note: You can actually skip using the start_if.* files if you elect to put the ifconfig statements into rc.conf. In order to limit access to your CARP authentication key, you would need to change the permissions on rc.conf which could be bad in certain situations.
  • ESX Note: If you’re trying to do this with a box in VMware, you’ll need to disable the vSwitch security features (accept: promisc, forged transmits, mac changes). This is not advisable in production as any VM on that switch can sniff traffic from any other VM. For my setup at home, I simply allocated a second NIC and a second vSwitch and made the security changes on the dedicated vSwitch. No other VMs should share this other vSwitch where the security features have been disabled.
分类: BSD/linux, DNS, 转载 标签: , ,

解决redmine不能浏览svn仓库的问题

2010年11月29日 16hot 没有评论

之前配置过,不能浏览也没有太在意。今天搜索了下,原来是svn路径的问题。

# vi ./lib/redmine/scm/adapters/subversion_adapter.rb

# SVN_BIN = “svn”
SVN_BIN = “/usr/local/bin/svn”

给svn命令加上完整路径就可以了。

分类: BSD/linux, 开发 标签: ,