系統版本centos5.6-x86_64
一直使用centos5.x系列,比較穩定,一些軟件兼容性很好。Centos6.x也有使用,但感覺一些軟件兼容性沒有5繫好,而且本人在使用過程中好像偶爾會出現一些莫名其妙的小問題。
訂製系統的目的是精簡系統,達到快速安裝。其核心是用一臺母機,先根據自己的需要安裝好系統,然後主要利用兩個文件。一個是安裝母機系統的安裝包列表文件(install.log),另一個是實現自動安裝的kickstart腳本(在安裝好的系統上叫anaconda-ks.cfg)。因爲這兩個文件是配套的,所以最好是用這兩個文件,不要在網上隨便找個就進行操作,這樣容易出現問題。
下面是訂製精簡系統的過程:
1. 母機安裝好後,把原版光盤或鏡像文件掛載到一個目錄。然後拷貝除CentOS之外的所有文件到要訂製系統的文件目錄。
首先安裝一些一會訂製系統要用到的包:
yum -y install createrepo mkisofs anaconda-runtime
建立一個訂製目錄:
[root@localhost ~]# mkdir /live_os
掛載原版光盤到/mnt目錄:
[root@localhost ~]# mount /dev/cdrom /mnt/
利用shell模式的rsync把文件拷貝過去:
[root@localhost ~]#rsync -a --exclude=CentOS /mnt/ /live_os
建立訂製目錄的CentOS文件夾(用來存放自己需要的rpm包):
[root@localhost ~]#mkdir /live_os/CentOS
接下來獲取所需的rpm包:
[root@localhost ~]#awk '{print $2}' install.log |sed s/^[0-9]*://g |grep -v 'i386' > /root/packages.list
(這條命令利用awk打印第二個字段,用sed過濾掉以數字開頭的內容,用grep過濾掉i386的安裝包)
[root@localhost ~]#for i in `cat packages.list` ; do cp /mnt/CentOS/$i* /live_os/CentOS/; done
(這條命令是利用package.list中的文件內容把光盤上的包拷貝到CentOS目錄)。
2. 拷貝kickstart文件到指定位置:
[root@localhost ~]#cp anaconda-ks.cfg /live_os/isolinux/ks.cfg
編輯ks.cfg文件:
我的ks文件內容如下:
[root@localhost isolinux]# cat ks.cfg
# Kickstart file automatically generated by anaconda.
install
text
cdrom
lang en_US.UTF-8
keyboard us
reboot
skipx
network --device eth0 --bootproto dhcp
rootpw --iscrypted $1$XigKVP5d$j4kCF.nEOQdq769algNmP/
firewall --disabled
authconfig --enableshadow --enablemd5
selinux --disabled
timezone --utc Asia/Shanghai
bootloader --location=mbr
zerombr yes
#--driveorder=sda
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
clearpart --all --initlabel
part /boot --fstype ext3 --size=256 --asprimary
part / --fstype ext3 --size=80000
part swap --size=16000
part /opt --fstype ext3 --size=100 --grow
%packages
@admin-tools
@base
@core
@development-libs
@development-tools
@editors
@system-tools
keyutils
kexec-tools
iscsi-initiator-utils
trousers
fipscheck
device-mapper-multipath
imake
audit
iptraf
3. 編輯isolinux.cfg文件:
[root@localhost isolinux]# chmod a+w isolinux.cfg
[root@localhost isolinux]# cat isolinux.cfg
default ks #指明默認使用kickstart腳本進行安裝
prompt 1
timeout 600
display boot.msg
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg
label linux
kernel vmlinuz
append initrd=initrd.img
label text
kernel vmlinuz
append initrd=initrd.img text
label ks
kernel vmlinuz
append ks=cdrom:/isolinux/ks.cfg initrd=initrd.img #這個ks.cfg理論上可以放到其他位置,指定好正確路徑就好。
label local
localboot 1
label memtest86
kernel memtest
append -
4. 回到訂製目錄的根下打包訂製iso文件:
[root@localhost live_os]#declare -x discinfo=`head -1 .discinfo`
[root@localhost live_os]#createrepo -g repodata/*comps.xml /live_os/
[root@localhost cnlive_os]#mkisofs -o /tmp/MYCentOS_5.6_x86_64.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -T /live_os/
完成@@@
刻錄成光盤之後只有600多兆。相比4G多的dvd原版輕便多了。再裝系統時只要讓服務器從光盤啓動就啥也不用管了。很方便!!!
上面是光盤版,現在再來一個U盤版
訂製好的光盤雖然輕便,但讀取速度還是不如U盤。
光盤適合的場景一個是服務器數量較少的情況。再有一個是帶遠程管理功能的服務器,比如配備了idrac卡的dell系列。還有最近接觸的帶BMC口的華爲系列服務器。這些服務器支持KVM over IP。能冷重啓,在關機的情況下開機,能遠程設置bios,當然也能加載本地光盤或鏡像供遠程服務器使用。功能強大,很受sa的歡迎。所以如果服務器在idc,如果服務器系統崩潰的話,iso鏡像就能很好的被利用了,利用本地鏡像可以給遠程服務器重裝系統。免去了去機房的麻煩。
U盤安裝速度快,幾分鐘就可以裝完一個系統。比較適合服務器比較多,但又暫時不方便聯網的時候用。
下面是安裝過程製作過程,很簡單,用上面製作好的鏡像文件再簡單配置就可以了。不過U盤裝有一個比較不爽的地方,就是U盤在不同的服務器上可能被識別成不同的盤符。所以關鍵是確定要用U盤安裝系統的服務器會把U盤識別成什麼盤。不然可要頭疼半天了。
1. 在windows下用ultraiso工具
文件---打開,選擇製作好的光盤鏡像(也可以是原版的)
雙擊images(如下圖)
雙擊boot.iso(如下圖)
點擊 啓動-----寫入硬盤映像(這時U盤應該是插在電腦上的)。彈出的界面,確認一下是要寫入的U盤。
點擊寫入就可以了,ultraiso直接創建了啓動linux所需的文件,和syslinux.cfg文件。直接編輯就可以了。
2. 經過以上操作在U盤裏會生成一個isolinux的文件夾,點擊進去後,編輯syslinux.cfg文件,這個是U盤啓動的配置文件。
我的文件內容如下:
default ks
prompt 1
timeout 600
display boot.msg
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg
label linux
kernel vmlinuz
append initrd=initrd.img
label text
kernel vmlinuz
append initrd=initrd.img text
label ks
kernel vmlinuz
append ks=hd:sdb4:/ks.cfg initrd=initrd.img #這裏注意了,其他的和光盤的配置文件一樣。
label local
localboot 1
label memtest86
kernel memtest
append -
3. 拷貝ks.cfg文件到U盤根下,內容大致如下:
# Kickstart file automatically generated by anaconda.
install
harddrive --partition=sdb4 --dir= #這裏注意
text
lang en_US.UTF-8
keyboard us
reboot
skipx
#network --device eth0 --bootproto dhcp
rootpw --iscrypted $1$XigKVP5d$j4kCF.nEOQdq769algNmP/
firewall --disabled
authconfig --enableshadow --enablemd5
selinux --disabled
timezone --utc Asia/Shanghai
bootloader --location=partition --driveorder=sda #這裏bootloader注意,如果有錯誤可能導致系統裝完後不能啓動
zerombr yes
#--driveorder=sda
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
clearpart --all --initlabel
part /boot --fstype ext3 --size=256 --asprimary
part / --fstype ext3 --size=80000
part swap --size=16000
part /opt --fstype ext3 --size=100 --grow
%packages
@admin-tools
@base
@core
@development-libs
@development-tools
@editors
@system-tools
keyutils
kexec-tools
iscsi-initiator-utils
trousers
fipscheck
device-mapper-multipath
imake
audit
4. 拷貝訂製好的iso鏡像到U盤根目錄下(也可以是原版,只不過佔地方吧)
完成@@@
插上U盤,讓系統從U盤啓動。喝杯茶吧。茶沒喝完就裝完了!!!
再次提醒不同的服務器可能會把U盤識別成不同盤符。確定好之後修改ks.cfg和syslinux.cfg文件!!!
本文也是參考網上文章製作而成,感謝網絡上朋友們的奉獻精神,同時把自己製作過程記錄下來,希望能幫到有需要的朋友。同時做個備忘。下一步打算把這個訂製系統用到pxe環境。再實驗一下!把步驟記錄下來。