歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Anaconda Kickstart

Anaconda Kickstart

日期:2017/2/28 14:50:53   编辑:Linux教程
linux安裝大致可以分為2個階段 第一階段:anaconda 階段 此階段是linux的預安裝環境,提供linux安裝選項的一個接口,可以將它比作是window中的PE環境 第二階段:install 階段 該階段系統會按照anaconda 階段設定的參數自動安裝 anaconda有兩種模式: 交互式:和普通安裝一樣,按照提示選擇選項一步步的安裝 非交互式:通過讀取kickstart文件的配置,進行自動安裝 而在安裝linux過程中,獲取ks.cfg文件的方式有多種,如直接在cdrom中獲取,常見的形式還有http,ftp,nfs等方式 cdrom和硬盤: ks=cdrom:/dir/ks.cfg ks=hd:/dir/ks.cfg http和ftp: ks=http://domain.com/dir/ks.cfg ks=ftp://domain.com/dir/ks.cfg NFS: ks=nfs:domain.com:/dir/ks.cfg 在使用ks.cfg之前,需要先引導啟動環境,引導方式有cdrom、usb、PXE等。在引導進入anaconda後,即可通過讀取ks.cfg來進行系統的自動安裝 ks.cfg文件會在安裝linux後,根據用戶的安裝選項自動生成在root家目錄,即anaconda_ks.cfg ks.cfg文件組成大致分為3段 1.命令段: 鍵盤類型,語言,安裝方式等系統的配置,有必選項和可選項,如果缺少某項必選項,安裝時會中斷並提示用戶選擇此項的選項 2.軟件包段: %packages @groupname #指定安裝的包組 package_name #指定安裝的包 -package_name #指定不安裝的包 3.腳本段(可選): %pre :預安裝腳本 (由於只依賴於啟動鏡像,支持的命令很少) %post:後安裝腳本(基本支持所有命令) 更多關於Anaconda Kickstart的內容請看:http://fedoraproject.org/wiki/Anaconda/Kickstart
  1. [root@rhel6 ~]# cat /var/ftp/pub/ks.cfg
  2. ######################################################################
  3. ############## 1 Main Begin
  4. ############## 1.1 Text,Key,Keyboard,Lang,Net Begin
  5. ######################################################################
  6. # platform=x86, AMD64, 或 Intel EM64T # 通過文本界面進行安裝
  7. text
  8. # 安裝/升級
  9. install
  10. # 如果是RHEL5的系統,會要求輸入key,這裡配置為跳過,如果不配置安裝時會停在那裡要求用戶輸入key
  11. key--skip
  12. # 安裝方式(cdrom/hdisk/http/ftp/nfs),指定安裝源的路徑
  13. nfs --server=192.168.0.90 --dir=/var/ftp/pub
  14. lang en_US.UTF-8
  15. keyboard us
  16. # 通過DHCP獲取IP地址
  17. network --bootproto dhcp
  18. ######################################################################
  19. ############## 1.1 Text,Key,Keyborad,Lang,Net End
  20. ############## 1.2 Partition Begin
  21. ######################################################################
  22. # Partition 10000M
  23. %include /tmp/partitioning
  24. ######################################################################
  25. ############## 1.2 Partition End
  26. ############## 1.3 Timezone,X,passwd,security,bootloader Begin
  27. ######################################################################
  28. timezone --utc Asia/Shanghai
  29. graphical
  30. # 設置root用戶的密碼
  31. rootpw RedHat
  32. # 禁用防火牆
  33. firewall --disabled
  34. authconfig --useshadow --passalgo=md5
  35. # 激活SELINUX
  36. selinux --enforcing
  37. # 首次引導時,禁用設置代理
  38. firstboot --disable
  39. # 安裝Grub到MBR
  40. bootloader --location=mbr
  41. # 安裝完成後重啟
  42. reboot
  43. ######################################################################
  44. ############## 1.3 Timezone,X,passwd,security,bootloader End
  45. ############## 1 Main End
  46. ############## 2 Packages Begin
  47. ######################################################################
  48. %packages
  49. # 安裝軟件包組
  50. @Base
  51. @Core
  52. @basic-desktop
  53. @desktop-debugging
  54. @desktop-platform
  55. @fonts
  56. @general-desktop
  57. @graphical-admin-tools
  58. @input-methods
  59. @legacy-x
  60. @remote-desktop-clients
  61. @x11
  62. # 安裝軟件包
  63. coreutils
  64. elfutils
  65. elfutils-libelf
  66. elinks
  67. enscript
  68. firefox
  69. gcc
  70. gimp
  71. gimp-data-extras
  72. gimp-print-plugin
  73. gnome-icon-theme
  74. gstreamer
  75. gstreamer-tools
  76. libIDL
  77. libcap
  78. libgsf
  79. libraw1394
  80. mutt
  81. nautilus-cd-burner
  82. ntp
  83. openmotif
  84. openssh
  85. openssh-clients
  86. openssh-server
  87. pyorbit
  88. samba-client
  89. samba-common
  90. startup-notification
  91. ttmkfdir
  92. vim-enhanced
  93. vnc
  94. %end
  95. ######################################################################
  96. ############## 2 Packages End
  97. ############## 3 Post Begin
  98. ############## Network Begin
  99. ######################################################################
  100. %post
  101. # 固定安裝後系統的IP地址
  102. cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << EOF
  103. DEVICE=eth0
  104. BOOTPROTO=none
  105. ONBOOT=yes
  106. NETMASK=255.255.255.0
  107. IPADDR=XXX
  108. GATEWAY=192.168.0.90
  109. TYPE=Ethernet
  110. USERCTL=no
  111. IPV6INIT=no
  112. PEERDNS=yes
  113. EOF
  114. # 提取IP地址
  115. v_ip=`ifconfig eth0 | head -n 2 | tail -n 1 | cut -d ':' -f 2 | cut -d ' ' -f 1`
  116. # 替換ifcfg-eth0文件中IPADDR的xxx為$v_ip
  117. perl -pi -e "s,XXX,$v_ip," /etc/sysconfig/network-scripts/ifcfg-eth0
  118. %end
  119. ######################################################################
  120. ############## Network End
  121. ############## 3 Post End
  122. ######################################################################
  123. %pre
  124. echo "Starting PRE" > /dev/tty2
  125. # 以下兩行在push 64位系統的時候是必須的(Bug)
  126. cd /mnt/
  127. ln -s Source/Packages ./
  128. v_pci0=$(udevinfo -ap /sys/class/net/eth0 | grep 'ID==' | head -n 1)
  129. v_driver0=$(udevinfo -ap /sys/class/net/eth0 | grep 'DRIVER==' | head -n 1)
  130. v_mac0=$(ifconfig eth0 | grep HWaddr | cut -d ' ' -f 11)
  131. v_ip_short=$(grep $v_mac0 /mnt/stage2/workstation.list | cut -d '-' -f 1)
  132. v_ip=192.168.0.$v_ip_short
  133. if [ ! -z $v_ip_short ]
  134. then
  135. ifconfig eth0 $v_ip
  136. fi
  137. # partitions
  138. if
  139. grep -q hda /proc/partitions
  140. then
  141. disktype=hda
  142. else
  143. disktype=sda
  144. fi
  145. # 設置分區
  146. cat >> /tmp/partitioning <<EOF
  147. # 清除主引導記錄MBR
  148. zerombr yes
  149. # 清除所有的分區
  150. clearpart --all
  151. # 設置/boot分區為50MB,文件系統格式為ext4
  152. part /boot --fstype=ext4 --size=50
  153. # 設置swqp分區為512MB
  154. part swap --size=512
  155. # 創建8GB的PV
  156. part pv.Lrhel6 --size=8000
  157. # 創建 VG
  158. volgroup Lrhel6 --pesize=32768 pv.Lrhel6
  159. # 創建 LV ,並掛載到根分區中
  160. logvol / --vgname=Lrhel6 --size=7000 --name=root
  161. EOF
  162. %end
Copyright © Linux教程網 All Rights Reserved