安装FreeBSD 6.2版本 只需要分两个区,/ 和 swap。 创建一个新用户并加入wheel组。 启动SSHD服务。
$pkg_add -r bash #(-r 表示使用远程下载:ftp)
$chpass username #(更改用户的登录shell=/usr/local/bin/bash,chpass实际会修改/etc/passwd文件)
$cp .profile .bash_profile
在.bash_profile中加入
PS1="[\u@\h:\w]"
case `id -u` in 0)
PS1="${PS1}# ";; *)
PS1="${PS1}$ ";;
esac
CVSup 用于从远程服务器主机上的主CVS仓库发布和升级源代码树的软件包。用户可以用其保持其源代码树更新。
$pkg_add -r cvsup-without-gui
CVSup的配置文件为/etc/supfile,可以参考/usr/share/examples/cvsup/下的模板文件撰写(具体参考FreeBSD用户手册 附录A)
$cp /usr/share/examples/cvsup/stable-supfile /etc/supfile $cp /usr/share/examples/cvsup/ports-supfile /etc/ports-supfile
*** 1.3.3 更新源码编辑/etc/supfile和/etc/ports-suppfile,寻找并更改下面,表示从那个站点下载 default host=cvsup.fr.FreeBSD.org
$cvsup -g -L 2 /etc/supfile $cvsup -g -L 2 /etc/ports-supfile
安装完所有的FreeBSD的Patches,使用动态库重新编译所有的程序,来节约磁盘空间 编辑 /etc/make.conf 加入(可参考/usr/share/examples/etc/make.conf更改/etc/make.conf) NO_SHARED=no
$cd /usr/src $make -j4 buildworld #在/usr/obj下建立一个全新的stable树,-j4表示并行编译4个程序 $make buildkernel #建立新的stable缺省内核 $make installkernel #安装内核 $reboot
启动时使用单用户模式,给loader传入参数 boot -s
$fsck -p #使用preen模式检测文件系统,仅仅修复一部分错误,遇到特殊错误会报错并退出 $mount -u / #装载根分区。 -u 表示一个已经mount的磁盘状态应该改变 $mount -a -t ufs #-a 表示mount /etc/fstab所有后面 -t 表示的ufs文件系统 $swapon -a #打开交换分区。-a 表示使用所有 /etc/fstab中列出的swap,除了noauto $adjkerntz -i #保持cmos中的local和kernel中的UTC时间的offset,-i表示将 adjkerntz 加入启动和关闭中来自动运行,/etc/rc中会加入相应条目。 $mergemaster -p #安装系统配置文件的脚本工具,建立一个临时的根环境,把新的配置文件映射到这个环境 $cd /usr/src $make installworld #安装新的stable程序树 $make delete-old # $mergemaster #更新/etc配置文件,需要与用户交互,如果是新安装的系统,则直接更新 $reboot $make delete-old-libs
$pkg_add -r perl $cd /usr/ports $make index $pkg_add -r portupgrade #安装portupgrade工具,来简化port升级过程 $portversion -l "<" #显示需要升级的port $portupgrade -arR #开始升级port,-a升级所有已安装且过时的程序 -r按照依赖关系递归的升级 -R按照需要关系递归的升级
安装FreeNAS需要的工具和PHP脚本,如果指令不是很清楚,下载FreeNAS的根文件系统.tgz文件并与你安装的相比较来进行分析。
$export WORKINGDIR="/usr/local/freenas" $export FREENAS="/usr/local/freenas/rootfs" $export BOOTDIR="/usr/local/freenas/bootloader" #引导程序 $export CDROOT="/usr/local/freenas/cdroot" #生成最终cd iso文件的目录
$mkdir /usr/local/freenas
下载freenas-create-dir.sh,其内容为:
#!/bin/sh
#
# This script was written by David Courtney of Ultradesic
# http://www.ultradesic.com
# E-Mail Contact: minibsd@ultradesic.com
#
# Adapted for FreeNAS by Olivier Cochard-Labbé (http://www.freenas.org)
# Modified by Volker Theile (votdev@gmx.de)
MINIBSD_DIR=/usr/local/freenas/rootfs;
# Initialize variables.
opt_f=0
# Parse the command-line options.
while getopts 'fh' option
do
case "$option" in
"f") opt_f=1;;
"h") echo "$(basename $0): Create FreeNAS directory structure";
echo "Common Options:";
echo " -f Force executing this script";
exit 1;;
?) echo "$0: Bad option specified. Exiting...";
exit 1;;
esac
done
shift `expr $OPTIND - 1`
echo "Create FreeNAS directory structure..."
if [ ! -z "$1" ]; then
MINIBSD_DIR=$1;
echo "Using directory $1.";
fi
if [ 1 != $opt_f -a -d "$MINIBSD_DIR" ]; then
echo ;
echo "$MINIBSD_DIR already exists. Remove the directory" ;
echo "before running this script." ;
echo ;
echo "Exiting..." ;
echo ;
exit 1 ;
fi ;
mkdir $MINIBSD_DIR ;
cd $MINIBSD_DIR ;
# Create directories
mkdir boot ; # fdisk 和bsdlabel使用
mkdir boot/kernel ; # 保存kernel 模块
mkdir bin ;
mkdir cf ; # 用于挂载Compact Flash card , Hard disk ..
mkdir ftmp ; # 用于通过WebGUI进行防火墙升级时挂载临时的内存文件系统
mkdir conf.default ; # 保存出厂时的默认配置文件config.xml
mkdir dev ;
mkdir etc ;
mkdir etc/defaults ;
mkdir etc/inc ; # 保存boot脚本和WebGUI所需要的php include文件
mkdir etc/pam.d ;
mkdir etc/ssh ;
mkdir etc/iscsi ;
mkdir lib ;
mkdir lib/geom ;
mkdir libexec ;
mkdir -m 0777 mnt ;
mkdir -m 0700 root ;
mkdir sbin ;
mkdir usr ;
mkdir usr/bin ;
mkdir usr/lib ;
mkdir usr/lib/aout ;
mkdir usr/libexec ;
mkdir usr/local ;
mkdir usr/local/bin;
mkdir usr/local/lib ;
mkdir usr/local/sbin ;
mkdir usr/local/share ;
mkdir usr/local/share/locale ;
mkdir usr/local/etc ;
mkdir usr/local/www ; # WebGUI文件
mkdir usr/local/www/syntaxhighlighter ;
mkdir usr/sbin ;
mkdir usr/share ;
mkdir usr/share/misc ;
mkdir usr/share/locale ;
mkdir tmp ;
mkdir var ;
# Creating symbolic links. Most of the target files will be created at runtime.
# 大多数的连接目标文件在FreeNAS运行时生成
ln -s cf/conf conf
ln -s /var/run/htpasswd usr/local/www/.htpasswd #在webGUI运行时用户配置的user/passwd会保存在/var/run/htpasswd中
ln -s /var/etc/resolv.conf etc/resolv.conf
ln -s /var/etc/master.passwd etc/master.passwd
ln -s /var/etc/passwd etc/passwd
ln -s /var/etc/group etc/group
ln -s /var/etc/hosts etc/hosts
ln -s /var/etc/pwd.db etc/pwd.db
ln -s /var/etc/spwd.db etc/spwd.db
ln -s /var/etc/crontab etc/crontab
ln -s /var/etc/ssh/sshd_config etc/ssh/sshd_config
ln -s /var/etc/ssh/ssh_host_dsa_key etc/ssh/ssh_host_dsa_key
ln -s /var/etc/iscsi/targets etc/iscsi/targets
ln -s /var/etc/pam.d/ftp etc/pam.d/ftp
ln -s /var/etc/pam.d/ftp etc/pam.d/pure-ftpd
ln -s /var/etc/pam.d/sshd etc/pam.d/sshd
ln -s /var/etc/pam.d/login etc/pam.d/login
ln -s /var/etc/pam.d/system etc/pam.d/system
ln -s /var/etc/ldap.conf usr/local/etc/ldap.conf
ln -s /var/etc/nsswitch.conf etc/nsswitch.conf
ln -s /libexec/ld-elf.so.1 usr/libexec/ld-elf.so.1
下载 freenas.files 和 mkmini.pl
运行的命令
$pkg_add -r perl $perl mkmini.pl freenas.files / $FREENAS
freenas.files文件内容为
# freenas.files
# List of files required for a the FreeNAS,
# intended to be parsed by mkmini.pl (script created by Manuel Kasper <mk@neon1.net>)
#
# Lines with colons (':') in them list files that should be hard-linked
# to each other, e.g.
# bin/link:bin/ln
# instructs mkmini.pl to copy over bin/link, then hard link ln to it.
####### contents of /bin
## Test: condition evaluation utility
bin/[:bin/test
## cat -- concatenate and print files
bin/cat
## chmod -- change file modes
bin/chmod
## cp -- copy files
bin/cp
## tcsh - C shell with file name completion and command line editing
bin/csh:bin/tcsh
## date -- display or set date and time
bin/date
## dd -- convert and copy a file
bin/dd
## df -- display free disk space
bin/df
## echo -- write arguments to the standard output
bin/echo
## expr -- evaluate expression
bin/expr
## hostname -- set or print name of current host system
bin/hostname
## kill -- terminate or signal a process
bin/kill
## ln, link -- make links
bin/link:bin/ln
## ls -- list directory contents
bin/ls
## mkdir -- make directories
bin/mkdir
## mv -- move files
bin/mv
## pax -- read and write file archives and copy directory hierarchies
#bin/pax
##ps -- process status
bin/ps
##pwd -- return working directory name
#Prevent WinSCP to Generate Error message
bin/pwd:bin/realpath
## rm, unlink -- remove directory entries
bin/rm:bin/unlink
##sh -- command interpreter (shell)
bin/sh
## sleep -- suspend execution for an interval of time
bin/sleep
## stty -- set the options for a terminal device interface
bin/stty
## sync -- force completion of pending disk writes (flush cache)
bin/sync
####### contents of /sbin
# adjkerntz -- adjust local time CMOS clock to reflect time zone changes and keep current timezone offset for the kernel
sbin/adjkerntz
## bsdlabel -- read and write disk pack label
sbin/bsdlabel
##devfs -- DEVFS control (NEW from FreeBSD 5.2, replace the )
sbin/devfs
## dhclient -- Dynamic Host Configuration Protocol (DHCP) client
sbin/dhclient
## dhclient-script -- DHCP client network configuration script
sbin/dhclient-script
## dmesg -- display the system message buffer
sbin/dmesg
## reboot, halt, fastboot, fasthalt -- stopping and restarting the system
sbin/fastboot:sbin/fasthalt:sbin/halt:sbin/reboot
## fdisk -- PC slice table maintenance utility
sbin/fdisk
## fsck -- file system consistency check and interactive repair
sbin/fsck
## fsck -- UFS,FFS 4.2BSD file system consistency check and interactive repair
sbin/fsck_ufs:sbin/fsck_ffs:sbin/fsck_4.2bsd
## fsck -- DOS/WINDOWS file system consistency check and interactive repair
sbin/fsck_msdosfs
## Gconcat -- Geom concat
sbin/gconcat
# Growfs -- grow size of an existing ufs file system
sbin/growfs
## gstripe -- Geom stripe
sbin/gstripe
## gmirror -- Geom mirror
sbin/gmirror
# geli -- Control utility for cryptographic GEOM class
sbin/geli
## gpt -- Manipulate GUID partition tables
sbin/gpt
## gvinum -- Volume manager (RAID0,1,5)
sbin/gvinum
## ifconfig -- configure network interface parameters
sbin/ifconfig
## init -- process control initialization
sbin/init
## kldload -- load a file into the kernel
sbin/kldload
## kldstat -- display status of dynamic kernel linker
sbin/kldstat
## kldunload -- unload a file from the kernel
sbin/kldunload
## ldconfig -- configure the shared library cache
sbin/ldconfig
# mdconfig -- configure and enable memory disks
sbin/mdconfig
## mknod -- build special file
sbin/mknod
## mount -- mount file systems
sbin/mount
## mount_std, mount_devfs, mount_fdescfs, mount_linprocfs, mount_procfs -- mount ``standard'' file systems
sbin/mount_devfs:sbin/mount_fdescfs:sbin/mount_linprocfs:sbin/mount_procfs:sbin/mount_std:
## mdmfs, mount_mfs -- configure and mount an in-memory file system using the md(4) driver
sbin/mdmfs
## mount_nullfs -- mount a loopback file system sub-tree; demonstrate the use of a null file system layer
sbin/mount_nullfs
## mount_umapfs -- sample file system layer
sbin/mount_umapfs
## mount_unionfs -- mount union file systems
sbin/mount_unionfs
## mount_msdosfs -- mount MS-DOS file system
sbin/mount_msdosfs
## mount_nfs -- mount NFS file system
sbin/mount_nfs
## mount_nfs4 -- mount NFSv4 file system
sbin/mount_nfs4
## mount_ntfs -- mount NTFS file system: Replaced by NTFS-3G
#sbin/mount_ntfs
## mount_ext2fs -- mount ext2fs file system
sbin/mount_ext2fs
## mount_cd9660 -- mount CDROM file system
sbin/mount_cd9660
## mount_reiserfs -- mount ReiserFS file system
sbin/mount_reiserfs
## mount_udf -- mount UDF file system
sbin/mount_udf
## natd -- Network Address Translation daemon
#sbin/natd
## newsfs -- construct a new UFS1/UFS2 file system
sbin/newfs
## newsfs -- construct a FAT (16/32) file system
sbin/newfs_msdos
##nologin -- politely refuse a login
sbin/nologin
## ping -- send ICMP ECHO_REQUEST packets to network hosts
sbin/ping
## route -- manually manipulate the routing tables
sbin/route
## shutdown -- close down the system at a given time
sbin/shutdown
##sysctl -- get or set kernel state
sbin/sysctl
## swapon - Enable swap
sbin/swapon
## swapoff - Disable swap
sbin/swapoff
##tunefs -- tune up an existing file system
sbin/tunefs
## umount -- unmount file systems
sbin/umount
# atacontrol: manage IDE disk
sbin/atacontrol
# camcontrol: manage SCSI disk
sbin/camcontrol
####### contents of /usr/bin
# chgrp: change group
usr/bin/chgrp
# fstat -- identify active files . Fuse mount use fstat
usr/bin/fstat
## FTP/HTTP download tools
usr/bin/fetch
## This utility prevent WinSCP to display error message
usr/bin/groups
## gzip, gunzip, zcat - compress or expand files
usr/bin/gzip:usr/bin/gunzip
## id - displays the user and group names and numeric IDs, of the calling process
usr/bin/id
## killall -- kill processes by name
usr/bin/killall
## logger -- make entries in the system log
usr/bin/logger
## netstat -- show network status
usr/bin/netstat
## nohup -- invoke a utility immune to hangups
usr/bin/nohup
## passwd -- Change user passwd
usr/bin/passwd
## su -- substitute user identity
usr/bin/su
##scp -- secure copy (remote file copy program)
usr/bin/scp
##ssh -- secure Shell Client (used for RSYNC and Unison over SSH)
# FreeNAS use the port openssh-portable with HPN-SSH patch enabled
# usr/bin/ssh
## tail -- display the last part of a file
usr/bin/tail
## tar -- manipulate tape archives
usr/bin/tar
## top - display and update information about the top cpu processes
usr/bin/top
## touch -- create/change file access and modification times
usr/bin/touch
## uptime -- show how long system has been running
usr/bin/uptime:usr/bin/w
####### contents of /usr/sbin
## ancontrol -- configure Aironet 4500/4800 devices
usr/sbin/ancontrol
## arp -- address resolution display and control
usr/sbin/arp
#boot0cfg -- boot manager installation/configuration utility
usr/sbin/boot0cfg
## chown -- change file owner and group
usr/sbin/chown
##chroot -- change root directory
usr/sbin/chroot
## cron - The scheduler
usr/sbin/cron
## powerd -- System power control utility
usr/sbin/powerd
## pwd_mkdb -- generate the password databases
usr/sbin/pwd_mkdb
## swapinfo - Give info on the swap disk
usr/sbin/swapinfo
## traceroute - print the route packets take to network host
usr/sbin/traceroute
# wicontrol -- configure Lucent, Intersil, and Atheros wireless devices
usr/sbin/wicontrol
# NFS server tools
usr/sbin/mountd
usr/sbin/nfsd
usr/sbin/rpcbind
usr/sbin/rpc.lockd
usr/sbin/rpc.statd
# sshd - Daemon program for ssh
# FreeNAS use the port openssh-portable with HPN-SSH patch enabled
#usr/sbin/sshd
####### contents of /usr/libexec
# ld-elf.so.1, ld.so, rtld -- run-time link-editor
libexec/ld-elf.so.1:usr/libexec/ld-elf.so.1
# sft-server
# FreeNAS use the port openssh-portable with HPN-SSH patch enabled
#usr/libexec/sftp-server
####### contents of /usr/share/misc
usr/share/misc/termcap
####### contents of /usr/share/locale
usr/share/locale/en_US.ISO8859-1/*
usr/share/locale/en_US.UTF-8/*
usr/share/locale/la_LN.US-ASCII/*
usr/share/locale/UTF-8/*
####### contents of /usr/local/bin
# nano - a small, free and friendly editor: IT's a port!!!
#usr/local/bin/nano
####### contents of /usr/lib
# PAM libraries
usr/lib/pam_*.so.3
####### contents of /lib/geom
# GEOM tools
lib/geom/*
####### contents of /etc/ssh
# moduli -- system moduli file
etc/ssh/moduli
下载freenas-etc.tgz 并解压缩至$FREENAS/目录
$fetch http://www.freenas.org/downloads/freenas-etc.tgz $tar -xzf freenas-etc.tgz -C $FREENAS/
并且确保/etc/rc下的rc.*文件有执行权限 chmod 755
在主机生成$FREENAS/etc/master.passwd并拷贝至$FREENAS/etc/,通过下列命令生成newpasssword数据库(pwd.db和spwd.db) -p表示重新生成/etc/passwd
$pwd_mkdb -p -d $FREENAS/etc $FREENAS/etc/master.passwd $tar cfvz freenas-tgz $FRRRNAS/etc/* #为了节省空间,???
/etc/platform文件非常重要,它标识出image是由什么系统生成的,php脚本使用它确定配置存储在何处以及webGUI中应该显示出的option。可以设置为以下值:
$echo "0.67b" > $FREENAS/etc/version $date > $FREENAS/etc/version.buildtime $echo "generic-pc-cdrom">$FREENAS/etc/platform
下载最新的默认配置文件http://www.freenas.org/downloads/config.xml 拷贝至$FREENAS/conf.defalut/config.xml
$cd $FREENAS/conf.default/ $fetch http://www.freenasw.org/downloads/config.xml
FreeNAS将时区信息保存在/usr/share/zoneinfo中,为了保存空间,m0n0wall使用一个stripped down的版本,并将其打包tar...
$cd $FREENAS/usr/share $fetch http://www.freenas.org/downloads/zoneinfo.tgz
$mkdir a100 $cd a100 $fetch http://www.freenas.org/downloads/bsd4a100.zip $gunzip bsd4a100.zip $cp a100.* /usr/src/sys/pci $echo "pci/a100.c optional ihb device-driver" >> /usr/src/sys/conf/files
下载FreeNAS的内核配置文件
$cd /sys/i386/conf/ $fetch http://www.freenas.org/downloads/FREENAS
编译内核和模块
$config FREENAS #config 命令产生内核源代码,并命名为FREENAS $cd ../compile/FREENAS/ #进入编译目录 $make cleandepend;make depend #编译 $make $gzip -9 kernel #压缩编译出的内核
$cp /sys/i386/compile/FREENAS/modules/usr/src/sys/modules/geom/geom_vinum/geom_vinum.ko $FREENAS/boot/kernel $cp /sys/i386/compile/FREENAS/modules/usr/src/sys/modules/geom/geom_stripe/geom_stripe.ko $FREENAS/boot/kernel $cp /sys/i386/compile/FREENAS/modules/usr/src/sys/modules/geom/geom_concat/geom_concat.ko $FREENAS/boot/kernel $cp /sys/i386/compile/FREENAS/modules/usr/src/sys/modules/geom/geom_mirror/geom_mirror.ko $FREENAS/boot/kernel $cp /sys/i386/compile/FREENAS/modules/usr/src/sys/modules/geom/geom_gpt/geom_gpt.ko $FREENAS/boot/kernel ####$cp /sys/i386/compile/FREENAS_GENERIC/modules/usr/src/sys/modules/ntfs/ntfs.ko $FREENAS/boot/kernel $cp /sys/i386/compile/FREENAS/modules/usr/src/sys/modules/ext2fs/ext2fs.ko $FREENAS/boot/kernel/
$cd /usr/src $fetch http://home.tiscali.de/cmdr_faako/geom_raid5.tbz $tar zxvf geom_raid5.tbz $cd /usr/src/sys/modules/geom/geom_raid5/ $make depend $make $cp geom_raid5.ko $FREENAS/boot/kernel/ $cd /usr/src/sbin/geom/class/raid5/ $mkdir /usr/include/geom/raid5 $cp /usr/src/sys/geom/raid5/g_raid5.h /usr/include/geom/raid5/ $make depend $make $make install $cp -p /sbin/graid5 $FREENAS/sbin/ $mkdir $FREENAS/lib/geom/ $cp geom_raid5.so $FREENAS/lib/geom/
mbr为fdisk用来创建可启动磁盘
$cp /boot/mbr $FREENAS/boot/
$pkg_add -r libxml2
$./configure --enable-fastcgi --enable-discard-path --enable-force-cgi-redirect --without-mysql --without-pear --with-openssl --without-sqlite --with-pcre-regex $make $install -s sapi/cgi/php $FREENAS/usr/local/bin
magic_quotes_gpc = Off magic_quotes_runtime = Off max_execution_time = 0 max_input_time = 180 register_argc_argv = Off file_uploads = On upload_tmp_dir = /ftmp upload_max_filesize = 256M post_max_size = 256M html_errors = Off include_path = ".:/etc/inc:/usr/local/www"
$fetch http://www.lighttpd.net/download/lighttpd-1.4.13.tar.gz $tar zxvf lighttpd-1.4.13.tar.gz $cd lighttpd-1.4.13 $./configure --sysconfdir=/var/etc/ --enable-lfs --without-mysql --without-ldap --with-openssl --without-lua --with-bzip2 --without-pam $make $install -s src/lighttpd $FREENAS/usr/local/sbin $mkdir $FREENAS/usr/local/bin/lighttpd $cp src/.libs/mod_indexfile.so $FREENAS/usr/local/lib/lighttpd/ $cp src/.libs/mod_access.so $FREENAS/usr/local/lib/lighttpd/ $cp src/.libs/mod_accesslog.so $FREENAS/usr/local/lib/lighttpd/ $cp src/.libs/mod_dirlisting.so $FREENAS/usr/local/lib/lighttpd/ $cp src/.libs/mod_staticfile.so $FREENAS/usr/local/lib/lighttpd/ $cp src/.libs/mod_cgi.so $FREENAS/usr/local/lib/lighttpd/ $cp src/.libs/mod_auth.so $FREENAS/usr/local/lib/lighttpd/ $cp src/.libs/mod_webdav.so $FREENAS/usr/local/lib/lighttpd/
clog程序记录所有到子网的连接。它使用pcap 库。
$fetch http://www.freenas.org/downloads/clog-1.0.1.tar.gz $fetch http://www.freenas.org/downloads/syslogd_clog-current.tgz $tar zxvf clog-1.0.1.tar.gz $tar zxvf syslogd_clog-current.tgz $cd syslogd $make $install -s syslogd $FREENAS/usr/sbin/ $cd ../clog $gcc clog.c -o clog $install -s clog $FREENAS/usr/sbin/
MSNTP为SNTP客户端,与NTP和SNTP服务器通讯显示和设置本地系统时间。可运行于交互模式,cron,或者daemon。
$cd /usr/ports/net/msntp/ $make $install -s work/msntp-1.6/msntp $FREENAS/usr/local/bin/
配置$FREENAS/usr/local/bin/runmsntp.sh并更改为可执行权限。
#!/bin/sh
# write our PID to file
echo $$ > $1
# execute msntp in endless loop; restart if it
# exits (wait 1 second to avoid restarting too fast in case
# the network is not yet setup)
while true; do
/usr/local/bin/msntp -r -P no -l $2 -x $3 $4
sleep 1
done
ataid处理ata协议硬盘在空闲时间放低转速。
$cd /usr/ports/sysutils/ataidle $make $install -s work/ataidle-0.9/ataidle $FREENAS/usr/local/sbin/
$fetch ftp://ftp.cs.huji.ac.il/users/danny/freebsd/iscsi-2.0.1.tar.bz2 $tar zxvf iscsi-2.0.1.tar.bz2 $cd sys $ln -s /sys/kern . $ln -s /sys/tools . $cd modules/iscsi_initiator $make clean $ln -s ../.. @ $make $cp iscsi_initiator.ko $FREENAS/boot/kernel/ $cd ../../../iscontrol/ $make $install -s iscontrol $FREENAS/usr/local/sbin/
$cd /root $fetch http://download.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.0.21.tar.gz $tar zxvf pure-ftpd-1.0.21.tar.gz $cd pure-ftpd-1.0.21 $./configure --with-rfc2640 --with-largefile --with-pam $make $install -s src/pure-ftpd $FREENAS/usr/local/sbin/
fetch http://us2.samba.org/samba/ftp/samba-latest.tar.gz tar zxvf samba-latest.tar.gz cd samba-3.0.23d/source/ ./configure --without-cups --with-ads --disable-cups --without-ads --with-pam --with-ldapsam --with-acl-support --with-winbind --with-pam_smbpass --with-logfilebase=/var/log/samba --with-piddir=/var/run --with-privatedir=/var/etc/private --with-configdir=/var/etc --with-lockdir=/var/run --with-piddir=/var/run --with-shared-modules=idmap_rid --with-pammodulesdir=/usr/local/lib --with-syslog make install samba: install -s bin/smbd $FREENAS/usr/local/sbin/ install -s bin/nmbd $FREENAS/usr/local/sbin/ install -s bin/winbindd $FREENAS/usr/local/sbin/ install -s bin/smbpasswd $FREENAS/usr/local/bin/ install -s bin/net $FREENAS/usr/local/bin/ install -s nsswitch/nss_winbind.so $FREENAS/usr/local/lib/ install -s nsswitch/nss_wins.so $FREENAS/usr/local/lib/ install -s bin/pam_winbind.so $FREENAS/usr/local/lib/ ln -s $FREENAS/usr/local/lib/nss_winbind.so $FREENAS/usr/local/lib/nss_winbind.so.1 mkdir $FREENAS/usr/local/samba/lib/idmap mkdir $FREENAS/usr/local/samba/lib/vfs install -s bin/rid.so $FREENAS/usr/local/samba/lib/idmap mkdir $FREENAS/usr/local/lib/samba mkdir $FREENAS/usr/local/lib/samba/charset mkdir $FREENAS/usr/local/lib/samba/rpc mkdir $FREENAS/usr/local/lib/samba/pdb cp bin/CP*.so $FREENAS/usr/local/lib/samba/charset cp codepages/*.dat $FREENAS/usr/local/lib/samba/ cp po/*.* $FREENAS/usr/local/lib/samba/ cp bin/recycle.so $FREENAS/usr/local/samba/lib/vfs
$cp /usr/sbin/nfsd $FREENAS/usr/sbin $cp /usr/sbin/mountd $FREENAS/usr/sbin $cp /usr/sbin/rpcbind $FREENAS/usr/sbin
Netatalk使用AppleTalk协议,为Apple电脑提供文件服务。
$cd /usr/ports/databases/db42 $make $make install
fetch http://ovh.dl.sourceforge.net/sourceforge/netatalk/netatalk-2.0.3.tar.gz tar zxvf netatalk-2.0.3.tar.gz cd netatalk-2.0.3 ./configure --bindir=/usr/local/bin --sbindir=/usr/local/sbin --sysconfdir=/var/etc --localstatedir=/var --enable-largefile --disable-tcp-wrappers --disable-cups --with-pam --with-uams-path=/etc/uams/ install -s etc/afpd/afpd $FREENAS/usr/local/sbin/ mkdir $FREENAS/etc/uams cp etc/uams/.libs/uams_passwd.so $FREENAS/etc/uams cp etc/uams/.libs/uams_dhx_passwd.so $FREENAS/etc/uams cp etc/uams/.libs/uams_guest.so $FREENAS/etc/uams cp etc/uams/.libs/uams_randnum.so $FREENAS/etc/uams cd $FREENAS/etc/uams ln -s uams_passwd.so uams_clrtxt.so ln -s uams_dhx_passwd.so uams_dhx.so cd $FREENAS/usr/local/lib/ cp /usr/local/lib/libdb-4.2.so.2 . cd $FREENAS/usr/lib/ cp /usr/lib/librpcsvc.so.3 .
RSYNC数据镜像和备份工具。本地/远程,目录之间进行快速同步镜像,远程数据备份等。仅仅更新变动部分。
$fetch http://samba.anu.edu.au/ftp/rsync/rsync-2.6.9.tar.gz $tar zxvf rsync-2.6.9.tar.gz $cd rsync-2.6.9 $./configure --with-rsyncd-conf=/var/etc $make $install -s rsync $FREENAS/usr/local/bin/
Unison 目录文件同步工具,与rsync不同为,它同步是双向的。
$cd /usr/ports/net/unison/ $make $cp work/unison-2.13.16/unison $FREENAS/usr/local/bin/
为采用ssh加密的sftp提供一个安全的chroot环境,它可以生成一个scponlyc的shell,只能运行scp / sftp等命令,且于rsync,svn,gftp兼容。
$cd /usr/ports/shells/scponly/
编辑Makefile
WITH_SCPONLY_RSYNC=YES WITH_SCPONLY_SCP=YES WITH_SCPONLY_WINSCP=YES WITH_SCPONLY_UNISON=YES WITH_SCPONLY_SFTP_LOGGING=YES
编译
$make $install -s work/scponly-4.4/scponly $FREENAS/usr/local/bin/
启动sshd,sftpd服务 编辑/usr/ports/security/openssh-portable/Makefile
HPN "Enable HPN-SSH patch" on \
编译
$make $install -vs work/openssh-4.5p1/sshd $FREENAS/usr/sbin/ $install -vs work/openssh-4.5p1/sftp-server $FREENAS/usr/libexec/
cd /usr/ports/sysutils/fusefs-kmod make cp -pv work/fuse4bsd-*/mount_fusefs/mount_fusefs $FREENAS/usr/local/sbin/ cp -pv work/fuse4bsd-*/fuse_module/fuse.ko $FREENAS/boot/kernel cd /usr/ports/sysutils/fusefs-ntfs/ make cp -p work/ntfs-3g-0.20070118-BETA/libntfs-3g/.libs/libntfs-3g.so $FREENAS/usr/local/lib/libntfs-3g.so.0 install -s work/ntfs-3g-0.20070118-BETA/src/.libs/ntfs-3g $FREENAS/usr/local/bin/ install -s /usr/local/lib/libfuse.so.2 $FREENAS/usr/local/lib/
$cd /usr/ports/sysutils/e2fsprogs/ $make $install -s work/e2fsprogs-1.39/e2fsck/e2fsck $FREENAS/usr/local/sbin/
$cd /usr/ports/sysutils/smartmontools/ $make $install -s work/smartmontools-5.37/smartctl $FREENAS/usr/local/sbin/ $install -s work/smartmontools-5.37/smartd $FREENAS/usr/local/sbin/
Adaptec SCSI RAID 管理工具,可以用来监控RAID卡状态。
$cd /usr/ports/sysutils/aaccli/ $make $tar zxvf work/aaccli-1.0_0.tgz $cp work/bin/aaccli $FREENAS/usr/local/bin/
$cd /usr/ports/audio/beep $make $install -s work/beep/beep $FREENAS/usr/local/bin/
一种apple的无须配置的网络连接方式。
$cd /usr/ports/net/mDNSResponder $make $install -s work/mDNSResponder-108/mDNSPosix/build/prod/mDNSResponderPosix $FREENAS/usr/local/sbin/
使用freenas-create-bootdir.sh生成引导需要的文件。
#!/bin/sh
#
# This script was written by David Courtney of Ultradesic
# http://www.ultradesic.com
# E-Mail Contact: minibsd@ultradesic.com
#
# Adapted for m0n0wall on FreeBSD 6.1 by Olivier Cochard-Labbé (http://www.freenas.org)
# Modified by Volker Theile (votdev@gmx.de)
MINIBSD_DIR=/usr/local/freenas/bootloader;
# Initialize variables.
opt_a=0
opt_d=0
opt_s=0
opt_f=0
# Parse the command-line options.
while getopts 'adfhs' option
do
case "$option" in
"a") opt_a=1;;
"d") opt_d=1;;
"f") opt_f=1;;
"s") opt_s=1;;
"h") echo "$(basename $0): Build boot loader";
echo "Common Options:";
echo " -a Disable ACPI"
echo " -d Enable debug"
echo " -s Enable serial console";
echo " -f Force executing this script";
exit 1;;
?) echo "$0: Bad option specified. Exiting...";
exit 1;;
esac
done
shift `expr $OPTIND - 1`
echo "Building the boot loader..."
if [ -n "$1" ]; then
MINIBSD_DIR=$1
echo "Using directory $1."
fi
if [ 1 != $opt_f -a -d "$MINIBSD_DIR" ]; then
echo
echo "=> $MINIBSD_DIR already exists. Remove the directory"
echo "=> before running this script."
echo
echo "=> Exiting..."
echo
exit 1
fi
# Create the boot directory that will contain boot, and kernel
mkdir $MINIBSD_DIR
mkdir $MINIBSD_DIR/defaults
mkdir $MINIBSD_DIR/kernel
# Copy the file in this directory:
cp -v /boot/defaults/loader.conf $MINIBSD_DIR/defaults
cp -v /boot/loader $MINIBSD_DIR
cp -v /boot/boot $MINIBSD_DIR
cp -v /boot/mbr $MINIBSD_DIR
cp -v /boot/cdboot $MINIBSD_DIR
cp -v /boot/loader.4th $MINIBSD_DIR
cp -v /boot/support.4th $MINIBSD_DIR
cp -v /boot/device.hints $MINIBSD_DIR
# Generate the loader.rc file using by bootloader
echo "Generate $MINIBSD_DIR/loader.rc"
echo 'include /boot/loader.4th
start
check-password' > $MINIBSD_DIR/loader.rc
# Generate the loader.conf file using by bootloader
echo "Generate $MINIBSD_DIR/loader.conf"
echo 'mfsroot_load="YES"
mfsroot_type="mfs_root"
mfsroot_name="/mfsroot"
autoboot_delay="-1"' > $MINIBSD_DIR/loader.conf
# Enable debug?
if [ 0 != $opt_d ]; then
echo 'verbose_loading="YES"' >> $MINIBSD_DIR/loader.conf
echo 'boot_verbose=""' >> $MINIBSD_DIR/loader.conf
fi
# Enable serial console?
if [ 0 != $opt_s ]; then
echo 'console="comconsole"' >> $MINIBSD_DIR/loader.conf
fi
# Disable ACPI?
if [ 0 != $opt_a ]; then
echo 'hint.acpi.0.disabled="1"' >> $MINIBSD_DIR/device.hints
fi
# Copy kernel.
if [ -e "/usr/obj/usr/src/sys/FREENAS/kernel.gz" ] ; then
cp /usr/obj/usr/src/sys/FREENAS/kernel.gz $MINIBSD_DIR/kernel
else
echo "=> ERROR: File kernel.gz does not exist!";
exit 1;
fi
FreeBSD启动顺序
1 boot0 为MBR(位于硬盘1扇区)。对应LILO。使用boot0cfg安装,默认基于/boot/boot0。446字节。 MBR 包括主引导程序、硬盘分区表且以0x55AA结尾。显示可选择的引导操作系统。 可以用FreeBSD的MBR覆盖现有的MBR $fdisk -B -b /boot/boot0 device device为要写入的磁盘名,如ad0,ad2(ide);da0(scsi)
2 boot1 与boot2 与boot2都属于同一个程序/boot/boot,处于磁盘的相同区域(文件系统外,引导分区的第一个轨道,第一个扇区),但由于空间限制,被分为两部分。可以使用bsdlabel更改。
3 booter 最后阶段,放置在文件系统中,为/boot/loader. 使用友好的配置方式,使用内建的命令集。
需要的动态连接库还没有添加。通过下载mklibs.pl并在root文件系统上运行来创建。
$fetch http://www.freenas.org/downloads/mklibs.pl $perl mklibs.pl $FREENAS > freenas.libs $perl mkmini.pl freenas.libs / $FREENAS $cp -p /usr/lib/pam_*.so.3 $FREENAS/usr/lib $cd /usr/ports/security/pam_ldap/ $make install $cp -p /usr/local/lib/pam_ldap.so $FREENAS/usr/local/lib $cp /libexec/ld-elf.so.1 $FREENAS/libexec $mkdir $FREENAS/lib/geom $cp /lib/geom/geom $cp /lib/geom
下载FreeNAS GUI 文件并拷贝他们到$FREENAS/usr/local/www 确保所有的.php文件有执行权限 chmod 755
$fetch http://www.freenas.org/downloads/freenas-gui.tgz $tar -zxvf freenas-gui.tgz -C $FREENAS
创建一个压缩的系统文件,它被用来运行在RAM disk上。其中为根文件系统,不包括引导程序。 首先下载并运行freenas-create-msfroot.sh脚本来创建一个用0填充的image文件。目前的大小为32MB。如果你添加了大的部件,需要提高其容量。
$fetch http://www.freenas.org/downloads/freenas-create-msfroot.sh $./freenas-create-msfroot.sh
它的内容为
#!/bin/sh
# Generate the mfs ROOT file system
#Setting directory
WORKINGDIR="/usr/local/freenas"
FREENAS="/usr/local/freenas/rootfs"
CDROOT="/usr/local/freenas/cdroot"
BOOTDIR="/usr/local/freenas/bootloader"
#lauching the script
# Remove old file
if [ $WORKINGDIR/mfsroot.gz ] ; then
echo ;
echo "mfsroot.gz already exists. Removing this file" ;
echo ;
rm $WORKINGDIR/mfsroot.gz;
#exit ;
fi ;
# umount the /mnt directory
umount /mnt
# Remove the memory file
mdconfig -d -u 0
# Create a 32Mb empty file
dd if=/dev/zero of=$WORKINGDIR/mfsroot bs=1k count=32768
# Configure this file as a virtual disk
mdconfig -a -t vnode -f $WORKINGDIR/mfsroot -u 0
# Create Label on this disk
bsdlabel -w md0 auto
# format it
newfs -b 8192 -f 1024 -o space -m 0 /dev/md0c
# Mount it
mount /dev/md0c /mnt
# Copy the file on it
cd /mnt
tar -cf - -C $FREENAS ./ | tar -xvpf -
cd $WORKINGDIR
# umount the /mnt directory
umount /mnt
# Remove the memory file
mdconfig -d -u 0
echo Compresing....
gzip -9 mfsroot
1 从系统中移走内存磁盘
$mdconf -d -u 4
释放/dev/md4使用的所有资源。 -d 从系统释放内存磁盘并释放所有的资源。 -u 指定一个md设备单元号,而不使用自动生成的。
2 挂载已经存在的映像文件
$mdconfig -a -t vnode -f diskimage -u 0
malloc: 使用malloc分配空间 vnode: 与之后的-f filename配合,用该文件保存内存磁盘内容 swap: 使用swap空间保存内存磁盘的内容 -dd 把指定的输入文件转换到输出文件,并可以进行格式转换。
<exmaple>$dd if=/dev/zero of=newimage bs=1k count=5k</example>
if:输入文件 of:输出文件 bs: 一次的读写字节数(缓冲区) count: 只拷贝输入的多少块(次),每次单位为bs字节
fdisk用来划分主分区(slice),它的操作对象是硬盘的第一个扇区(MBR),在MBR中写入标准引导程序(boot0),以及主分区的分区信息。
bsdlabel用来在主分区中划分逻辑分区,操作对象是硬盘中主分区的第一个扇区,用来写入boot1和boot2,以及位于该主分区中的逻辑分区的分区信息以及标识号。
$bsdlabel -B -w /dev/ad0s1 auto
-B 表示在该主分区ad0s1中写入该主分区的引导记录boot1,boot2。
$newfs -b 8192 -f 1024 -o space -m 0 /dev/md0c
md0c ,c为所有的分区
$tar -cf - -C $FREENAS ./ | tar -xvpf -
与创建mfsroot类似。使用freenas-create-image.sh 内容为mfsroot+引导程序
$fetch http://freenas.org/downloads/freenas-create-image.sh $./freenas-create-image.sh
下面是其内容
#!/bin/sh
# FreeNAS script for generating .img
# setting variables
FREENAS="/usr/local/freenas/rootfs"
WORKINGDIR="/usr/local/freenas"
CDROOT="/usr/local/freenas/imgroot"
BOOTDIR="/usr/local/freenas/bootloader"
PLATFORM="generic-pc"
VERSION=`cat $FREENAS/etc/version`
ISOFILENAME="FreeNAS-$PLATFORM-$VERSION.img"
# Remove old directory
if [ -d $CDROOT ] ; then
echo ;
echo "$CDROOT already exists. Removing this directory" ;
echo ;
echo ;
rm -rf $CDROOT;
#exit ;
fi ;
if [ $WORKINGDIR/$ISOFILENAME ] ; then
echo ;
echo "$ISOFILENAME already exists. Removing this directory" ;
echo ;
echo ;
rm $WORKINGDIR/$ISOFILENAME;
#exit ;
fi ;
echo $PLATFORM > $FREENAS/etc/platform
date > $FREENAS/etc/version.buildtime
$WORKINGDIR/freenas-create-mfsroot.sh
echo Generating $CDROOT folder
mkdir $CDROOT
#Creating a 16Mb empty file
dd if=/dev/zero of=image.bin bs=1k count=18432
#use this file as a virtual RAM disk
mdconfig -a -t vnode -f image.bin -u 0
#Create partition on this disk
fdisk -BI -b $BOOTDIR/mbr /dev/md0
#Create label on this disk
bsdlabel -B -w -b $BOOTDIR/boot /dev/md0 auto
bsdlabel md0 >/tmp/label.$$
bsdlabel md0 |
egrep unused |
sed "s/c:/a:/" |
sed "s/unused/4.2BSD/" >>/tmp/label.$$
bsdlabel -R -B md0 /tmp/label.$$
rm -f /tmp/label.$$
#Create filesystem on this disk
newfs -b 8192 -f 1024 -o space -m 0 /dev/md0a
#Mount this disk
mount /dev/md0a $CDROOT
cp $WORKINGDIR/mfsroot.gz $CDROOT
mkdir $CDROOT/boot
mkdir $CDROOT/boot/kernel $CDROOT/boot/defaults
mkdir $CDROOT/conf
cp $FREENAS/conf.default/config.xml $CDROOT/conf
cp $BOOTDIR/kernel/kernel.gz $CDROOT/boot/kernel
cp $BOOTDIR/boot $CDROOT/boot
cp $BOOTDIR/loader $CDROOT/boot
cp $BOOTDIR/loader.conf $CDROOT/boot
cp $BOOTDIR/loader.rc $CDROOT/boot
cp $BOOTDIR/loader.4th $CDROOT/boot
cp $BOOTDIR/support.4th $CDROOT/boot
cp $BOOTDIR/defaults/loader.conf $CDROOT/boot/defaults/
cp $BOOTDIR/device.hints $CDROOT/boot
umount $CDROOT
mdconfig -d -u 0
gzip -9 image.bin
mv image.bin.gz $ISOFILENAME
# Cleaning directory and temp file
if [ $WORKINGDIR/mfsroot.gz ] ; then
echo ;
echo "cleaning mfsroot.gz" ;
echo ;
rm $WORKINGDIR/mfsroot.gz
fi;
if [ -d $CDROOT ] ; then
echo ;
echo "cleaning $CDROOT by Removing this directory" ;
echo ;
echo ;
rm -rf $CDROOT;
fi;
在创建可引导CD之前,我们必须安装CDRTools
$cd /usr/ports/sysutils/cdrtools $make $make install
使用freenas-create-cd.sh
$fetch http://www.freenas.org/downloads/freenas-create-cd.sh $./freenas-create-cd.sh
脚本内容为
#!/bin/sh
# FreeNAS script for generating iso file
FREENAS="/usr/local/freenas/rootfs"
WORKINGDIR="/usr/local/freenas"
CDROOT="/usr/local/freenas/cdroot"
BOOTDIR="/usr/local/freenas/bootloader"
PLATFORM="generic-pc-cdrom"
VERSION=`cat $FREENAS/etc/version`
ISOFILENAME="FreeNAS-$VERSION.iso"
#remove old directory
if [ -d $CDROOT ] ; then
echo ;
echo "$CDROOT already exists. Removing this directory" ;
echo "before running this script." ;
echo ;
#echo "Exiting..." ;
echo ;
rm -rf $CDROOT;
#exit ;
fi ;
echo "$PLATFORM" > $FREENAS/etc/platform
date > $FREENAS/etc/version.buildtime
$WORKINGDIR/freenas-create-mfsroot.sh
rm $WORKINGDIR/$ISOFILENAME
echo Generating $CDROOT folder
mkdir $CDROOT
cp $WORKINGDIR/mfsroot.gz $CDROOT
mkdir $CDROOT/boot
mkdir $CDROOT/boot/kernel $CDROOT/boot/defaults
cp $BOOTDIR/kernel/kernel.gz $CDROOT/boot/kernel
cp $BOOTDIR/cdboot $CDROOT/boot
cp $BOOTDIR/loader $CDROOT/boot
cp $BOOTDIR/loader.conf $CDROOT/boot
cp $BOOTDIR/loader.rc $CDROOT/boot
cp $BOOTDIR/loader.4th $CDROOT/boot
cp $BOOTDIR/support.4th $CDROOT/boot
cp $BOOTDIR/defaults/loader.conf $CDROOT/boot/defaults/
cp $BOOTDIR/device.hints $CDROOT/boot
###### BEGIN: NEW RELEASE CHANGE ######
$WORKINGDIR/freenas-create-image.sh
cp $WORKINGDIR/FreeNAS-generic-pc-$VERSION.img $CDROOT/FreeNAS-generic-pc.gz
###### END: NEW RELEASE CHANGE ######
mkisofs -b "boot/cdboot" -no-emul-boot -A "FreeNAS CD-ROM image" -c "boot/boot.catalog" -d -r -publisher "freenas.org" -p "Olivier Cochard" -V "freenas_cd" -o "$ISOFILENAME" $CDROOT
if [ -d $CDROOT ] ; then
echo ;
echo "Cleaning directory" ;
echo ;
echo ;
rm -rf $CDROOT;
rm mfsroot.gz;
#exit ;
fi ;