ubuntu自動化安裝關(guān)鍵點

1. 鏡像源

歷史版本下載地址:http://old-releases.ubuntu.com/releases/

選擇服務(wù)器版本64位adm架構(gòu)的鏡像作為安裝源,例如:ubuntu-18.04.4-server-amd64.iso。(此種版本無需連公網(wǎng)末贾,安裝源包含所有安裝信息)

如果想使用最新版本作為安裝源,只能找到live版构回,例如ubuntu-20.04-live-server-amd64.iso。(此種版本需要連公網(wǎng)绣张,或是能訪問到軟件源地址惕蹄,以便裝機過程中安裝必要的軟件)

2. 引導(dǎo)文件

  1. pxe的菜單可參考如下:
label Ubuntu 18.X
  menu label Ubuntu 18.X
  kernel http://192.168.8.101/iso/ubuntu-18.04/install/netboot/ubuntu-installer/amd64/linux
  append initrd=http://192.168.8.101/iso/ubuntu-18.04/install/netboot/ubuntu-installer/amd64/initrd.gz preseed/url=http://192.168.8.101/ks/preseed.cfg ksdevice=bootif net.ifnames=0 biosdevname=0 rd.driver.pre=mlx5_core,i40e,ixgbe ip=dhcp 
  ipappend 2
  1. 自動選擇語言狂秦、鍵盤灌侣、國家

方法1:如下三項添加到pxe菜單中

debian-installer/locale=en_US
keyboard-configuration/layoutcode=us
netcfg/get_hostname=unassigned-hostname

方法2:添加到pxe環(huán)境中
解壓安裝源中的/install/netboot/ubuntu-installer/amd64/initrd.gz文件,在解壓后的根目錄下創(chuàng)建preseed.cfg裂问、

# 解壓命令參考
gzip -d initrd.gz
cpio -ivmd < ../initrd

# 添加文件內(nèi)容參考
[root@pxe-01 rootfs]# ls
bin  dev  etc  init  initrd  lib  lib64  media  mnt  preseed.cfg  proc  run  sbin  sys  tmp  usr  var
[root@pxe-01 rootfs]# cat preseed.cfg 
d-i debian-installer/locale string en_US
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/layoutcode string us
d-i keyboard-configuration/xkb-keymap select us
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string ubuntu18
d-i netcfg/get_domain string localdomain

# 壓縮
find .|cpio -o -H newc |gzip > ../initrd.gz

3. 應(yīng)答文件

僅供參考

# 安裝前將debconf命令的優(yōu)先級調(diào)高侧啼,這樣可防止不必要的彈窗
d-i auto-install/enable boolean true
d-i debconf/priority string critical

# 選擇語言
d-i debian-installer/locale string en_US
d-i localechooser/supported-locales multiselect en_US.UTF-8

# 選擇鍵盤
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/layoutcode string us
d-i keyboard-configuration/xkb-keymap select us

# 選擇獲取ip地址的方式和主機名
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string unassigned-hostname
d-i netcfg/get_domain string localdomain
d-i netcfg/wireless_wep string

# 選擇國家,這里可以為空
d-i mirror/country string manual

# 選擇訪問公網(wǎng)時的代理服務(wù)
#d-i mirror/http/proxy string http://192.168.192.8:8088
d-i mirror/http/proxy string 

# 選擇鏡像所在國家堪簿,最好選上中國的
d-i mirror/http/mirror select cn.archive.ubuntu.com

# 賬號密碼的一些配置
d-i passwd/root-login boolean true
d-i passwd/make-user boolean false
d-i passwd/root-password-crypted password $6$EBSccHsW$DuRH3N5t9UEYjuICQ7Q1eAHDCF68zHHcnN5P0QSWDyPVcaTMKhXsgZ2o0Ly7iwSgSo7f3tz9G9tqbgxXK2vQl/
#d-i passwd/root-password password r00tme
#d-i passwd/root-password-again password r00tme
d-i user-setup/allow-password-weak boolean true
d-i user-setup/encrypt-home boolean false

# 是否時間同步
d-i time/zone string Asia/Shanghai
d-i clock-setup/ntp-server string ntp.ubuntu.com
d-i clock-setup/utc boolean true
d-i clock-setup/ntp boolean true

