我須要作一個一鍵安裝centos系統的程序,而且pxe沒法使用,由於dhcp服務器不支持pxe指令集,因此只是使用kickstart,但又想智能自動一點,因此使用了網絡安裝方式,有一個好處就是,如今我不使用cdrom了,使用u盤,可是u盤的在linux下的device標籤會有時候變,會在sda和sdb中變化,因此最後仍是決定使用網絡安裝系統,由u盤引導,最後就有了這樣一篇文章。php
1. 載入 BIOS 的硬體資訊與進行自我測試,並依據設定取得第一個可開機的裝置; 2. 讀取並執行第一個開機裝置內 MBR 的 boot Loader (亦便是 grub, spfdisk 等程式); 3. 依據 boot loader 的設定載入 Kernel ,Kernel 會開始偵測硬體與載入驅動程式; 4. 在硬體驅動成功後,Kernel 會主動呼叫 init 程式,而 init 會取得 run-level 資訊; 5. init 執行 /etc/rc.d/rc.sysinit 檔案來準備軟體執行的做業環境 (如網路、時區等); 6. init 執行 run-level 的各個服務之啟動 (script 方式); 7. init 執行 /etc/rc.d/rc.local 檔案; 8. init 執行終端機模擬程式 mingetty 來啟動 login 程式,最後就等待使用者登入啦;
引用參考:http://linux.vbird.org/linux_basic/0510osloader.php#startup_introhtml
Anaconda是RedHat、CentOS、Fedora等Linux的安裝管理程序。它能夠提供文本、圖形等安裝管理方式,並支持Kickstart等腳本提供自動安裝的功能。此外,其還支持許多啓動參數,熟悉這些參數可爲安裝帶來不少方便。該程序的功能是把位於光盤或其餘源上的數據包,根據設置安裝到主機上。爲實現該定製安裝,它提供一個定製界面,能夠實現交互式界面供用戶選擇配置(如選擇語言,鍵盤,時區等信息)。Anaconda的大部分模塊用Python編寫,有少量的載入模塊用C編寫。python
Anaconda支持的管理模式: (1)Kickstart提供的自動化安裝; (2)對一個RedHat實施upgrade; (3)Rescuse模式對不能啓動的系統進行故障排除。 要進入安裝步驟,須要先有一個引導程序引導啓動一個特殊的Linux安裝環境系統;引導有多種方式: (1)基於網絡方式的小型引導鏡像,須要提供小型的引導鏡像; (2)U盤引導,經過可引導存儲介質中的小型引導鏡像啓動安裝過程; (3)基於PXE的網絡安裝方式,要提供PXE的完整安裝環境; (4)其餘bootloder引導(如GRUB)。 可用的安裝方式:本地CDROM、硬盤驅動器、網絡方式(NFS、FTP、HTTP)。
對於Kickstart,它是一個利用Anconda工具實現服務器自動化安裝的方法。經過生成的kickstart配置文件ks.cfg,服務器安裝能夠實現從裸機到全功能服務的的非交互式(無人值守式)安裝配置;ks.cfg是一個簡單的文本文件,文件包含Anconda在安裝系統及安裝後配置服務時所須要獲取的一些必要配置信息(如鍵盤設置,語言設置,分區設置等)。Anconda直接從該文件中讀取必要的配置,只要該文件信息配置正確無誤且知足全部系統需求,就再也不須要同用戶進行交互獲取信息,從而實現安裝的自動化。可是配置中若是忽略任何須需的項目,安裝程序會提示用戶輸入相關的項目的選擇,就象用戶在典型的安裝過程當中所遇到的同樣。一旦用戶進行了選擇,安裝會以非交互的方式(unattended)繼續。使用kickstart能夠實現流線化自動化的安裝、快速大量的裸機部署、強制創建的一致性(軟件包,分區,配置,監控,安全性)、以及減小人爲的部署失誤。linux
(1)第一階段:加載安裝樹的isolinux目錄下的內核映像vmlinuz和初始RAM磁盤initrd.img,創建安裝環境。initrd.img中的/init程序調用/sbin/loader程序,loader加載kickstart文件,最後運行/usr/bin/anaconda主程序,進入第二階段。ios
(2)第二階段:anaconda程序加載各python和bash模塊,執行各個安裝步驟web
引用參考:http://blog.csdn.net/zhoudaxia/article/details/7172020sql
他是由dhcp中pxe的指令集分配pxe指令到客戶機,而且客戶機自己網卡支持pxe網絡啓動,這樣的話就能夠在分配ip的時候告知客戶機kickstart配置和系統iso資源的位置,這樣就能完成了無人值守的一鍵安裝apache
第一步是啓動盤引導centos
第二步是獲取dhcp分配的ip安全
第三步是訪問web服務器拿到ks.cfg文件
第四步是經過第三步的ks.cfg來訪問web服務器的系統盤iso資源進行安裝
第一次格式化磁盤的時候kickstart並不能識別,因此有warning,按照指示點擊確認便可
主要是這2步。
1.建立一個啓動iso鏡像,而且寫入到光盤或者u盤裏面,這個叫光盤引導驅動盤或者u盤引導驅動盤
1.下載原始光盤(centos官網下載,32位,64位,mini32),我這邊選用32位mini
下載完成後掛載到/mnt/下
mount -o loop -t iso9660 /root/CentOS-6.5-i386-minimal.iso /mnt mkdir /tmp/isomake_dir cp -arp /mnt/* /tmp/isomake_dir/
2.修改iso啓動配置文件isolinux.cfg(vi /tmp/isomake_dir/isolinux/isolinux.cfg)
default vesamenu.c32 #prompt 1 timeout 600 display boot.msg menu background splash.jpg menu title Welcome to CentOS 6.5! menu color border 0 #ffffffff #00000000 menu color sel 7 #ffffffff #ff000000 menu color title 0 #ffffffff #00000000 menu color tabmsg 0 #ffffffff #00000000 menu color unsel 0 #ffffffff #00000000 menu color hotsel 0 #ff000000 #ffffffff menu color hotkey 7 #ffffffff #ff000000 menu color scrollbar 0 #ffffffff #00000000 label linux menu label ^Install or upgrade an existing system menu default kernel vmlinuz append initrd=initrd.img label vesa menu label Install system with ^basic video driver kernel vmlinuz append initrd=initrd.img xdriver=vesa nomodeset label rescue menu label ^Rescue installed system kernel vmlinuz append initrd=initrd.img rescue label local menu label Boot from ^local drive localboot 0xffff label memtest86 menu label ^Memory test kernel memtest append - label http menu http kernel vmlinuz append initrd=initrd.img append initrd=initrd.img ks=http://192.168.6.127/centos/isolinux/ks.cfg
主要是增長了
label http #啓動界面的名字,寫http是爲了方便識別 menu http kernel vmlinuz append initrd=initrd.img append initrd=initrd.img ks=http://192.168.6.127/centos/isolinux/ks.cfg
ks.cfg是後面建立,這裏先寫好,這裏的意義是在啓動盤啓動引導的時候指定使用的kickstart文件,(isolinux.cfg是centos6系統盤iso的啓動引導菜單,就是安裝彈出的第一個選擇的菜單,增長這個是指定了哪一個啓動項對於的啓動動做)而後交給這個kickstart文件進行引導安裝
3.製做啓動iso鏡像
yum -y install mkisofs cd /tmp/isomake_dir mkisofs -R -J -T -v -no-emul-boot -boot-load-size 4 -boot-info-table -V "test centos install iso" -b isolinux/isolinux.bin -c isolinux/boot.cat -o /tmp/test.iso I: -input-charset not specified, using utf-8 (detected in locale settings) genisoimage 1.1.9 (Linux) Scanning . Scanning ./isolinux Excluded by match: ./isolinux/boot.cat Scanning ./Packages Scanning ./repodata Scanning ./images Excluded: ./TRANS.TBL Using RPM_G000.;1 for /RPM-GPG-KEY-CentOS-Debug-6 (RPM-GPG-KEY-CentOS-6) Using RPM_G001.;1 for /RPM-GPG-KEY-CentOS-6 (RPM-GPG-KEY-CentOS-Security-6) Using RPM_G002.;1 for /RPM-GPG-KEY-CentOS-Security-6 (RPM-GPG-KEY-CentOS-Testing-6) Using DEVIC000.RPM;1 for ./Packages/device-mapper-multipath-libs-0.4.9-72.el6.i686.rpm (device-mapper-event-libs-1.02.79-8.el6.i686.rpm) Using DEVIC001.RPM;1 for ./Packages/device-mapper-event-libs-1.02.79-8.el6.i686.rpm (device-mapper-multipath-0.4.9-72.el6.i686.rpm) Using DEVIC002.RPM;1 for ./Packages/device-mapper-multipath-0.4.9-72.el6.i686.rpm (device-mapper-1.02.79-8.el6.i686.rpm) Using LIBSE000.RPM;1 for ./Packages/libselinux-2.0.94-5.3.el6_4.1.i686.rpm (libselinux-utils-2.0.94-5.3.el6_4.1.i686.rpm) Using FIPSC000.RPM;1 for ./Packages/fipscheck-1.2.0-7.el6.i686.rpm (fipscheck-lib-1.2.0-7.el6.i686.rpm) Using OPENS000.RPM;1 for ./Packages/openssh-server-5.3p1-94.el6.i686.rpm (openssh-5.3p1-94.el6.i686.rpm) Using SELIN000.RPM;1 for ./Packages/selinux-policy-3.7.19-231.el6.noarch.rpm (selinux-policy-targeted-3.7.19-231.el6.noarch.rpm) Using CRACK000.RPM;1 for ./Packages/cracklib-2.8.16-4.el6.i686.rpm (cracklib-dicts-2.8.16-4.el6.i686.rpm) Using IPTAB000.RPM;1 for ./Packages/iptables-1.4.7-11.el6.i686.rpm (iptables-ipv6-1.4.7-11.el6.i686.rpm) Using DEVIC003.RPM;1 for ./Packages/device-mapper-1.02.79-8.el6.i686.rpm (device-mapper-libs-1.02.79-8.el6.i686.rpm) Using E2FSP000.RPM;1 for ./Packages/e2fsprogs-1.41.12-18.el6.i686.rpm (e2fsprogs-libs-1.41.12-18.el6.i686.rpm) Using CYRUS000.RPM;1 for ./Packages/cyrus-sasl-lib-2.1.23-13.el6_3.1.i686.rpm (cyrus-sasl-2.1.23-13.el6_3.1.i686.rpm) Using DEVIC004.RPM;1 for ./Packages/device-mapper-libs-1.02.79-8.el6.i686.rpm (device-mapper-persistent-data-0.2.8-2.el6.i686.rpm) Using KEYUT000.RPM;1 for ./Packages/keyutils-libs-1.4-4.el6.i686.rpm (keyutils-1.4-4.el6.i686.rpm) Using OPENS001.RPM;1 for ./Packages/openssh-5.3p1-94.el6.i686.rpm (openssh-clients-5.3p1-94.el6.i686.rpm) Using PLYMO000.RPM;1 for ./Packages/plymouth-0.8.3-27.el6.centos.i686.rpm (plymouth-scripts-0.8.3-27.el6.centos.i686.rpm) Using PLYMO001.RPM;1 for ./Packages/plymouth-scripts-0.8.3-27.el6.centos.i686.rpm (plymouth-core-libs-0.8.3-27.el6.centos.i686.rpm) Using CRYPT000.RPM;1 for ./Packages/cryptsetup-luks-1.2.0-7.el6.i686.rpm (cryptsetup-luks-libs-1.2.0-7.el6.i686.rpm) Using NSS_S000.RPM;1 for ./Packages/nss-softokn-3.14.3-9.el6.i686.rpm (nss-softokn-freebl-3.14.3-9.el6.i686.rpm) Using P11_K000.RPM;1 for ./Packages/p11-kit-0.18.5-2.el6.i686.rpm (p11-kit-trust-0.18.5-2.el6.i686.rpm) Using NFS_U000.RPM;1 for ./Packages/nfs-utils-1.2.3-39.el6.i686.rpm (nfs-utils-lib-1.1.5-6.el6.i686.rpm) Using DEVIC005.RPM;1 for ./Packages/device-mapper-persistent-data-0.2.8-2.el6.i686.rpm (device-mapper-event-1.02.79-8.el6.i686.rpm) Using NCURS000.RPM;1 for ./Packages/ncurses-libs-5.7-3.20090208.el6.i686.rpm (ncurses-base-5.7-3.20090208.el6.i686.rpm) Using NCURS001.RPM;1 for ./Packages/ncurses-base-5.7-3.20090208.el6.i686.rpm (ncurses-5.7-3.20090208.el6.i686.rpm) Using COREU000.RPM;1 for ./Packages/coreutils-libs-8.4-31.el6.i686.rpm (coreutils-8.4-31.el6.i686.rpm) Writing: Initial PadblockStart Block 0 Done with: Initial PadblockBlock(s)16 Writing: Primary Volume Descriptor Start Block 16 Done with: Primary Volume Descriptor Block(s)1 Writing: Eltorito Volume Descriptor Start Block 17 Size of boot image is 4 sectors -No emulation Done with: Eltorito Volume Descriptor Block(s)1 Writing: Joliet Volume DescriptorStart Block 18 Done with: Joliet Volume DescriptorBlock(s)1 Writing: End Volume Descriptor Start Block 19 Done with: End Volume Descriptor Block(s)1 Writing: Version block Start Block 20 Done with: Version block Block(s)1 Writing: Path table Start Block 21 Done with: Path table Block(s)4 Writing: Joliet path table Start Block 25 Done with: Joliet path table Block(s)4 Writing: Directory tree Start Block 29 Done with: Directory tree Block(s)27 Writing: Joliet directory tree Start Block 56 Done with: Joliet directory tree Block(s)17 Writing: Directory tree cleanup Start Block 73 Done with: Directory tree cleanup Block(s)0 Writing: Extension recordStart Block 73 Done with: Extension recordBlock(s)1 Writing: The File(s) Start Block 74 3.02% done, estimate finish Sun Jan 18 05:17:14 2015 6.04% done, estimate finish Sun Jan 18 05:17:14 2015 9.06% done, estimate finish Sun Jan 18 05:17:14 2015 12.08% done, estimate finish Sun Jan 18 05:17:14 2015 15.09% done, estimate finish Sun Jan 18 05:17:14 2015 18.11% done, estimate finish Sun Jan 18 05:17:14 2015 21.13% done, estimate finish Sun Jan 18 05:17:14 2015 24.15% done, estimate finish Sun Jan 18 05:17:14 2015 27.16% done, estimate finish Sun Jan 18 05:17:14 2015 30.18% done, estimate finish Sun Jan 18 05:17:14 2015 33.20% done, estimate finish Sun Jan 18 05:17:14 2015 36.22% done, estimate finish Sun Jan 18 05:17:14 2015 39.24% done, estimate finish Sun Jan 18 05:17:14 2015 42.25% done, estimate finish Sun Jan 18 05:17:14 2015 45.28% done, estimate finish Sun Jan 18 05:17:14 2015 48.29% done, estimate finish Sun Jan 18 05:17:14 2015 51.31% done, estimate finish Sun Jan 18 05:17:14 2015 54.33% done, estimate finish Sun Jan 18 05:17:14 2015 57.34% done, estimate finish Sun Jan 18 05:17:14 2015 60.36% done, estimate finish Sun Jan 18 05:17:14 2015 63.38% done, estimate finish Sun Jan 18 05:17:14 2015 66.39% done, estimate finish Sun Jan 18 05:17:14 2015 69.42% done, estimate finish Sun Jan 18 05:17:14 2015 72.43% done, estimate finish Sun Jan 18 05:17:14 2015 75.45% done, estimate finish Sun Jan 18 05:17:14 2015 78.47% done, estimate finish Sun Jan 18 05:17:14 2015 81.49% done, estimate finish Sun Jan 18 05:17:14 2015 84.50% done, estimate finish Sun Jan 18 05:17:14 2015 87.52% done, estimate finish Sun Jan 18 05:17:14 2015 90.54% done, estimate finish Sun Jan 18 05:17:14 2015 93.56% done, estimate finish Sun Jan 18 05:17:14 2015 96.57% done, estimate finish Sun Jan 18 05:17:14 2015 99.60% done, estimate finish Sun Jan 18 05:17:14 2015 Total translation table size: 68712 Total rockridge attributes bytes: 30785 Total directory bytes: 49152 Path table size(bytes): 72 Done with: The File(s) Block(s)165455 Writing: Ending Padblock Start Block 165529 Done with: Ending Padblock Block(s)150 Max brk space used 61000 165679 extents written (323 MB)
這裏作的比較簡便,將安裝包也一塊兒打包到iso了,其實咱們使用了網絡安裝,安裝包不須要也能夠的,只要有linux引導三部曲(vmlinux,initrd,root分區信息)就能夠了,不過如今的新系統都比較豐滿了,包裝了不少東西進去,也懶得刪減了,畢竟自己也就幾百M。
2.安裝web 服務器 apache(能夠是ftp,nfs)
yum -y install httpd
默認安裝後配置文件在/etc/httpd/conf/httpd.conf,默認使用apache 用戶運行,80端口監聽,網頁存放目錄/var/www/html/
啓動apache(root用戶運行)
service httpd start
建立一個ks.cfg的kickstart配置(demo模板在/root/anaconda-ks.cfg),並放到web服務器apache 的網頁目錄,例如默認的目錄就是/var/www/html/
install url --url http://192.168.6.127/centos/ lang en_US.UTF-8 keyboard us network --onboot yes --device eth0 --bootproto dhcp --noipv6 --hostname=XXXX rootpw XXXX firewall --disabled authconfig --enableshadow --passalgo=sha512 selinux --disabled timezone --utc Asia/Shanghai bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet" clearpart --all --drives=sda part / --fstype=ext4 --size=7000 part /var/log --fstype=ext4 --size=1024 part swap --size=1024 part /workerfree --fstype=ext4 --size=30 --grow #repo --name="CentOS" --baseurl=cdrom:sr0 --cost=100 %packages --nobase @core %post --interpreter=/bin/bash ( cd /mnt /usr/bin/curl -O http://192.168.6.127/XXXX.tar.gz /bin/tar -zxpf XXXX.tar.gz cd XXXX /bin/sh install.sh )2>&1 >> /root/post-install.log %end reboot
注意修改權限755,起碼可讓apache服務器訪問這個文件
mkdir /var/www/html/centos chmod 755 /var/www/html/centos/isolinux/ks.cfg
這個位置就是ks=http://192.168.6.127/centos/isolinux/ks.cfg訪問的位置,遙相呼應的
將安裝光盤鏡像iso的掛載的目錄複製到web服務器apache的網頁目錄,達到能夠網頁訪問的效果
mkdir /var/www/html/centos cp -arp /tmp/isomake_dir/* /var/www/html/centos
這裏作的目的是網絡安裝,啓動盤讀到kickstart文件後轉到訪問網絡安裝鏡像的位置進行安裝
至此完成配置,便可試驗。
開機啓動選擇http
而後就一鍵安裝了
-r -rational-rock 使用Rock Ridge Extensions,並開放所有文件的讀取權限。
-J -joliet -J或-joliet 使用Joliet格式的目錄與文件名稱。
-b:啓動image
-c boot_catalog #指定啓動的boot catalog
Specifies the path and filename of the boot catalog, which is required for an El Torito bootable CD. The pathname must be relative to the source path specified to genisoimage. This file will be inserted into the output tree and not created in the source filesystem, so be sure the specified filename does not conflict with an existing file, or it will be excluded. Usually a name like boot.catalog is chosen. If -sort has not been specified, the boot catalog sorted with low priority (+1) to the beginning of the medium. If you don’t like this, you need to specify a sort weight of 0 for the boot catalog.
-no-emul-boot Boot image is 'no emulation' image即非模擬模式啓動
-boot-load-size 4 #指定啓動的分區,設置爲4是爲了兼容某些bios
Specifies the number of "virtual" (512-byte) sectors to load in no-emulation mode. The default is to load the entire boot file. Some BIOSes may have problems if this is not a multiple of 4.
-boot-info-table #指定啓動信息
Specifies that a 56-byte table with information of the CD-ROM layout will be patched in at offset 8 in the boot file. If this option is given, the boot file is modified in the source filesystem, so make a copy of this file if it cannot be easily regenerated! See the EL TORITO BOOT INFO TABLE section for a description of this table.
有興趣能夠自行man mkisofs
這裏我說說個人配置文件
install #安裝模式 url --url http://192.168.6.127/centos/ #使用url模式,也支持nfs,harddisk,cdrom,這裏就是說安裝方式 lang en_US.UTF-8 #我這裏不須要考慮中文 keyboard us #鍵盤制式 network --onboot yes --device eth0 --bootproto dhcp --noipv6 --hostname=XXXX #配置網絡相關信息 rootpw XXXXX #配置root密碼 firewall --disabled #默認關閉iptables authconfig --enableshadow --passalgo=sha512 #配置驗證方式,使用sha512加密密碼 selinux --disabled #默認關閉selinux timezone --utc Asia/Shanghai #時區 bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet" #引導內容,安裝引導程序grub到mbr,磁盤識別的順序是sda優先,使用auto rhgb quiet的內核啓動參數,該參數rhgb表示redhat graphics boot,就是會看到圖片來代替啓動過程當中顯示的文本信息,這些信息在啓動後用dmesg也能夠看到,quiet表示在啓動過程當中只有重要信息顯示,相似硬件自檢的消息不回顯示 clearpart --all --drives=sda #清理磁盤全部內容,清理的磁盤是sda盤,關於sda和hda,sdb的區別hda通常是指IDE接口的硬盤,hda通常指第一塊硬盤,相似的有hdb,hdc等,sda通常是指SATA接口的硬盤,sda通常指第一塊硬盤,相似的有sdb,sdc等 part / --fstype=ext4 --size=7000 #分區設置 part /var/log --fstype=ext4 --size=1024 part swap --size=1024 #swap配置 part /workerfree --fstype=ext4 --size=30 --grow #--grow表明增加到能夠用的最大 #repo --name="CentOS" --baseurl=cdrom:sr0 --cost=100 %packages --nobase #nobase是爲了防止彈出的警告說沒有basegroup的組件 @core #mini的iso只有core的group包能夠安裝 %post --interpreter=/bin/bash #配置安裝後的動做,這裏指定bash做爲環境變量和腳本執行工具 ( cd /mnt /usr/bin/curl -O http://192.168.6.127/XXXX.tar.gz /bin/tar -zxpf XXXX.tar.gz cd XXXX /bin/sh install.sh )2>&1 >> /root/post-install.log #自定義腳本命令或者命令合集,例如能夠下載文件,配置網絡等等,而且將內容的執行日誌輸出到指定的日誌 %end #結束%post的動做 reboot #安裝完成後自動重啓 ~
詳細能夠參考官方:
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Installation_Guide/s1-kickstart2-options.html
這裏也有幾個能夠看的翻譯文章,可是怎麼說呢,翻譯老是滯後,而且不必定翻譯對,最重要仍是要理解原文做者的意思,這樣才能搞懂,以不變應萬變,固然實操試驗纔是王道。
參考:http://www.cnblogs.com/xiaOt119/p/3143462.html
參考:http://bbs.linuxtone.org/thread-7539-1-1.html
Unable to read package metadata. This may be due to missing repodata directory. Please ensure that your install tree has been correctly generated. Failare: repodata/743fec56b2af0ce8d6ec82c47a4efafc2a4d18cddfa9683f29611cb18d1a33de-primary.sqlite.bz2 from anaconda-CentOS-201311271240.i386: [Ermo 256] No more mirrors to try.
這裏是由於iso通過解壓後將裏面的bz或者gz壓縮文件解壓了,致使安裝程序的安裝過程處理失敗,解決辦法就是找一個完整的安裝iso,不要解壓,用iso的掛載方式從新讀取repodata下的文件,而後覆蓋你的系統安裝資源便可
引用參考:http://stackoverflow.com/questions/21637068/unable-to-read-package-metadata-this-may-be-due-to-missing-repodata-directory
原文連接:http://www.godblessyuan.com/2015/01/24/kickstart_http_install_centos_no_pxe/