歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Unix知識 >> BSD >> 制作FreeBSD系統定制安裝ISO

制作FreeBSD系統定制安裝ISO

日期:2017/3/1 17:14:19   编辑:BSD
制作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-file mtree -c -K md5digest -p ./base/ > base.tar/base.mtree cd /8.0-Release-src-file/base tar -czpf - ./* | split -b 4M rm -f ../base.tar/ mv x?? ../base.tar cd /8.0-Release-src-file/base.tar find ./ -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.inf cksum 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.MD5 cat /dev/null > CHECKSUM.SHA256 md5 * | grep -v CHECKSUM > CHECKSUM.MD5 sha256 * | 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/boot gzip -d mfsroot.gz mdconfig -a -t vnode -u0 -f mfsroot mount /dev/md0 /dist vim /dist/install.cfg #編輯自動安裝腳本 #修改完成後將文件重新打包進 mfsroot包中 umount /dist cd /8.0-Release/boot mdconfig -d -u0 gzip 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 output debug=YES country=china keymap=us.iso nonInteractive=YES noWarn=YES ############網絡配置####################### ##主機名 hostname=test domainname=hapame.com nameserver=114.113.145.31 nameserver=202.106.0.20 defaultrouter=192.168.16.1 ipaddr=192.168.16.198 netmask=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 susbin distSetCustom #############磁盤配置############# disk=da0 partition=all bootManager=standard diskPartitionEditor #######分區設置############# # 分區大小計算方法 #比如:60G空間 1024 * 1024 * 2 * 60 = 125829120 da0s1-1=ufs 1048576 / da0s1-2=swap 1048576 none da0s1-3=ufs 2097152 /var da0s1-4=ufs 2097152 /usr da0s1-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 data hostname=crate.cdrom.com domainname=cdrom.com nameserver=204.216.27.3 defaultrouter=204.216.27.228 ipaddr=204.216.27.230 netmask=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/pub netDev=ed0 mediaSetFTP ################################ # Select which distributions we want. dists=base doc manpages info src sbase ssys kernels GENERIC distSetCustom ################################ # 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=da0 partition=exclusive diskPartitionEditor # 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 partition da0s1-1=ufs 1048576 / # And a 512MB swap partition da0s1-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 1 da0s2-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=ad1 partition=exclusive diskPartitionEditor ad1s1-1=ufs 2097152 /var ad1s1-2=ufs 0 /usr/src diskLabelEditor ################################ # And the 3rd, adding a second 512MB of swap and the rest of the disk # for /tmp. disk=da0 partition=exclusive diskPartitionEditor da0s1-1=swap 1048576 none da0s1-2=ufs 0 /tmp diskLabelEditor ################################ # OK, everything is set. Do it! installCommit # Install some packages at the end. package=bash-3.1.17 packageAdd package=ncftp-3.2.0 packageAdd
Copyright © Linux教程網 All Rights Reserved