add files
[leishi.git] / draft / en / note / freenas-development-manual-zh-0.68.org
blobd9ae4f72feda33ca40bba7c6c3c67cb0db73db38
1 * <lisp>(setq Title "FreeNAS0.68开发人员手册")</lisp>
2  - 作者: [[http://www.freenas.org][FreeNAS Projects Team]]
3  - 翻译,改编: [[stoneszone.net][石磊]]
4  - 版权: 转载请注明出处
6 <contents depth="4">
9 ** 1 安装FreeBSD
10 *** 1.1 安装
11   安装FreeBSD 6.2版本 
12   只需要分两个区,/ 和 swap。
13   创建一个新用户并加入wheel组。
14   启动SSHD服务。
16 *** 1.2 配置User 和 Shell 
17 **** 1.2.1 安装Bash Shell
18 <example>
19   $pkg_add -r bash  #(-r 表示使用远程下载:ftp)
20 </example>
22 **** 1.2.2 配置Bash 
23   $chpass username  #(更改用户的登录shell=/usr/local/bin/bash,chpass实际会修改/etc/passwd文件)
25   $cp .profile .bash_profile
27   在.bash_profile中加入
29 <example>
30   PS1="[\u@\h:\w]"
31   case `id -u` in 0)
32   PS1="${PS1}# ";; *)
33   PS1="${PS1}$ ";;
34   esac
35 </example>
38 *** 1.3 升级FreeBSD宿主系统源代码树
39 **** 1.3.1 安装CVSup
40   CVSup 用于从远程服务器主机上的主CVS仓库发布和升级源代码树的软件包。用户可以用其保持其源代码树更新。
42 <example>
43   $pkg_add -r cvsup-without-gui
44 </example>
46 **** 1.3.2 配置CVSup
47   CVSup的配置文件为/etc/supfile,可以参考/usr/share/examples/cvsup/下的模板文件撰写(具体参考FreeBSD用户手册 附录A)
49 <example>
50   $cp /usr/share/examples/cvsup/stable-supfile /etc/supfile
51   $cp /usr/share/examples/cvsup/ports-supfile /etc/ports-supfile
52 </example>
54   编辑/etc/supfile和/etc/ports-suppfile,寻找并更改下面,表示从那个站点下载
55   *default host=cvsup.fr.FreeBSD.org  
57 **** 1.3.3 更新源码
58   -g   :代表没有GUI
59   -L 2 :显示2级别的输出  
60 <example>
61   $cvsup -g -L 2 /etc/supfile
62   $cvsup -g -L 2 /etc/ports-supfile
63 </example>
65 *** 1.4 重新编译所有代码
66 **** 1.4.1 配置/etc/make.conf
67   安装完所有的FreeBSD的Patches,使用动态库重新编译所有的程序,来节约磁盘空间
68   编辑 /etc/make.conf 加入(可参考/usr/share/examples/etc/make.conf更改/etc/make.conf)
69   NO_SHARED=no
71 **** 1.4.2 编译所有
72 *****  1.4.2.1 编译安装内核
73 <example>
74   $cd /usr/src
75   $make -j4 buildworld  #在/usr/obj下建立一个全新的stable树,-j4表示并行编译4个程序
76   $make buildkernel     #建立新的stable缺省内核
77   $make installkernel   #安装内核
78   $reboot
79 </example>
81 ***** 1.4.2.2 编译安装根 
82   启动时使用单用户模式,给loader传入参数 boot -s
83 <example>
84   $fsck -p           #使用preen模式检测文件系统,仅仅修复一部分错误,遇到特殊错误会报错并退出
85   $mount -u /        #装载根分区。 -u 表示一个已经mount的磁盘状态应该改变
86   $mount -a -t ufs   #-a 表示mount /etc/fstab所有后面 -t 表示的ufs文件系统
87   $swapon -a         #打开交换分区。-a 表示使用所有 /etc/fstab中列出的swap,除了noauto
88   $adjkerntz -i      #保持cmos中的local和kernel中的UTC时间的offset,-i表示将 adjkerntz 加入启动和关闭中来自动运行,/etc/rc中会加入相应条目。
89   $mergemaster -p    #安装系统配置文件的脚本工具,建立一个临时的根环境,把新的配置文件映射到这个环境
90   $cd /usr/src
91   $make installworld #安装新的stable程序树 
92   $make delete-old   #
93   $mergemaster       #更新/etc配置文件,需要与用户交互,如果是新安装的系统,则直接更新
94   $reboot
95   $make delete-old-libs
96 </example>
98 ***** 1.4.2.3 升级port
99 <example>
100   $pkg_add -r perl
101   $cd /usr/ports
102   $make index
103   $pkg_add -r portupgrade  #安装portupgrade工具,来简化port升级过程
104   $portversion -l "<"      #显示需要升级的port
105   $portupgrade -arR        #开始升级port,-a升级所有已安装且过时的程序 -r按照依赖关系递归的升级 -R按照需要关系递归的升级
106 </example>  
108 ** 2 安装FreeNAS
109   安装FreeNAS需要的工具和PHP脚本,如果指令不是很清楚,下载FreeNAS的根文件系统.tgz文件并与你安装的相比较来进行分析。
110   
111 *** 2.1 定义系统环境变量
112 <example>
113    $export WORKINGDIR="/usr/local/freenas"
114    $export FREENAS="/usr/local/freenas/rootfs"
115    $export BOOTDIR="/usr/local/freenas/bootloader"  #引导程序
116    $export CDROOT="/usr/local/freenas/cdroot"       #生成最终cd iso文件的目录
117 </example>
119 *** 2.2 创建根文件系统
121 **** 2.2.1 创建工作目录
122   $mkdir /usr/local/freenas
124 **** 2.2.2 生成最小root文件系统
125   下载freenas-create-dir.sh,其内容为: 
127 <example>
128   #!/bin/sh
129   #
130   # This script was written by David Courtney of Ultradesic
131   # http://www.ultradesic.com
132   # E-Mail Contact: minibsd@ultradesic.com
133   #
134   # Adapted for FreeNAS by Olivier Cochard-Labbé (http://www.freenas.org)
135   # Modified by Volker Theile (votdev@gmx.de)
137   MINIBSD_DIR=/usr/local/freenas/rootfs;
139   # Initialize variables.
140   opt_f=0
142   # Parse the command-line options.
143   while getopts 'fh' option
144   do
145     case "$option" in
146     "f")  opt_f=1;;
147     "h")  echo "$(basename $0): Create FreeNAS directory structure";
148           echo "Common Options:";
149           echo "  -f    Force executing this script";
150           exit 1;;
151      ?)    echo "$0: Bad option specified. Exiting...";
152           exit 1;;
153     esac
154   done
156   shift `expr $OPTIND - 1`
158   echo "Create FreeNAS directory structure..."
160   if [ ! -z "$1" ]; then
161      MINIBSD_DIR=$1;
162      echo "Using directory $1.";
163   fi
165   if [ 1 != $opt_f -a -d "$MINIBSD_DIR" ]; then
166      echo ;
167      echo "$MINIBSD_DIR already exists. Remove the directory" ;
168      echo "before running this script." ;
169      echo ;
170      echo "Exiting..." ;
171      echo ;
172      exit 1 ;
173    fi ;
175    mkdir $MINIBSD_DIR ;
176    cd $MINIBSD_DIR ;
178    # Create directories
179    mkdir boot ;           # fdisk 和bsdlabel使用
180    mkdir boot/kernel ;    # 保存kernel 模块
181    mkdir bin ;
182    mkdir cf ;             # 用于挂载Compact Flash card , Hard disk ..
183    mkdir ftmp ;           # 用于通过WebGUI进行防火墙升级时挂载临时的内存文件系统
184    mkdir conf.default ;   # 保存出厂时的默认配置文件config.xml
185    mkdir dev ;
186    mkdir etc ;
187    mkdir etc/defaults ;
188    mkdir etc/inc ;        # 保存boot脚本和WebGUI所需要的php include文件
189    mkdir etc/pam.d ;
190    mkdir etc/ssh ;
191    mkdir etc/iscsi ;
192    mkdir lib ;
193    mkdir lib/geom ;
194    mkdir libexec ;
195    mkdir -m 0777 mnt ;
196    mkdir -m 0700 root ;
197    mkdir sbin ;
198    mkdir usr ;
199    mkdir usr/bin ;
200    mkdir usr/lib ;
201    mkdir usr/lib/aout ;
202    mkdir usr/libexec ;
203    mkdir usr/local ;
204    mkdir usr/local/bin;
205    mkdir usr/local/lib ;
206    mkdir usr/local/sbin ;
207    mkdir usr/local/share ;
208    mkdir usr/local/share/locale ;
209    mkdir usr/local/etc ;
210    mkdir usr/local/www ;           # WebGUI文件
211    mkdir usr/local/www/syntaxhighlighter ;
212    mkdir usr/sbin ;
213    mkdir usr/share ;
214    mkdir usr/share/misc ;
215    mkdir usr/share/locale ;
216    mkdir tmp ;
217    mkdir var ;
219    # Creating symbolic links. Most of the target files will be created at runtime.
220    # 大多数的连接目标文件在FreeNAS运行时生成
221    ln -s cf/conf conf
222    ln -s /var/run/htpasswd usr/local/www/.htpasswd   #在webGUI运行时用户配置的user/passwd会保存在/var/run/htpasswd中
223    ln -s /var/etc/resolv.conf etc/resolv.conf
224    ln -s /var/etc/master.passwd etc/master.passwd
225    ln -s /var/etc/passwd etc/passwd
226    ln -s /var/etc/group etc/group
227    ln -s /var/etc/hosts etc/hosts
228    ln -s /var/etc/pwd.db etc/pwd.db
229    ln -s /var/etc/spwd.db etc/spwd.db
230    ln -s /var/etc/crontab etc/crontab
231    ln -s /var/etc/ssh/sshd_config etc/ssh/sshd_config
232    ln -s /var/etc/ssh/ssh_host_dsa_key etc/ssh/ssh_host_dsa_key
233    ln -s /var/etc/iscsi/targets etc/iscsi/targets
234    ln -s /var/etc/pam.d/ftp etc/pam.d/ftp
235    ln -s /var/etc/pam.d/ftp etc/pam.d/pure-ftpd
236    ln -s /var/etc/pam.d/sshd etc/pam.d/sshd
237    ln -s /var/etc/pam.d/login etc/pam.d/login
238    ln -s /var/etc/pam.d/system etc/pam.d/system
239    ln -s /var/etc/ldap.conf usr/local/etc/ldap.conf
240    ln -s /var/etc/nsswitch.conf etc/nsswitch.conf
241    ln -s /libexec/ld-elf.so.1 usr/libexec/ld-elf.so.1
242 </example>
244 *** 2.3 拷贝需要的二进制文件
246 下载 freenas.files 和 mkmini.pl
247  - freenas.files 包含所有的Freenas需要的二进制文件
248  - mkmini.pl     为perl文件,
250 运行的命令
251 <example>
252   $pkg_add -r perl
253   $perl mkmini.pl freenas.files / $FREENAS
254 </example>
256 freenas.files文件内容为
257 <example>
258 # freenas.files
259 # List of files required for a the FreeNAS,
260 # intended to be parsed by mkmini.pl (script created by Manuel Kasper <mk@neon1.net>)
262 # Lines with colons (':') in them list files that should be hard-linked
263 # to each other, e.g.
264 #     bin/link:bin/ln
265 # instructs mkmini.pl to copy over bin/link, then hard link ln to it.
267 ####### contents of /bin
269 ## Test: condition evaluation utility
270 bin/[:bin/test
272 ##  cat -- concatenate and print files
273 bin/cat
275 ## chmod -- change file modes
276 bin/chmod
278 ## cp -- copy files
279 bin/cp
281 ## tcsh - C shell with file name completion and command line editing
282 bin/csh:bin/tcsh
284 ## date -- display or set date and time
285 bin/date
287 ## dd -- convert and copy a file
288 bin/dd
290 ##  df -- display free disk space
291 bin/df
293 ## echo -- write arguments to the standard output
294 bin/echo
296 ##  expr -- evaluate expression
297 bin/expr
299 ##  hostname -- set or print name of current host system
300 bin/hostname
302 ## kill -- terminate or signal a process
303 bin/kill
305 ## ln, link -- make links
306 bin/link:bin/ln
308 ## ls -- list directory contents
309 bin/ls
311 ##  mkdir -- make directories
312 bin/mkdir
314 ##  mv -- move files
315 bin/mv
317 ## pax -- read and write file archives and copy directory hierarchies
318 #bin/pax
320 ##ps -- process status
321 bin/ps
323 ##pwd -- return working directory name
324 #Prevent WinSCP to Generate Error message
325 bin/pwd:bin/realpath
327 ## rm, unlink -- remove directory entries
328 bin/rm:bin/unlink
330 ##sh -- command interpreter (shell)
331 bin/sh
333 ## sleep -- suspend execution for an interval of time
334 bin/sleep
336 ## stty -- set the options for a terminal device interface
337 bin/stty
339 ## sync -- force completion of pending disk writes (flush cache)
340 bin/sync
343 ####### contents of /sbin
344 # adjkerntz -- adjust local time CMOS clock to reflect time zone changes and keep current timezone offset for the kernel
345 sbin/adjkerntz
347 ## bsdlabel -- read and write disk pack label
348 sbin/bsdlabel
350 ##devfs -- DEVFS control (NEW from FreeBSD 5.2, replace the )
351 sbin/devfs
353 ## dhclient -- Dynamic Host Configuration Protocol (DHCP) client
354 sbin/dhclient
356 ## dhclient-script -- DHCP client network configuration script
357 sbin/dhclient-script
359 ## dmesg -- display the system message buffer
360 sbin/dmesg
362 ## reboot, halt, fastboot, fasthalt -- stopping and restarting the system
363 sbin/fastboot:sbin/fasthalt:sbin/halt:sbin/reboot
365 ##  fdisk -- PC slice table maintenance utility
366 sbin/fdisk
368 ## fsck -- file system consistency check and interactive repair
369 sbin/fsck
371 ## fsck -- UFS,FFS 4.2BSD file system consistency check and interactive repair
372 sbin/fsck_ufs:sbin/fsck_ffs:sbin/fsck_4.2bsd
374 ## fsck -- DOS/WINDOWS file system consistency check and interactive repair
375 sbin/fsck_msdosfs
377 ## Gconcat -- Geom concat
378 sbin/gconcat
380 # Growfs -- grow size of an existing ufs file system
381 sbin/growfs
383 ## gstripe -- Geom stripe
384 sbin/gstripe
386 ## gmirror -- Geom mirror
387 sbin/gmirror
389 # geli -- Control utility for cryptographic GEOM class
390 sbin/geli
392 ## gpt -- Manipulate GUID partition tables
393 sbin/gpt
395 ## gvinum -- Volume manager (RAID0,1,5)
396 sbin/gvinum
398 ## ifconfig -- configure network interface parameters
399 sbin/ifconfig
401 ## init -- process control initialization
402 sbin/init
404 ## kldload -- load a file into the kernel
405 sbin/kldload
407 ## kldstat -- display status of dynamic kernel linker
408 sbin/kldstat
410 ## kldunload -- unload a file from the kernel
411 sbin/kldunload
413 ## ldconfig -- configure the shared library cache
414 sbin/ldconfig
416 # mdconfig -- configure and enable memory disks
417 sbin/mdconfig
419 ## mknod -- build special file
420 sbin/mknod
422 ## mount -- mount file systems
423 sbin/mount
425 ## mount_std, mount_devfs, mount_fdescfs, mount_linprocfs, mount_procfs -- mount ``standard'' file systems
426 sbin/mount_devfs:sbin/mount_fdescfs:sbin/mount_linprocfs:sbin/mount_procfs:sbin/mount_std:
428 ## mdmfs, mount_mfs -- configure and mount an in-memory file system using the md(4) driver
429 sbin/mdmfs
431 ## mount_nullfs -- mount a loopback file system sub-tree; demonstrate the use of a null file system layer
432 sbin/mount_nullfs
434 ## mount_umapfs -- sample file system layer
435 sbin/mount_umapfs
437 ## mount_unionfs -- mount union file systems
438 sbin/mount_unionfs
440 ## mount_msdosfs -- mount MS-DOS file system
441 sbin/mount_msdosfs
443 ## mount_nfs -- mount NFS file system
444 sbin/mount_nfs
446 ## mount_nfs4 -- mount NFSv4 file system
447 sbin/mount_nfs4
449 ## mount_ntfs -- mount NTFS file system: Replaced by NTFS-3G
450 #sbin/mount_ntfs
452 ## mount_ext2fs -- mount ext2fs file system
453 sbin/mount_ext2fs
455 ## mount_cd9660 -- mount CDROM file system
456 sbin/mount_cd9660
458 ## mount_reiserfs -- mount ReiserFS file system
459 sbin/mount_reiserfs
461 ## mount_udf -- mount UDF file system
462 sbin/mount_udf
464 ## natd -- Network Address Translation daemon
465 #sbin/natd
467 ## newsfs -- construct a new UFS1/UFS2 file system
468 sbin/newfs
470 ## newsfs -- construct a FAT (16/32) file system
471 sbin/newfs_msdos
473 ##nologin -- politely refuse a login
474 sbin/nologin
476 ## ping -- send ICMP ECHO_REQUEST packets to network hosts
477 sbin/ping
479 ## route -- manually manipulate the routing tables
480 sbin/route
482 ##  shutdown -- close down the system at a given time
483 sbin/shutdown
485 ##sysctl -- get or set kernel state
486 sbin/sysctl
488 ## swapon - Enable swap
489 sbin/swapon
491 ## swapoff - Disable swap
492 sbin/swapoff
494 ##tunefs -- tune up an existing file system
495 sbin/tunefs
497 ## umount -- unmount file systems
498 sbin/umount
500 # atacontrol: manage IDE disk
501 sbin/atacontrol
503 # camcontrol: manage SCSI disk
504 sbin/camcontrol
506 ####### contents of /usr/bin
507 # chgrp: change group
508 usr/bin/chgrp
510 # fstat -- identify active files . Fuse mount use fstat
511 usr/bin/fstat
513 ## FTP/HTTP download tools
514 usr/bin/fetch
516 ## This utility prevent WinSCP to display error message
517 usr/bin/groups
519 ## gzip, gunzip, zcat - compress or expand files
520 usr/bin/gzip:usr/bin/gunzip
522 ## id - displays the user and group names and numeric IDs, of the calling process
523 usr/bin/id
525 ## killall -- kill processes by name
526 usr/bin/killall
528 ## logger -- make entries in the system log
529 usr/bin/logger
531 ##  netstat -- show network status
532 usr/bin/netstat
534 ## nohup -- invoke a utility immune to hangups
535 usr/bin/nohup
537 ## passwd -- Change user passwd
538 usr/bin/passwd
540 ## su -- substitute user identity
541 usr/bin/su
543 ##scp -- secure copy (remote file copy program)
544 usr/bin/scp
546 ##ssh -- secure Shell Client (used for RSYNC and Unison over SSH)
547 # FreeNAS use the port openssh-portable with HPN-SSH patch enabled
548 # usr/bin/ssh
550 ## tail -- display the last part of a file
551 usr/bin/tail
553 ## tar -- manipulate tape archives
554 usr/bin/tar
556 ## top - display and update information about the top cpu processes
557 usr/bin/top
559 ## touch -- create/change file access and modification times
560 usr/bin/touch
562 ## uptime -- show how long system has been running
563 usr/bin/uptime:usr/bin/w
566 ####### contents of /usr/sbin
567 ##  ancontrol -- configure Aironet 4500/4800 devices
568 usr/sbin/ancontrol
570 ## arp -- address resolution display and control
571 usr/sbin/arp
573 #boot0cfg -- boot manager installation/configuration utility
574 usr/sbin/boot0cfg
576 ## chown -- change file owner and group
577 usr/sbin/chown
579 ##chroot -- change root directory
580 usr/sbin/chroot
582 ## cron - The scheduler
583 usr/sbin/cron
585 ## powerd -- System power control utility
586 usr/sbin/powerd
588 ## pwd_mkdb -- generate the password databases
589 usr/sbin/pwd_mkdb
591 ## swapinfo - Give info on the swap disk
592 usr/sbin/swapinfo
594 ##  traceroute - print the route packets take to network host
595 usr/sbin/traceroute
597 # wicontrol -- configure Lucent, Intersil, and Atheros wireless devices
598 usr/sbin/wicontrol
600 # NFS server tools
601 usr/sbin/mountd
602 usr/sbin/nfsd
603 usr/sbin/rpcbind
604 usr/sbin/rpc.lockd
605 usr/sbin/rpc.statd
607 # sshd - Daemon program for ssh
608 # FreeNAS use the port openssh-portable with HPN-SSH patch enabled
609 #usr/sbin/sshd
611 ####### contents of /usr/libexec
612 # ld-elf.so.1, ld.so, rtld -- run-time link-editor
613 libexec/ld-elf.so.1:usr/libexec/ld-elf.so.1
615 # sft-server
616 # FreeNAS use the port openssh-portable with HPN-SSH patch enabled
617 #usr/libexec/sftp-server
619 ####### contents of /usr/share/misc
620 usr/share/misc/termcap
622 ####### contents of /usr/share/locale
623 usr/share/locale/en_US.ISO8859-1/*
624 usr/share/locale/en_US.UTF-8/*
625 usr/share/locale/la_LN.US-ASCII/*
626 usr/share/locale/UTF-8/*
628 ####### contents of /usr/local/bin
629 # nano - a small, free and friendly editor: IT's a port!!!
630 #usr/local/bin/nano
632 ####### contents of /usr/lib
633 # PAM libraries
634 usr/lib/pam_*.so.3
636 ####### contents of /lib/geom
637 # GEOM tools
638 lib/geom/*
640 ####### contents of /etc/ssh
641 # moduli -- system moduli file
642 etc/ssh/moduli
644 </example>
647 *** 2.4 准备/etc 
648 **** 2.4.1 安装etc和PHP配置脚本
649  下载freenas-etc.tgz 并解压缩至$FREENAS/目录
650 <example>
651   $fetch http://www.freenas.org/downloads/freenas-etc.tgz
652   $tar -xzf freenas-etc.tgz -C $FREENAS/
653 </example> 
654  并且确保/etc/rc下的rc.*文件有执行权限 chmod 755
656 **** 2.4.2 其他注意事项 (自己写,未验证)
657   在主机生成$FREENAS/etc/master.passwd并拷贝至$FREENAS/etc/,通过下列命令生成newpasssword数据库(pwd.db和spwd.db) -p表示重新生成/etc/passwd
658 <example> 
659   $pwd_mkdb -p -d $FREENAS/etc $FREENAS/etc/master.passwd
660   $tar cfvz freenas-tgz $FRRRNAS/etc/*   #为了节省空间,???
661 </example>
663 **** 2.4.3 配置平台变量
664  /etc/platform文件非常重要,它标识出image是由什么系统生成的,php脚本使用它确定配置存储在何处以及webGUI中应该显示出的option。可以设置为以下值:
665  - generic-pc
666  - generic-pc-cdrom
667 <example>
668   $echo "0.67b" > $FREENAS/etc/version
669   $date > $FREENAS/etc/version.buildtime
670   $echo "generic-pc-cdrom">$FREENAS/etc/platform
671 </example>
673 **** 2.4.4 配置 config.xml
674  下载最新的默认配置文件http://www.freenas.org/downloads/config.xml 
675  拷贝至$FREENAS/conf.defalut/config.xml
676 <example>
677   $cd $FREENAS/conf.default/
678   $fetch http://www.freenasw.org/downloads/config.xml 
679 </example>
681 **** 2.4.5 时区Zone 信息
682   FreeNAS将时区信息保存在/usr/share/zoneinfo中,为了保存空间,m0n0wall使用一个stripped down的版本,并将其打包tar...
683 <example>
684   $cd $FREENAS/usr/share
685   $fetch http://www.freenas.org/downloads/zoneinfo.tgz
686 </example>
688 *** 2.5 编译内核
689 *** 2.5.1 添加A100U2 U2W-SCSI-Controller驱动程序
690 <example>
691   $mkdir a100
692   $cd a100
693   $fetch http://www.freenas.org/downloads/bsd4a100.zip 
694   $gunzip bsd4a100.zip
695   $cp a100.* /usr/src/sys/pci
696   $echo "pci/a100.c optional ihb device-driver" >> /usr/src/sys/conf/files
697 </example> 
699 *** 2.5.2 编译并压缩内核
700   下载FreeNAS的内核配置文件
701 <example>
702   $cd /sys/i386/conf/
703   $fetch http://www.freenas.org/downloads/FREENAS 
704 </example>
705   编译内核和模块
706 <example>
707   $config FREENAS                #config 命令产生内核源代码,并命名为FREENAS 
708   $cd ../compile/FREENAS/        #进入编译目录
709   $make cleandepend;make depend  #编译
710   $make
711   $gzip -9 kernel                #压缩编译出的内核
712 </example>
714 *** 2.5.3 安装模块
715 <example>
716   $cp /sys/i386/compile/FREENAS/modules/usr/src/sys/modules/geom/geom_vinum/geom_vinum.ko $FREENAS/boot/kernel
717   $cp /sys/i386/compile/FREENAS/modules/usr/src/sys/modules/geom/geom_stripe/geom_stripe.ko $FREENAS/boot/kernel
718   $cp /sys/i386/compile/FREENAS/modules/usr/src/sys/modules/geom/geom_concat/geom_concat.ko $FREENAS/boot/kernel
719   $cp /sys/i386/compile/FREENAS/modules/usr/src/sys/modules/geom/geom_mirror/geom_mirror.ko $FREENAS/boot/kernel
720   $cp /sys/i386/compile/FREENAS/modules/usr/src/sys/modules/geom/geom_gpt/geom_gpt.ko $FREENAS/boot/kernel
721   ####$cp /sys/i386/compile/FREENAS_GENERIC/modules/usr/src/sys/modules/ntfs/ntfs.ko $FREENAS/boot/kernel
722   $cp /sys/i386/compile/FREENAS/modules/usr/src/sys/modules/ext2fs/ext2fs.ko $FREENAS/boot/kernel/
723 </example>
725 *** 2.5.4 添加试验版本的geom RAID 5模块
726 <example>
727   $cd /usr/src
728   $fetch http://home.tiscali.de/cmdr_faako/geom_raid5.tbz
729   $tar zxvf geom_raid5.tbz
730   $cd /usr/src/sys/modules/geom/geom_raid5/
731   $make depend
732   $make
733   $cp geom_raid5.ko $FREENAS/boot/kernel/
734   $cd /usr/src/sbin/geom/class/raid5/
735   $mkdir /usr/include/geom/raid5
736   $cp /usr/src/sys/geom/raid5/g_raid5.h /usr/include/geom/raid5/
737   $make depend
738   $make
739   $make install
740   $cp -p /sbin/graid5 $FREENAS/sbin/
741   $mkdir $FREENAS/lib/geom/
742   $cp geom_raid5.so $FREENAS/lib/geom/
743 </example>
745 *** 2.5.6 安装mbr
746   mbr为fdisk用来创建可启动磁盘
747 <example>
748   $cp /boot/mbr $FREENAS/boot/
749 </example>
751 *** 2.6 安装软件包
752 *** 2.6.1 PHP5
753 **** 2.6.1.1  安装 libxml2
754 <example>
755   $pkg_add -r libxml2
756 </example>
757 **** 2.6.1.2  下载并解压PHP5.2 http://www.php.net 
758 <example>
759   $./configure --enable-fastcgi --enable-discard-path --enable-force-cgi-redirect --without-mysql --without-pear --with-openssl --without-sqlite --with-pcre-regex
760   $make
761   $install -s sapi/cgi/php $FREENAS/usr/local/bin
762 </example>
764 **** 3.6.1.3 写配置文件$FREENAS/usr/local/lib/php.ini
765 <example>
766 magic_quotes_gpc = Off
767 magic_quotes_runtime = Off
768 max_execution_time = 0
769 max_input_time = 180
770 register_argc_argv = Off
771 file_uploads = On
772 upload_tmp_dir = /ftmp
773 upload_max_filesize = 256M
774 post_max_size = 256M
775 html_errors = Off
776 include_path = ".:/etc/inc:/usr/local/www"
777 </example>
779 *** 2.6.2 Lighthttpd
780 <example>
781   $fetch http://www.lighttpd.net/download/lighttpd-1.4.13.tar.gz
782   $tar zxvf lighttpd-1.4.13.tar.gz
783   $cd lighttpd-1.4.13
784   $./configure --sysconfdir=/var/etc/ --enable-lfs --without-mysql --without-ldap --with-openssl --without-lua --with-bzip2 --without-pam
785   $make
786   $install -s src/lighttpd $FREENAS/usr/local/sbin
787   $mkdir $FREENAS/usr/local/bin/lighttpd
788   $cp src/.libs/mod_indexfile.so $FREENAS/usr/local/lib/lighttpd/
789   $cp src/.libs/mod_access.so $FREENAS/usr/local/lib/lighttpd/
790   $cp src/.libs/mod_accesslog.so $FREENAS/usr/local/lib/lighttpd/
791   $cp src/.libs/mod_dirlisting.so $FREENAS/usr/local/lib/lighttpd/
792   $cp src/.libs/mod_staticfile.so $FREENAS/usr/local/lib/lighttpd/
793   $cp src/.libs/mod_cgi.so $FREENAS/usr/local/lib/lighttpd/
794   $cp src/.libs/mod_auth.so $FREENAS/usr/local/lib/lighttpd/
795   $cp src/.libs/mod_webdav.so $FREENAS/usr/local/lib/lighttpd/
796 </example>
797   
799 *** 2.6.3 clog
800   clog程序记录所有到子网的连接。它使用pcap 库。
801 <example>
802   $fetch http://www.freenas.org/downloads/clog-1.0.1.tar.gz
803   $fetch http://www.freenas.org/downloads/syslogd_clog-current.tgz
804   $tar zxvf clog-1.0.1.tar.gz
805   $tar zxvf syslogd_clog-current.tgz
806   $cd syslogd
807   $make
808   $install -s syslogd $FREENAS/usr/sbin/
809   $cd ../clog
810   $gcc clog.c -o clog
811   $install -s clog $FREENAS/usr/sbin/
812 </example>
814 *** 2.6.4 MSNTP
815   MSNTP为SNTP客户端,与NTP和SNTP服务器通讯显示和设置本地系统时间。可运行于交互模式,cron,或者daemon。
816 <example>
817   $cd /usr/ports/net/msntp/
818   $make
819   $install -s work/msntp-1.6/msntp $FREENAS/usr/local/bin/
820 </example>
822   配置$FREENAS/usr/local/bin/runmsntp.sh并更改为可执行权限。
823 <example>
824   #!/bin/sh
825   
826   # write our PID to file
827   echo $$ > $1
829   # execute msntp in endless loop; restart if it
830   # exits (wait 1 second to avoid restarting too fast in case
831   # the network is not yet setup)
832   while true; do
833         /usr/local/bin/msntp -r -P no -l $2 -x $3 $4
834         sleep 1
835   done
836 </example>
838 *** 2.6.5 ataidle
839   ataid处理ata协议硬盘在空闲时间放低转速。
840 <example>
841   $cd /usr/ports/sysutils/ataidle
842   $make
843   $install -s work/ataidle-0.9/ataidle $FREENAS/usr/local/sbin/
844 </example>
846 *** 2.6.6 iscsi initiator
847 <example>
848   $fetch ftp://ftp.cs.huji.ac.il/users/danny/freebsd/iscsi-2.0.1.tar.bz2
849   $tar zxvf iscsi-2.0.1.tar.bz2
850   $cd sys
851   $ln -s /sys/kern .
852   $ln -s /sys/tools .
853   $cd modules/iscsi_initiator
854   $make clean
855   $ln -s ../.. @
856   $make
857   $cp iscsi_initiator.ko $FREENAS/boot/kernel/
858   $cd ../../../iscontrol/
859   $make
860   $install -s iscontrol $FREENAS/usr/local/sbin/
861 </example>
863 *** 2.6.7 Pure-FTPd
864 <example>
865   $cd /root
866   $fetch http://download.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.0.21.tar.gz
867   $tar zxvf pure-ftpd-1.0.21.tar.gz
868   $cd pure-ftpd-1.0.21
869   $./configure --with-rfc2640 --with-largefile --with-pam
870   $make
871   $install -s src/pure-ftpd $FREENAS/usr/local/sbin/
872 </example>
874 *** 2.6.8 samba (CIFS server)
875 <example>
876 fetch http://us2.samba.org/samba/ftp/samba-latest.tar.gz
878 tar zxvf samba-latest.tar.gz
880 cd samba-3.0.23d/source/
882 ./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
884 make
886 install samba:
888 install -s bin/smbd $FREENAS/usr/local/sbin/
890 install -s bin/nmbd $FREENAS/usr/local/sbin/
892 install -s bin/winbindd $FREENAS/usr/local/sbin/
894 install -s bin/smbpasswd $FREENAS/usr/local/bin/
896 install -s bin/net $FREENAS/usr/local/bin/
898 install -s nsswitch/nss_winbind.so $FREENAS/usr/local/lib/
900 install -s nsswitch/nss_wins.so $FREENAS/usr/local/lib/
902 install -s bin/pam_winbind.so $FREENAS/usr/local/lib/
904 ln -s $FREENAS/usr/local/lib/nss_winbind.so $FREENAS/usr/local/lib/nss_winbind.so.1
906 mkdir $FREENAS/usr/local/samba/lib/idmap
908 mkdir $FREENAS/usr/local/samba/lib/vfs
910 install -s bin/rid.so $FREENAS/usr/local/samba/lib/idmap
912 mkdir $FREENAS/usr/local/lib/samba
914 mkdir $FREENAS/usr/local/lib/samba/charset
916 mkdir $FREENAS/usr/local/lib/samba/rpc
918 mkdir $FREENAS/usr/local/lib/samba/pdb
920 cp bin/CP*.so $FREENAS/usr/local/lib/samba/charset
922 cp codepages/*.dat $FREENAS/usr/local/lib/samba/
924 cp po/*.* $FREENAS/usr/local/lib/samba/
926 cp bin/recycle.so $FREENAS/usr/local/samba/lib/vfs
927 </example>
929 *** 2.6.9 NFS
930 <example>
931   $cp /usr/sbin/nfsd $FREENAS/usr/sbin
932   $cp /usr/sbin/mountd $FREENAS/usr/sbin
933   $cp /usr/sbin/rpcbind $FREENAS/usr/sbin
934 </example>
936 *** 2.6.10 Netatalk
937   Netatalk使用AppleTalk协议,为Apple电脑提供文件服务。
939 **** 2.6.10.1 安装Database Berkeley  port
940 <example>
941   $cd /usr/ports/databases/db42
942   $make 
943   $make install
944 </example>
946 **** 2.6.10.2 安装
947 <example>
948 fetch http://ovh.dl.sourceforge.net/sourceforge/netatalk/netatalk-2.0.3.tar.gz
950 tar zxvf netatalk-2.0.3.tar.gz
952 cd netatalk-2.0.3
954 ./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/
956 install -s etc/afpd/afpd $FREENAS/usr/local/sbin/
958 mkdir $FREENAS/etc/uams
960 cp etc/uams/.libs/uams_passwd.so $FREENAS/etc/uams
962 cp etc/uams/.libs/uams_dhx_passwd.so $FREENAS/etc/uams
964 cp etc/uams/.libs/uams_guest.so $FREENAS/etc/uams
966 cp etc/uams/.libs/uams_randnum.so $FREENAS/etc/uams
968 cd $FREENAS/etc/uams
970 ln -s uams_passwd.so uams_clrtxt.so
972 ln -s uams_dhx_passwd.so uams_dhx.so
974 cd $FREENAS/usr/local/lib/
976 cp /usr/local/lib/libdb-4.2.so.2 .
978 cd $FREENAS/usr/lib/
980 cp /usr/lib/librpcsvc.so.3 .
981 </example>
983 *** 2.6.11 RSYNC
984   RSYNC数据镜像和备份工具。本地/远程,目录之间进行快速同步镜像,远程数据备份等。仅仅更新变动部分。
985 <example>
986   $fetch http://samba.anu.edu.au/ftp/rsync/rsync-2.6.9.tar.gz
987   $tar zxvf rsync-2.6.9.tar.gz
988   $cd rsync-2.6.9
989   $./configure --with-rsyncd-conf=/var/etc
990   $make
991   $install -s rsync $FREENAS/usr/local/bin/
992 </example>
994 *** 2.6.12 Unison
995   Unison 目录文件同步工具,与rsync不同为,它同步是双向的。
996 <example>
997   $cd /usr/ports/net/unison/
998   $make
999   $cp work/unison-2.13.16/unison $FREENAS/usr/local/bin/
1000 </example>
1002 *** 2.6.13 scponly
1003   为采用ssh加密的sftp提供一个安全的chroot环境,它可以生成一个scponlyc的shell,只能运行scp / sftp等命令,且于rsync,svn,gftp兼容。
1005 <example>
1006   $cd /usr/ports/shells/scponly/
1007 </example>
1008   编辑Makefile
1009 <example>
1010 WITH_SCPONLY_RSYNC=YES
1012 WITH_SCPONLY_SCP=YES
1014 WITH_SCPONLY_WINSCP=YES
1016 WITH_SCPONLY_UNISON=YES
1018 WITH_SCPONLY_SFTP_LOGGING=YES
1019 </example>
1021   编译
1022 <example>
1023   $make
1024   $install -s work/scponly-4.4/scponly $FREENAS/usr/local/bin/
1025 </example>
1027 *** 2.6.14 openssh-portable with HPN patch
1028   启动sshd,sftpd服务
1029   编辑/usr/ports/security/openssh-portable/Makefile
1030 <example>
1031 HPN "Enable HPN-SSH patch" on \
1032 </example>
1033   编译
1034 <example>
1035   $make
1036   $install -vs work/openssh-4.5p1/sshd $FREENAS/usr/sbin/
1037   $install -vs work/openssh-4.5p1/sftp-server $FREENAS/usr/libexec/
1038 </example>
1040 *** 2.6.15 ntfs-3g
1041 <example>
1042 cd /usr/ports/sysutils/fusefs-kmod
1044 make
1046 cp -pv work/fuse4bsd-*/mount_fusefs/mount_fusefs $FREENAS/usr/local/sbin/
1048 cp -pv work/fuse4bsd-*/fuse_module/fuse.ko $FREENAS/boot/kernel
1050 cd /usr/ports/sysutils/fusefs-ntfs/
1052 make
1054 cp -p work/ntfs-3g-0.20070118-BETA/libntfs-3g/.libs/libntfs-3g.so $FREENAS/usr/local/lib/libntfs-3g.so.0
1056 install -s work/ntfs-3g-0.20070118-BETA/src/.libs/ntfs-3g $FREENAS/usr/local/bin/
1058 install -s /usr/local/lib/libfuse.so.2 $FREENAS/usr/local/lib/
1059 </example>
1061 *** 2.6.16 e2fsck
1062 <example>
1063   $cd /usr/ports/sysutils/e2fsprogs/
1064   $make
1065   $install -s work/e2fsprogs-1.39/e2fsck/e2fsck $FREENAS/usr/local/sbin/
1066 </example>
1068 *** 2.6.17 SMART
1069 <example>
1070   $cd /usr/ports/sysutils/smartmontools/
1071   $make
1072   $install -s work/smartmontools-5.37/smartctl $FREENAS/usr/local/sbin/
1073   $install -s work/smartmontools-5.37/smartd $FREENAS/usr/local/sbin/
1074 </example>
1076 *** 2.6.18 aaccli
1077   Adaptec SCSI RAID 管理工具,可以用来监控RAID卡状态。
1078 <example>
1079   $cd /usr/ports/sysutils/aaccli/ 
1080   $make
1081   $tar zxvf work/aaccli-1.0_0.tgz
1082   $cp work/bin/aaccli $FREENAS/usr/local/bin/
1083 </example>
1085 *** 2.6.19 beep
1086 <example>
1087   $cd /usr/ports/audio/beep
1088   $make
1089   $install -s work/beep/beep $FREENAS/usr/local/bin/
1090 </example>
1092 *** 2.6.20 mDNSReponder (Apple bonjour)
1093   一种apple的无须配置的网络连接方式。
1094 <example>
1095   $cd /usr/ports/net/mDNSResponder
1096   $make
1097   $install -s work/mDNSResponder-108/mDNSPosix/build/prod/mDNSResponderPosix $FREENAS/usr/local/sbin/
1098 </example>
1100 *** 2.7 构建boot loader 
1101   使用freenas-create-bootdir.sh生成引导需要的文件。
1103 <example>
1104 #!/bin/sh
1106 # This script was written by David Courtney of Ultradesic
1107 # http://www.ultradesic.com
1108 # E-Mail Contact: minibsd@ultradesic.com
1110 # Adapted for m0n0wall on FreeBSD 6.1 by Olivier Cochard-Labbé (http://www.freenas.org)
1111 # Modified by Volker Theile (votdev@gmx.de)
1113 MINIBSD_DIR=/usr/local/freenas/bootloader;
1115 # Initialize variables.
1116 opt_a=0
1117 opt_d=0
1118 opt_s=0
1119 opt_f=0
1121 # Parse the command-line options.
1122 while getopts 'adfhs' option
1124         case "$option" in
1125     "a")  opt_a=1;;
1126     "d")  opt_d=1;;
1127     "f")  opt_f=1;;
1128     "s")  opt_s=1;;
1129     "h")  echo "$(basename $0): Build boot loader";
1130           echo "Common Options:";
1131           echo "  -a    Disable ACPI"
1132           echo "  -d    Enable debug"
1133           echo "  -s    Enable serial console";
1134           echo "  -f    Force executing this script";
1135           exit 1;;
1136     ?)    echo "$0: Bad option specified. Exiting...";
1137           exit 1;;
1138   esac
1139 done
1141 shift `expr $OPTIND - 1`
1143 echo "Building the boot loader..."
1145 if [ -n "$1" ]; then
1146   MINIBSD_DIR=$1
1147   echo "Using directory $1."
1150 if [ 1 != $opt_f -a -d "$MINIBSD_DIR" ]; then
1151   echo
1152   echo "=> $MINIBSD_DIR already exists. Remove the directory"
1153   echo "=> before running this script."
1154   echo
1155   echo "=> Exiting..."
1156   echo
1157   exit 1
1160 # Create the boot directory that will contain boot, and kernel
1161 mkdir $MINIBSD_DIR
1162 mkdir $MINIBSD_DIR/defaults
1163 mkdir $MINIBSD_DIR/kernel
1165 # Copy the file in this directory:
1166 cp -v /boot/defaults/loader.conf $MINIBSD_DIR/defaults
1167 cp -v /boot/loader $MINIBSD_DIR
1168 cp -v /boot/boot $MINIBSD_DIR
1169 cp -v /boot/mbr $MINIBSD_DIR
1170 cp -v /boot/cdboot $MINIBSD_DIR
1171 cp -v /boot/loader.4th $MINIBSD_DIR
1172 cp -v /boot/support.4th $MINIBSD_DIR
1173 cp -v /boot/device.hints $MINIBSD_DIR
1175 # Generate the loader.rc file using by bootloader
1176 echo "Generate $MINIBSD_DIR/loader.rc"
1177 echo 'include /boot/loader.4th
1178 start
1179 check-password' > $MINIBSD_DIR/loader.rc
1181 # Generate the loader.conf file using by bootloader
1182 echo "Generate $MINIBSD_DIR/loader.conf"
1183 echo 'mfsroot_load="YES"
1184 mfsroot_type="mfs_root"
1185 mfsroot_name="/mfsroot"
1186 autoboot_delay="-1"' > $MINIBSD_DIR/loader.conf
1187 # Enable debug?
1188 if [ 0 != $opt_d ]; then
1189   echo 'verbose_loading="YES"' >> $MINIBSD_DIR/loader.conf
1190   echo 'boot_verbose=""' >> $MINIBSD_DIR/loader.conf
1192 # Enable serial console?
1193 if [ 0 != $opt_s ]; then
1194   echo 'console="comconsole"' >> $MINIBSD_DIR/loader.conf
1197 # Disable ACPI?
1198 if [ 0 != $opt_a ]; then
1199   echo 'hint.acpi.0.disabled="1"' >> $MINIBSD_DIR/device.hints
1202 # Copy kernel.
1203 if [ -e "/usr/obj/usr/src/sys/FREENAS/kernel.gz" ] ; then
1204   cp /usr/obj/usr/src/sys/FREENAS/kernel.gz $MINIBSD_DIR/kernel
1205 else
1206   echo "=> ERROR: File kernel.gz does not exist!";
1207   exit 1;
1209 </example>
1211   FreeBSD启动顺序
1213   1 boot0  
1214     为MBR(位于硬盘1扇区)。对应LILO。使用boot0cfg安装,默认基于/boot/boot0。446字节。
1215     MBR 包括主引导程序、硬盘分区表且以0x55AA结尾。显示可选择的引导操作系统。
1216     可以用FreeBSD的MBR覆盖现有的MBR
1217     $fdisk -B -b /boot/boot0 device
1218     device为要写入的磁盘名,如ad0,ad2(ide);da0(scsi)
1220   2 boot1 与boot2
1221     与boot2都属于同一个程序/boot/boot,处于磁盘的相同区域(文件系统外,引导分区的第一个轨道,第一个扇区),但由于空间限制,被分为两部分。可以使用bsdlabel更改。
1222     - boot1 识别存储这分区信息的bsdlabel,并寻找执行boot2。
1223     - boot2 可以理解FreeBSD的文件系统,可以选择内核和加载器。
1225   3 booter
1226     最后阶段,放置在文件系统中,为/boot/loader.
1227     使用友好的配置方式,使用内建的命令集。
1229     3.1 探测控制台和磁盘,识别从那个盘引导,来设置变量
1230     
1231     3.2 读取运行/boot/loader.rc ,loader.rc读取/boot/defaults/loader.conf设置默认变量
1232     
1233     3.3 loader.rc读取/boot/loader.conf对读取/boot/defaults/loader.conf的变量作本地修改。
1235 ***  3.8 添加库
1236    需要的动态连接库还没有添加。通过下载mklibs.pl并在root文件系统上运行来创建。
1238 <example>
1239   $fetch http://www.freenas.org/downloads/mklibs.pl
1240   $perl mklibs.pl $FREENAS > freenas.libs
1241   $perl mkmini.pl freenas.libs / $FREENAS
1242   $cp -p /usr/lib/pam_*.so.3 $FREENAS/usr/lib
1243   $cd /usr/ports/security/pam_ldap/
1244   $make install
1245   $cp -p /usr/local/lib/pam_ldap.so $FREENAS/usr/local/lib
1246   $cp /libexec/ld-elf.so.1 $FREENAS/libexec
1247   $mkdir $FREENAS/lib/geom
1248   $cp /lib/geom/geom
1249   $cp /lib/geom
1250 </example>
1252 *** 3.9 添加WebGUI
1253   下载FreeNAS GUI 文件并拷贝他们到$FREENAS/usr/local/www
1254   确保所有的.php文件有执行权限 chmod 755
1256 <example>
1257   $fetch http://www.freenas.org/downloads/freenas-gui.tgz
1258   $tar -zxvf freenas-gui.tgz -C $FREENAS
1259 </example>
1261 *** 3.10 创建msfroot
1262   创建一个压缩的系统文件,它被用来运行在RAM disk上。其中为根文件系统,不包括引导程序。
1263   首先下载并运行freenas-create-msfroot.sh脚本来创建一个用0填充的image文件。目前的大小为32MB。如果你添加了大的部件,需要提高其容量。
1265 <example>
1266   $fetch http://www.freenas.org/downloads/freenas-create-msfroot.sh
1267   $./freenas-create-msfroot.sh
1268 </example>
1270   它的内容为
1272 <example>
1273 #!/bin/sh
1274 # Generate the mfs ROOT file system
1276 #Setting directory
1278 WORKINGDIR="/usr/local/freenas"
1279 FREENAS="/usr/local/freenas/rootfs"
1280 CDROOT="/usr/local/freenas/cdroot"
1281 BOOTDIR="/usr/local/freenas/bootloader"
1283 #lauching the script
1285 # Remove old file
1286 if [ $WORKINGDIR/mfsroot.gz ] ; then
1287         echo ;
1288         echo "mfsroot.gz already exists.  Removing this file" ;
1289         echo ;
1290     rm $WORKINGDIR/mfsroot.gz;
1291     #exit ;
1292 fi ;
1294 # umount the /mnt directory
1295 umount /mnt
1297 # Remove the memory file
1298 mdconfig -d -u 0
1300 # Create a 32Mb empty file
1301 dd if=/dev/zero of=$WORKINGDIR/mfsroot bs=1k count=32768
1303 # Configure this file as a virtual disk
1304 mdconfig -a -t vnode -f $WORKINGDIR/mfsroot -u 0
1306 # Create Label on this disk
1307 bsdlabel -w md0 auto
1309 # format it
1310 newfs -b 8192 -f 1024 -o space -m 0 /dev/md0c
1312 # Mount it
1313 mount /dev/md0c /mnt
1315 # Copy the file on it
1316 cd /mnt
1317 tar -cf - -C $FREENAS ./ | tar -xvpf -
1318 cd $WORKINGDIR
1320 # umount the /mnt directory
1321 umount /mnt
1323 # Remove the memory file
1324 mdconfig -d -u 0
1325 echo Compresing....
1326 gzip -9 mfsroot
1327 </example>
1329  - mdconfig 创建并使用内存磁盘
1331    1 从系统中移走内存磁盘
1332      <example> $mdconf -d -u 4 </example>
1333      释放/dev/md4使用的所有资源。 -d 从系统释放内存磁盘并释放所有的资源。
1334                               -u 指定一个md设备单元号,而不使用自动生成的。
1336    2 挂载已经存在的映像文件
1338     <example> $mdconfig -a -t vnode -f diskimage -u 0</example>
1340      -a 挂接一个内存磁盘到系统
1341      -t type 选择内存磁盘的类型 
1342               malloc: 使用malloc分配空间
1343               vnode:  与之后的-f filename配合,用该文件保存内存磁盘内容
1344               swap:   使用swap空间保存内存磁盘的内容
1345   -dd 把指定的输入文件转换到输出文件,并可以进行格式转换。
1347    <exmaple>$dd if=/dev/zero of=newimage bs=1k count=5k</example>
1349     if:输入文件
1350     of:输出文件
1351     bs: 一次的读写字节数(缓冲区)
1352     count: 只拷贝输入的多少块(次),每次单位为bs字节
1354   - bsdlabel
1355     
1356     fdisk用来划分主分区(slice),它的操作对象是硬盘的第一个扇区(MBR),在MBR中写入标准引导程序(boot0),以及主分区的分区信息。
1358     bsdlabel用来在主分区中划分逻辑分区,操作对象是硬盘中主分区的第一个扇区,用来写入boot1和boot2,以及位于该主分区中的逻辑分区的分区信息以及标识号。
1359    
1361 <example>
1362   $bsdlabel -B -w /dev/ad0s1 auto 
1363 </example>   
1364   -B 表示在该主分区ad0s1中写入该主分区的引导记录boot1,boot2。
1365   -w  表示写入。
1366   auto表示 在主分区中自动划出一个逻辑分区
1368   -newfs 创建文件系统
1370 <example>
1371   $newfs -b 8192 -f 1024 -o space -m 0 /dev/md0c
1372 </example>
1373   -b block 大小
1374   -f fragment 大小
1375   -o 优化选项 space 或者是 time
1376   -m 保留的未使用空间 默认为10%
1377      md0c ,c为所有的分区
1379   - tar
1381   <example>
1382     $tar -cf - -C $FREENAS ./ | tar -xvpf -
1383   </example>
1384     -c 创建
1385     -f 指定存档
1386     -C 转到指定的目录
1388 *** 2.11 创建image (为了hard drive  或 CF)
1389   与创建mfsroot类似。使用freenas-create-image.sh
1390   内容为mfsroot+引导程序
1392 <example>
1393   $fetch http://freenas.org/downloads/freenas-create-image.sh
1394   $./freenas-create-image.sh
1395 </example>
1397   下面是其内容
1399 <example>
1400 #!/bin/sh
1401 # FreeNAS script for generating .img
1403 # setting variables
1404 FREENAS="/usr/local/freenas/rootfs"
1405 WORKINGDIR="/usr/local/freenas"
1406 CDROOT="/usr/local/freenas/imgroot"
1407 BOOTDIR="/usr/local/freenas/bootloader"
1408 PLATFORM="generic-pc"
1409 VERSION=`cat $FREENAS/etc/version`
1410 ISOFILENAME="FreeNAS-$PLATFORM-$VERSION.img"
1412 # Remove old directory
1413 if [ -d $CDROOT ] ; then
1414         echo ;
1415         echo "$CDROOT already exists.  Removing this directory" ;
1416         echo ;
1417         echo ;
1418     rm -rf $CDROOT;
1419     #exit ;
1420 fi ;
1422 if [ $WORKINGDIR/$ISOFILENAME ] ; then
1423         echo ;
1424         echo "$ISOFILENAME already exists.  Removing this directory" ;
1425         echo ;
1426         echo ;
1427     rm $WORKINGDIR/$ISOFILENAME;
1428     #exit ;
1429 fi ;
1431 echo $PLATFORM > $FREENAS/etc/platform
1432 date > $FREENAS/etc/version.buildtime
1433 $WORKINGDIR/freenas-create-mfsroot.sh
1434 echo Generating $CDROOT folder
1435 mkdir $CDROOT
1437 #Creating a 16Mb empty file
1438 dd if=/dev/zero of=image.bin bs=1k count=18432
1440 #use this file as a virtual RAM disk
1441 mdconfig -a -t vnode -f image.bin -u 0
1443 #Create partition on this disk
1444 fdisk -BI -b $BOOTDIR/mbr /dev/md0
1446 #Create label on this disk
1447 bsdlabel -B -w -b $BOOTDIR/boot /dev/md0 auto
1448 bsdlabel md0 >/tmp/label.$$
1449 bsdlabel md0 |
1450      egrep unused |
1451      sed "s/c:/a:/" |
1452      sed "s/unused/4.2BSD/" >>/tmp/label.$$
1453 bsdlabel -R -B md0 /tmp/label.$$
1454 rm -f /tmp/label.$$
1456 #Create filesystem on this disk
1457 newfs -b 8192 -f 1024 -o space -m 0 /dev/md0a
1459 #Mount this disk
1460 mount /dev/md0a $CDROOT
1461 cp $WORKINGDIR/mfsroot.gz $CDROOT
1462 mkdir $CDROOT/boot
1463 mkdir $CDROOT/boot/kernel $CDROOT/boot/defaults
1464 mkdir $CDROOT/conf
1465 cp $FREENAS/conf.default/config.xml $CDROOT/conf
1466 cp $BOOTDIR/kernel/kernel.gz $CDROOT/boot/kernel
1467 cp $BOOTDIR/boot $CDROOT/boot
1468 cp $BOOTDIR/loader $CDROOT/boot
1469 cp $BOOTDIR/loader.conf $CDROOT/boot
1470 cp $BOOTDIR/loader.rc $CDROOT/boot
1471 cp $BOOTDIR/loader.4th $CDROOT/boot
1472 cp $BOOTDIR/support.4th $CDROOT/boot
1473 cp $BOOTDIR/defaults/loader.conf $CDROOT/boot/defaults/
1474 cp $BOOTDIR/device.hints $CDROOT/boot
1475 umount $CDROOT
1476 mdconfig -d -u 0
1477 gzip -9 image.bin
1478 mv image.bin.gz $ISOFILENAME
1480 # Cleaning directory and temp file
1481 if [ $WORKINGDIR/mfsroot.gz ] ; then
1482         echo ;
1483         echo "cleaning mfsroot.gz" ;
1484         echo ;
1485     rm $WORKINGDIR/mfsroot.gz 
1488 if [ -d $CDROOT ] ; then
1489         echo ;
1490         echo "cleaning $CDROOT by Removing this directory" ;
1491         echo ;
1492         echo ;
1493     rm -rf $CDROOT;
1495 </example>
1497 *** 2.12 创建cd-rom
1498 **** 2.12.1 安装CDRTools
1499   在创建可引导CD之前,我们必须安装CDRTools
1501 <example>
1502   $cd /usr/ports/sysutils/cdrtools
1503   $make
1504   $make install
1505 </example>
1507 **** 2.12.2 创建可引导iso文件
1508   使用freenas-create-cd.sh
1510 <example>
1511   $fetch http://www.freenas.org/downloads/freenas-create-cd.sh
1512   $./freenas-create-cd.sh
1513 </example>
1514   
1515   脚本内容为
1517 <example>
1518 #!/bin/sh
1519 # FreeNAS script for generating iso file
1520 FREENAS="/usr/local/freenas/rootfs"
1521 WORKINGDIR="/usr/local/freenas"
1522 CDROOT="/usr/local/freenas/cdroot"
1523 BOOTDIR="/usr/local/freenas/bootloader"
1524 PLATFORM="generic-pc-cdrom"
1525 VERSION=`cat $FREENAS/etc/version`
1526 ISOFILENAME="FreeNAS-$VERSION.iso"
1528 #remove old directory
1529 if [ -d $CDROOT ] ; then
1530         echo ;
1531         echo "$CDROOT already exists.  Removing this directory" ;
1532         echo "before running this script." ;
1533         echo ;
1534         #echo "Exiting..." ;
1535         echo ;
1536     rm -rf $CDROOT;
1537     #exit ;
1538 fi ;
1540 echo "$PLATFORM" > $FREENAS/etc/platform
1541 date > $FREENAS/etc/version.buildtime
1542 $WORKINGDIR/freenas-create-mfsroot.sh
1544 rm $WORKINGDIR/$ISOFILENAME
1545 echo Generating $CDROOT folder
1546 mkdir $CDROOT
1547 cp $WORKINGDIR/mfsroot.gz $CDROOT
1548 mkdir $CDROOT/boot
1549 mkdir $CDROOT/boot/kernel $CDROOT/boot/defaults
1550 cp $BOOTDIR/kernel/kernel.gz $CDROOT/boot/kernel
1551 cp $BOOTDIR/cdboot $CDROOT/boot
1552 cp $BOOTDIR/loader $CDROOT/boot
1553 cp $BOOTDIR/loader.conf $CDROOT/boot
1554 cp $BOOTDIR/loader.rc $CDROOT/boot
1555 cp $BOOTDIR/loader.4th $CDROOT/boot
1556 cp $BOOTDIR/support.4th $CDROOT/boot
1557 cp $BOOTDIR/defaults/loader.conf $CDROOT/boot/defaults/
1558 cp $BOOTDIR/device.hints $CDROOT/boot
1560 ###### BEGIN: NEW RELEASE CHANGE ######
1561 $WORKINGDIR/freenas-create-image.sh
1562 cp $WORKINGDIR/FreeNAS-generic-pc-$VERSION.img $CDROOT/FreeNAS-generic-pc.gz
1563 ###### END: NEW RELEASE CHANGE ######
1565 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
1567 if [ -d $CDROOT ] ; then
1568         echo ;
1569         echo "Cleaning directory" ;
1570         echo ;
1571         echo ;
1572             rm -rf $CDROOT;
1573 rm mfsroot.gz;
1574             #exit ;
1575 fi ;
1577 </example>