一、目的
减少操作系统安装过程中人机交互过程,实现选择光盘安装后,无需其他人机交互过程即可自动完成操作系统的安装。
二、环境和软件工具
环境:Linux Ubuntu/CentOS操作系统(其他发行版未作尝试)
软件:mkisofs,xorriso
软件安装:
CentOS : yum install mkisofs xorriso -y
Ubuntu: sudo apt install -y mkisofs xorriso
三、iso重新打包
1.Ubuntu
1.1原料
我是用ubuntu-16.04.3-server-arm64.iso挂载出来再做一份拷贝,如果有现成的编译环境也是可以的。
$ mkdir mnt/ ubuntu/
$ ls -al
mnt/
ubuntu/
ubuntu-16.04.3-server-arm64.iso
$ sudo mount ubuntu-16.04.3-server-arm64.iso mnt/
$ cp -rf ./mnt/* ./mnt/.disk/ ./ubuntu/
$ sudo umount ./mnt/
1.2修改/添加配置文件
1.2.1.boot/grub/grub.cfg
$ vim ubuntu/boot/grub/grub.cfg
set menu_color_normal=cyan/blue
set menu_color_highlight=white/blue
set timeout=60
insmod gzio
menuentry 'Install Ubuntu' {
set background_color=black
linux /install/vmlinuz auto-install/enable=true file=/cdrom/preseed/ubuntu.seed
initrd /install/initrd.gz
}
(1)set timeout=60 ##设置60秒无应答自动选择默认项
(2)auto-install/enable=true ##允许自动安装模式
(3)file=/cdrom/preseed/ubuntu.seed ##指定自动安装的preseed文件。
(4)如果想将正常发行的iso和可以自动安装的iso合并为一个,可以添加其他的菜单项,但是一定确保上面这条配置是默认项,并配置超时操作。
1.2.2.preseed文件preseed/ubuntu.seed
$ vim ubuntu/preseed/ubuntu.seed
#########################################################################
## CDROM auto install
#########################################################################
# Continue install on "no kernel modules were found for this kernel"
#d-i anna/no_kernel_modules boolean true
d-i auto-install/enable boolean true
## Set country, language and keyboard map
d-i debian-installer/language string en
d-i debian-installer/country string US
d-i debain-install/locale string en_US.UTF-8
# Optionally specify additional locales to be generated.
#d-i localechooser/supported-locales multiselect zh_CH.UTF-8, C.UTF-8, en_US.UTF-8
#d-i keyboard-configuration/xkb-keymap select us
## Disable automatic (interactive) keymap detection.
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/layoutcode string us
## To select a variant of the selected layout (if you leave this out, the
## basic form of the layout will be used):
#d-i keyboard-configuration/variantcode string dvorak
##net config
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string unassigned-hostname
d-i netcfg/get_domain string unassigned-domain
## set root password
d-i passwd/root-login boolean root
d-i passwd/root-password password root
d-i passwd/root-password-again password root
d-i user-setup/allow-password-weak boolean true
## creat user
d-i passwd/make-user boolean true
d-i passwd/user-fullname string User
d-i passwd/username string user
d-i passwd/user-password-crypted password userpassword
d-i passwd/user-password-again password userpassword
## Encrypt your home directory NO
d-i user-setup/encrypt-home boolean false
## Controls whether or not the hardware clock is set to UTC.
d-i clock-setup/utc boolean true
d-i time/zone string Asia/Shanghai
## Disk usage
d-i partman-auto/disk string /dev/sda
#d-i partman-auto/method string lvm
#d-i partman-auto-lvm/guided_size string max
d-i partman-auto/method string regular
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-lvm/confirm_nooverwrite boolean true
d-i partman-auto/choose_recipe select atomic
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
## umount /dev/sda
d-i partman/unmount_active boolean true
d-i preseed/early_command string umount /media || true
#set mirror CD 安装不需要设置:mirror
#d-i mirror/country string manual
#d-i mirror/http/hostname string ports.ubuntu.com
#d-i mirror/http/directory string /ubuntu-ports/
#d-i mirror/http/proxy string
#d-i mirror/http/mirror select 192.168.50.122:8083
#d-i mirror/http/mirror select 192.168.1.107:80
## apt-setup
#d-i apt-setup/non-free boolean true
#d-i apt-setup/contrib boolean true
d-i apt-setup/use_mirror boolean false
d-i apt-setup/restricted boolean true
d-i apt-setup/universe boolean true
d-i apt-setup/backports boolean true
d-i apt-setup/services-select multiselect security
d-i apt-setup/security_host string security.ubuntu.com
d-i apt-setup/security_path string /ubuntu
d-i pkgsel/update-policy select none
##install software
tasksel tasksel/first multiselect standard
## Individual additional packages to install
d-i pkgsel/include string openssh-server vim
d-i pkgsel/upgrade select none
popularity-contest popularity-contest/participate boolean false
##Grub and bootloder
## This is fairly safe to set, it makes grub install automatically to the MBR
## if no other operating system is detected on the machine.
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
## Avoid that last message about the install being complete.
d-i finish-install/keep-consoles boolean true
d-i finish-install/reboot_in_progress note
d-i cdrom-detect/eject boolean false
1.3 重新打包iso
$ sudo xorriso -as mkisofs -r -checksum_algorithm_iso md5,sha1 -V 'Ubuntu-Server 16.04.3 LTS arm64' \
-o ./new-ubuntu-16.04.3-server-arm64.iso -J -joliet-long -cache-inodes -e boot/grub/efi.img \
-no-emul-boot -append_partition 2 0xef ubuntu/boot/grub/efi.img -partition_cyl_align all ubuntu/
生成的iso就在当前目录下。
2.CentOS
2.1原料
我是用CentOS-7-aarch64-Everything.iso挂载出来再做一份拷贝,如果有现成的编译环境也是可以的。(用的是CentOS7.4-1708-ARM服务器版iso)
$ mkdir mnt/ centos/
$ ls -al
centos/
mnt/
CentOS-7-aarch64-Everything.iso
$ sudo mount CentOS-7-aarch64-Everything.iso mnt/
$ sudo cp -rf mnt/* mnt/.discinfo mnt/.treeinfo centos/
$ sudo umount ./mnt/
2.2修改/添加配置文件
2.2.1grub菜单EFI/BOOT/grub.cfg对默认项内容修改:
$ vim centos/EFI/BOOT/grub.cfg
set timeout=60
### END /etc/grub.d/00_header ###
search --no-floppy --set=root -l 'CentOS 7 aarch64'
### BEGIN /etc/grub.d/10_linux ###
menuentry 'install CentOS Linux AltArch 7' --class red --class gnu-linux --class gnu --class os {
linux /images/pxeboot/vmlinuz inst.stage2=hd:LABEL=CentOS\x207\x20aarch64 ip=dhcp acpi=force inst.ks=cdrom:/ks-iso.cfg
initrd /images/pxeboot/initrd.img
}
(1)inst.stage2=hd:LABEL=CentOS\x207\x20aarch64 ##第二部执行的空间LiveOS的父目录位置。
(2)inst.ks=file:/ks-iso.cfg ##自动安装用到的kickstart文件路径。
(3)acpi的设置根据具体设备而定,有些可能需要设置为off
2.2.2.kickstart文件
$ vim centos/ks-iso.cfg
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
cdrom
# Use text mode install
text
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts=''
# System language
lang en_US.UTF-8
# Network information
network --bootproto=dhcp --device=eth0 --ipv6=auto --activate
network --bootproto=dhcp --device=eth1 --onboot=off --ipv6=auto
network --bootproto=dhcp --device=eth2 --onboot=off --ipv6=auto
network --bootproto=dhcp --device=eth3 --onboot=off --ipv6=auto
network --hostname=localhost.localdomain
# Root password
rootpw --iscrypted $6$Kd3yxUtwpOk3fJ.M$KnTt/6pHJzXWYcKGQbqqkifavlMLrQcuOd6OAud97qD2IbFcWGtljsRVo9qWSSHj0Mcy.HmyLZ0JsDlq8mQ7B/
# System services
services --enabled="chronyd"
# Do not configure the X Window System
skipx
# System timezone
timezone US/Alaska --isUtc
user --groups=user,wheel --name=user --password=$6$aBUT2gAUGjmQEeKF$.y8qtYgDX0gZZyiAVbBwlCfsNgPUykgP9HP82vzAcRJMz2E0ynnHpthBaSVlJWk0a8EmUZJDD6marUZhH7mkG1 --iscrypted --gecos="user"
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
clearpart --all --initlabel --drives=sda
reboot
%post
#安装完成后的操作
%end
%packages
#需要安装的软件包
%end
以上自动安装配置只是提供一种方案。
2.3 重新打包iso
$ cd centos/
$ sudo genisoimage -e images/efiboot.img -no-emul-boot -T -J -R -c boot.catalog -hide boot.catalog -V "CentOS 7 aarch64"\
-o ../CentOS-7-aarch64-Everything.iso .