製作FreeBSD系統定製安裝ISO FreeBSD ISO的定製的想法起源於當時在安裝完系統後,要做些重複的配置工作,浪費時間可經曆。 www.2cto.com 於是就開始尋找資料,發現國內幾乎沒有這方面的資料可查,最後還是從老外的一篇文章中知道了大概的過程! FreeBSD系統的結構相對還是比較簡單的,其目錄檔案基本上分為兩類:1、基本系統,安裝在除 /usr/local 外的位置。2、通過pkg_add 或 使用port樹 make install 安裝在/usr/local 路徑下。 基本系統則是通過壓縮包直接解壓縮出來,並放到新系統的對應目錄中,那麼我們就可以通過修改壓縮包的內容,直接將我們修改定製好的配置內容替換原始內容,那麼新安裝的系統就和我們配置好的系統完全一致,達到安裝、配置一步完成,提高效率,同時也避免了重複勞動。(由於這篇文章是後期整理,離實際操作已經有一段時間啦,可能有些步驟未必列出) 一、將下載的ISO檔案載入到一天配置完成的模板系統上,建立模板系統存放路徑,如:/var/custom-iso 將ISO內的所有檔案複製到目錄中。 www.2cto.com 將配置好的檔案替換掉解壓縮出來的目錄中的相應檔案,當然也可以添加原系統中沒有的檔案,下面是重新打包壓縮的過程 1、產生 base 目錄檔案的步驟 cd /8.0-Release-src-filemtree -c -K md5digest -p ./base/ > base.tar/base.mtree cd /8.0-Release-src-file/basetar -czpf - ./* | split -b 4M rm -f ../base.tar/mv x?? ../base.tar cd /8.0-Release-src-file/base.tarfind ./ -type f -depth 1 -name 'x??' |sed s/'.\/x'//g | awk '{MV="mv "};{PRE="base."};{SRC="x"};{print MV SRC$0, PRE$0}' | sh echo "Pieces =`ls -l base.?? | wc -l`" > base.infcksum base.?? |sed s/base/cksum/g | awk -F" " '{printf("%s = %s %s\n", $3, $1, $2)}' >> base.inf cksum base.aa | awk -F" " '{printf("%s = %s %s\n", $3, $1, $2)}' 組建目錄樹的MD5碼cat /dev/null > CHECKSUM.MD5cat /dev/null > CHECKSUM.SHA256md5 * | grep -v CHECKSUM > CHECKSUM.MD5sha256 * | grep -v CHECKSUM > CHECKSUM.SHA256 rm -f /8.0-Release/8.0-RELEASE/base/*cp * /8.0-Release/8.0-RELEASE/base/ 修改自動安裝指令碼INSTALL.CFG的步驟(實現系統的自動安裝、自動分區、及其他,安裝過程可不需要人工輸入)由於 install.cfg 包含在mfsroot.gz包內,通過下面的步驟將其掛載到當前的系統的 /dist 下。cd /8.0-Release/bootgzip -d mfsroot.gzmdconfig -a -t vnode -u0 -f mfsrootmount /dev/md0 /dist vim /dist/install.cfg #編輯自動安裝指令碼 #修改完成後將檔案重新打包進 mfsroot包中umount /distcd /8.0-Release/bootmdconfig -d -u0gzip mfsroot #建立定製完成的iso檔案mkisofs –R –no-emul-boot –b ~/freebsd/boot/cdboot –o freebsdautoinstall.iso ~/freebsd #ISO檔案建立完成後就是實際安裝驗證是否正確啦#我是將該ISO傳到vmware exsi 的虛擬系統中,通過安裝虛擬機器的方式驗證echo 'password' | scp /fb8-amd64-hapa.iso root@vmwareexs4:/vmfs/volumes/4aaa839c-7791b8bf-280b-002219bf7965 #沒有問題的話就可以燒錄光碟片啦burncd –f /dev/acd0 freebsdautoinstall.iso fixate 附:自動安裝設定檔#THIS A SIMPLE INSTALL.CFG#DO NOT USE THIS CONFIG YOU'VE READ IT CAREFULLY AS IT WILL OVERWRITE YOUR DISK##############################Use Alt F2 to see the debug outputdebug=YES country=chinakeymap=us.isononInteractive=YESnoWarn=YES############網路設定#########################主機名稱hostname=testdomainname=hapame.comnameserver=114.113.145.31nameserver=202.106.0.20defaultrouter=192.168.16.1ipaddr=192.168.16.198netmask=255.255.255.0#############安裝方式######################mediaSetCDROM#############選擇安裝的Distribution Set##############dists=base GENERIC manpages info lib32 ports#dists= base GENERIC manpages catpages proflibs info sbase scontrib ssecure scrypto sgnu setc sinclude skrb5 slib slibexec sgames srelease srescue stools sbin ssbin sshare ssys stools subin susbindistSetCustom#############磁碟配置#############disk=da0partition=allbootManager=standarddiskPartitionEditor#######分區設定############## 分區大小計算方法#比如:60G空間 1024 * 1024 * 2 * 60 = 125829120da0s1-1=ufs 1048576 /da0s1-2=swap 1048576 noneda0s1-3=ufs 2097152 /varda0s1-4=ufs 2097152 /usrda0s1-5=ufs 0 /storage 1 installCommit############安裝附加軟體包##########shutdown 下面是從網上找的一個INSTALL.CFG 樣本, # This is a sample installation configuration file for my test machine,# crate.cdrom.com.# It is included here merely as a sort-of-documented example.## $FreeBSD: src/usr.sbin/sysinstall/install.cfg,v 1.12.10.1.2.1 2009/10/25 01:10:29 kensmith Exp $ # Turn on extra debugging.debug=yes ################################# My host specific datahostname=crate.cdrom.comdomainname=cdrom.comnameserver=204.216.27.3defaultrouter=204.216.27.228ipaddr=204.216.27.230netmask=255.255.255.240 ################################# Which installation device to use - ftp is pointed directly at my local# machine and the installation device is my WD8013 ethernet interface._ftpPath=ftp://time.cdrom.com/pubnetDev=ed0mediaSetFTP ################################# Select which distributions we want.dists=base doc manpages info src sbase ssys kernels GENERICdistSetCustom ################################# Now set the parameters for the partition editor on da0. Set to use the# disk exclusively (could also be "all" to use the whole disk but# respecting the MBR or "free" to use only unallocated space for FreeBSD). disk=da0partition=exclusivediskPartitionEditor # Uncomment this instead to use only the free space and install boot manager.#partition=free#bootManager=booteasy#diskPartitionEditor################################ # Disk partitioning.# All sizes are expressed in 512 byte blocks! # A 512MB root partitionda0s1-1=ufs 1048576 /# And a 512MB swap partitionda0s1-2=swap 1048576 none# Followed by a /usr partition using all remaining space (size 0 = free space)# and with softupdates enabled (non-zero arg following mountpoint).da0s1-3=ufs 0 /usr 1da0s2-1=ufs 0 /storage 1# Let's do it!diskLabelEditor ################################# Now partition the 2nd disk with a 1GB /var and /usr/src using the# remainder of the disk.disk=ad1partition=exclusivediskPartitionEditor ad1s1-1=ufs 2097152 /varad1s1-2=ufs 0 /usr/srcdiskLabelEditor ################################# And the 3rd, adding a second 512MB of swap and the rest of the disk# for /tmp.disk=da0partition=exclusivediskPartitionEditor da0s1-1=swap 1048576 noneda0s1-2=ufs 0 /tmpdiskLabelEditor################################ # OK, everything is set. Do it!installCommit # Install some packages at the end.package=bash-3.1.17packageAddpackage=ncftp-3.2.0packageAdd