# This first command is run as early as possible, just after preseeding is read.
# 當(dāng)本文件讀取后痊乾,先運行如下命令
d-i preseed/early_command string \
    echo $(grep dhcp-server-identifier /var/lib/dhcp/dhclient* |tail -n1 |egrep -o '([0-9]{1,3}\.){3}[0-9]{1,3}') > /tmp/pxe_server;\
    wget -O /tmp/ubuntu_preseed_early_script.sh http://$(cat /tmp/pxe_server)/scripts/ubuntu_preseed_early_script.sh ;\
    sh /tmp/ubuntu_preseed_early_script.sh ;\
    debconf-set-selections /tmp/preseed_early.cfg
#ubuntu_preseed_early_script.sh腳本用于生成/tmp/preseed_early.cfg,然后再包含到本文件中來椭更,被包含的內(nèi)容如下
#(這里也需要注意下哪审,如果安裝Ubuntu最新版,將此處配置為公網(wǎng)的軟件源)
#d-i mirror/http/hostname string 192.168.192.8
#d-i mirror/http/directory string /iso/ubuntu-18.04
#d-i live-installer/net-image string http://192.168.192.8/iso/ubuntu-18.04/install/filesystem.squashfs

# This command is run immediately before the partitioner starts.
d-i partman/early_command string \
    wget -O /tmp/ubuntu_partman_early_script.sh http://$(cat /tmp/pxe_server)/scripts/ubuntu_partman_early_script.sh ;\
    sh /tmp/ubuntu_partman_early_script.sh ;\
    debconf-set-selections /tmp/partman_early.cfg
#ubuntu_partman_early_script.sh腳本用于生成/tmp/partman_early.cfg虑瀑,其內(nèi)容如下
#d-i partman-auto/disk string /dev/sdb
#d-i grub-installer/bootdev string /dev/sdb
#d-i partman-auto/expert_recipe string                         \
#      boot-root ::                                            \
#        2     4   2   free                                    \
#                      $iflabel{ gpt }                         \
#                      method{ biosgrub }                      \
#        .                                                     \
#        1536  3  1536 ext4                                    \
#                      $primary{ } $bootable{ }                \
#                      method{ format } format{ }              \
#                      use_filesystem{ } filesystem{ ext4 }    \
#                      mountpoint{ /boot }                     \
#        .                                                     \
#        8192  2  8192 linux-swap                              \
#                      method{ swap } format{ }                \
#        .                                                     \
#        10240 1  -1   ext4                                    \
#                      $primary{ }                             \
#                      method{ format } format{ }              \
#                      use_filesystem{ } filesystem{ ext4 }    \
#                      mountpoint{ / }                         \
#        .   

# This command is run just before the install finishes.
# 安裝完成之后執(zhí)行初始化腳本
d-i preseed/late_command string \
    cp /tmp/pxe_server /target/opt/pxe_server; \
    in-target wget -O /opt/ubuntu_preseed_late_script.sh http://$(cat /tmp/pxe_server)/scripts/ubuntu_preseed_late_script.sh; \
    in-target bash /opt/ubuntu_preseed_late_script.sh

# 遠程執(zhí)行腳本
#d-i preseed/run string http://192.168.192.8/scripts/ubuntu_preseed_run_script.sh
# 相當(dāng)于ks的include湿滓,但是它訪問的是網(wǎng)絡(luò)上的文件,而不是本地文件
#d-i preseed/include_command string debconf-set grub-installer/bootdev `cat /tmp/os_disk`

# 使用的盤符和分區(qū)方法
d-i partman-auto/disk string default
d-i partman-auto/method string regular
d-i partman/unmount_active boolean true
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-basicfilesystems/choose_label string gpt
d-i partman-basicfilesystems/default_label string gpt
d-i partman-partitioning/choose_label string gpt
d-i partman-partitioning/default_label string gpt
d-i partman/choose_label string gpt
d-i partman/default_label string gpt
d-i partman-partitioning/choose_label select gpt
d-i partman-auto/choose_recipe select boot-root
d-i partman-partitioning/confirm_write_new_label boolean true
#d-i partman/choose_partition select finish
d-i partman/choose_partition select Finish partitioning and write changes to disk
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true

# Use the following option to add additional boot parameters for the installed system
d-i debian-installer/add-kernel-opts string nousb net.ifnames=0 biosdevname=0 rd.driver.pre=mlx5_core,i40e,ixgbe

# The kernel image (meta) package to be installed; "none" can be used if no kernel is to be installed.
d-i base-installer/kernel/image string linux-generic

