制作FreeBSD系统定制安装ISO


制作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
 

相关内容

    暂无相关文章