13 April 2015
這篇要講怎麼客製化你自己想要的ubuntu ISO,
會講解一些preseed的參數,
preseed file是debian系列的automation config,而redhat系列就是用kickstart,
debian系列就是根據preseed file去進行安裝.
因此ubuntu也是用preseed,當然ubuntu也可以用kickstart,只是“似乎”支援沒有那麼好!?
題外話,雖然說preseed file是debian的標準格式,
但有一點要記得,debian自己本身的preseed file,並不是每一個command,ubuntu都能接受!


1. Download ubuntu ISO

首先,你要有一個ubuntu的ISO,
這裏我選用ubuntu 12.04的ISO,
wget http://releases.ubuntu.com/12.04.5/ubuntu-12.04.5-server-amd64.iso


2. Mount the ISO

接著要把ISO內的東西,先mount起來,接著再copy出來,
mkdir -p /mnt/tmp /mnt/iso
mount -o loop ./ubuntu-12.04.5-server-amd64.iso /mnt/tmp
rsyn -av /mnt/tmp /mnt/iso
umount /mnt/tmp

3. Add boot menu option

因為要客製化你自己的ISO,
所以我們要在boot menu中,新增一個屬於我們自己的menu,
首先先開啟這個isolinux/txt.cfg檔案
vim /mnt/iso/isolinux/txt.cfg

打開以後應該會看到下面的內容,

我們就在label install之前新增一筆boot menu,
內容如下,
label YourCustomizedISO
menu label ^Customized ISO
kernel /install/vmlinuz
append file=/cdrom/preseed/customized.seed initrd=/install/initrd.gz quiet --


4. Add pressed file

接著就要新增一個客製化的preseed file,
vim /mnt/iso/preseed/customized.seed

內容如下,這份preseed讓你可以不用輸入任何按鍵就進行自動安裝!
我覺得還蠻淺顯易懂的,每個section都有標註是在做什麼,
比較值得注意的是『Advance command』這個section,
這section裡面放的是,『安裝完ubuntu以後,要做些什麼事情。』
但是如果你想要在『安裝之前』或者『partition之前或者之後』做些事情,都是可以的。
只不過這個example,我們是在『安裝完ubuntu以後』。

『preseed/late_command』就是『安裝完ubuntu以後』的意思。
不過這邊可能大家會覺得很奇怪,為什麼在late_command中,
一開始要cp至/target目錄?/target目錄又是什麼?
大家在安裝ubuntu的時候,可以change console一下,這時候cd至/target底下,
你會發現其實裡面就是你真正ubuntu安裝的位置!
那/target外面的東西是誰的呢(bin, lib, etc,....)?
其實是busybox的,所以你一定得把你想要的東西搬到/target裡面,
這樣在你安裝完以後,該東西才會存在。
接著還有另一段奇怪的command:in-target,
『in-target』,簡單的說就是chroot /target而已,
你也可以用chroot /target去取代『in-target』。

####### Localization #######
d-i debian-installer/locale string en_US
d-i debian-installer/language string en
d-i debian-installer/country string US


####### Keyboard selection #######
d-i console-setup/ask_detect boolean false
d-i console-setup/layoutcode string us
d-i console-setup/modelcode string pc105
d-i kbd-chooser/method string us
d-i keyboard-configuration/layout string USA
d-i keyboard-configuration/variant string USA

####### Network configuration #######
#d-i netcfg/choose_interface select auto
d-i netcfg/choose_interface select eth0
d-i netcfg/get_hostname string ubuntu
d-i netcfg/get_domain string
# configure the network manually
#d-i netcfg/disable_autoconfig boolean true
# configure the network automatically
d-i netcfg/get_nameservers string 8.8.8.8
d-i netcfg/get_ipaddress string 172.16.131.138
d-i netcfg/get_netmask string 255.255.255.0
d-i netcfg/get_gateway string 172.16.131.2
d-i netcfg/confirm_static boolean true

####### Apt setup #######
d-i apt-setup/security-updates boolean false
d-i apt-setup/restricted boolean false
d-i apt-setup/universe boolean false
d-i apt-setup/backports boolean false
d-i apt-setup/security boolean false
d-i mirror/http/proxy string

####### Base system installation #######
d-i debian-installer/splash boolean false
d-i base-installer/install-recommends boolean true
d-i base-installer/kernel/altmeta string lts-saucy

####### Clock and time zone setup #######
d-i clock-setup/utc boolean true
d-i clock-setup/utc-auto boolean true
d-i time/zone string UTC

####### Boot loader installation #######
d-i finish-install/reboot_in_progress note
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true

####### Partitioning using LVM #######
d-i partman-auto-lvm/guided_size string max
d-i partman-auto/choose_recipe select atomic
d-i partman-auto/method string lvm
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-lvm/device_remove_lvm boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/confirm_write_new_label boolean true

####### User #######
d-i passwd/root-login boolean true
d-i passwd/root-password password 1234
d-i passwd/root-password-again password 1234
d-i user-setup/allow-password-weak boolean true
# create user or not
d-i passwd/make-user boolean false
#d-i user-setup/encrypt-home boolean false
#d-i passwd/user-fullname string ken
#d-i passwd/username string ken
#d-i passwd/user-password password 123456
#d-i passwd/user-password-again password 123456

####### Package selection #######
d-i pkgsel/include string openssh-server vim
d-i pkgsel/install-language-support boolean false
d-i pkgsel/update-policy select none
d-i pkgsel/upgrade select none

tasksel tasksel/first multiselect standard, ubuntu-server

####### Advance command #######
d-i preseed/late_command string \
cp /cdrom/preseed/setup-something.bash /target/tmp/setup-something.bash && in-target chmod +x /tmp/setup-something.bash && in-target /bin/bash /tmp/setup-something.bash




5. Make an ISO

完成上面的步驟後,
剩下最後一步就完成了,
把剛剛copy出來的內容,在包成一個ISO就好了。
mkisofs -r -R -J -T -v -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -z -iso-level 4 -c isolinux/isolinux.cat -o custom.iso /mnt/iso

大概等個20秒以後,就會看到一個custom.iso,就代表你成功了!











blog comments powered by Disqus