# 最終也會配置到/etc/apt/sources.list里面
d-i apt-setup/security_host string 192.168.192.8
d-i apt-setup/security_path string /iso/ubuntu-18.04

# 安裝時是否驗證舌狗,注釋與否好像影響不大
d-i debian-installer/allow_unauthenticated boolean true

# 安裝系統(tǒng)的版本和軟件
tasksel tasksel/first multiselect standard system utilities, OpenSSH server
d-i pkgsel/include string openssh-server vim

# 是否自動升級
d-i pkgsel/upgrade select none
d-i pkgsel/language-packs multiselect en, zh
d-i pkgsel/update-policy select none

# 安裝grub
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean false
d-i finish-install/reboot_in_progress note

4. 啟動畫面

將圖形界面啟動改成文本啟動
修改:/etc/default/grub

  1. GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" 改為GRUB_CMDLINE_LINUX_DEFAULT="text"
  2. 取消注釋GRUB_TERMINAL=console
  3. 更新grub叽奥,執(zhí)行update-grub
  4. 設(shè)置默認啟動級別,執(zhí)行systemctl set-default multi-user.target

5. 其它常用設(shè)置

允許root登錄

sed -i s/prohibit-password/yes/g /etc/ssh/sshd_config
sed -i s/\#PermitRootLogin/PermitRootLogin/g /etc/ssh/sshd_config

取消重啟清空/tmp

echo 'd /tmp 1777 root root 30d' >> /etc/tmpfiles.d/tmp.conf

6. pxe環(huán)境添加工具

dpkg -X 軟件包名稱.deb ./rootfs
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末把夸,一起剝皮案震驚了整個濱河市而线,隨后出現(xiàn)的幾起案子铭污,更是在濱河造成了極大的恐慌恋日,老刑警劉巖膀篮,帶你破解...
    沈念sama閱讀 212,718評論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異岂膳,居然都是意外死亡誓竿,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,683評論 3 385
  • 文/潘曉璐 我一進店門谈截,熙熙樓的掌柜王于貴愁眉苦臉地迎上來筷屡,“玉大人,你說我怎么就攤上這事簸喂”兴溃” “怎么了?”我有些...
    開封第一講書人閱讀 158,207評論 0 348
  • 文/不壞的土叔 我叫張陵喻鳄,是天一觀的道長扼倘。 經(jīng)常有香客問我,道長除呵,這世上最難降的妖魔是什么再菊? 我笑而不...
    開封第一講書人閱讀 56,755評論 1 284
  • 正文 為了忘掉前任,我火速辦了婚禮颜曾,結(jié)果婚禮上纠拔,老公的妹妹穿的比我還像新娘。我一直安慰自己泛豪,他們只是感情好稠诲,可當(dāng)我...
    茶點故事閱讀 65,862評論 6 386
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著候址,像睡著了一般吕粹。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上岗仑,一...
    開封第一講書人閱讀 50,050評論 1 291
  • 那天匹耕,我揣著相機與錄音,去河邊找鬼荠雕。 笑死稳其,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的炸卑。 我是一名探鬼主播既鞠,決...
    沈念sama閱讀 39,136評論 3 410
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼盖文!你這毒婦竟也來了嘱蛋?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,882評論 0 268
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎洒敏,沒想到半個月后龄恋,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,330評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡凶伙,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,651評論 2 327
  • 正文 我和宋清朗相戀三年郭毕,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片函荣。...
    茶點故事閱讀 38,789評論 1 341
  • 序言:一個原本活蹦亂跳的男人離奇死亡显押,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出傻挂,到底是詐尸還是另有隱情乘碑,我是刑警寧澤,帶...
    沈念sama閱讀 34,477評論 4 333
  • 正文 年R本政府宣布金拒,位于F島的核電站蝉仇,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏殖蚕。R本人自食惡果不足惜轿衔,卻給世界環(huán)境...
    茶點故事閱讀 40,135評論 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望睦疫。 院中可真熱鬧害驹,春花似錦、人聲如沸蛤育。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,864評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽瓦糕。三九已至底洗,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間咕娄,已是汗流浹背亥揖。 一陣腳步聲響...
    開封第一講書人閱讀 32,099評論 1 267
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留圣勒,地道東北人费变。 一個月前我還...
    沈念sama閱讀 46,598評論 2 362
  • 正文 我出身青樓,卻偏偏與公主長得像圣贸,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子滑负,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 43,697評論 2 351

推薦閱讀更多精彩內(nèi)容