一、linux系统安装过程
1、总体流程及概述
POST --> Bootloader (kernel+ramdisk) --> anaconda
①安装系统也需要先加载内核,内核初始化完毕后会执行安装程序anaconda。
②若待安装系统的硬盘未被使用过或无bootloader,接好安装介质后,BIOS会自动将安装介质作为引导设备;若硬盘上已有系统,则需要进入BIOS界面将安装介质调整为第一引导设备。
③安装介质:光盘、U盘、支持PXE的网卡等
补充:如何在虚拟机中进入BIOS界面?(以VMware为例)
方法一:刚开机时快速按F2键
方法二:
2、启动安装过程的引导参数
■系统光盘中几个重要的目录:
isolinux:存放着与安装引导相关的文件
isolinux.bin:bootloader的第二阶段
isolinux.cfg:isolinux.bin会读取该文件生成如上图形界面所示的菜单
splash.jpg:图形界面背景图片
images:包含各种引导镜像
install.img:anaconda程序就在这个镜像文件中
Packages:各种安装包
[[email protected] ~]# mkdir /media/cdrom [[email protected] ~]# mount /dev/cdrom /media/cdrom mount: block device /dev/sr0 is write-protected, mounting read-only [[email protected] ~]# ls /media/cdrom #Packages目录为安装源 CentOS_BuildTag EULA images Packages repodata RPM-GPG-KEY-CentOS-Debug-6 RPM-GPG-KEY-CentOS-Testing-6 EFI GPL isolinux RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-6 RPM-GPG-KEY-CentOS-Security-6 TRANS.TBL [[email protected] ~]# cd /media/cdrom/isolinux [[email protected] isolinux]# ls boot.cat boot.msg grub.conf initrd.img isolinux.bin isolinux.cfg memtest splash.jpg TRANS.TBL vesamenu.c32 vmlinuz [[email protected] isolinux]# cat isolinux.cfg #bootloader图形界面菜单配置信息 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 - [[email protected] isolinux]# cd .. [[email protected] cdrom]# ls images/ efiboot.img efidisk.img install.img pxeboot TRANS.TBL
■bootloaderl界面:
GUI界面
text界面
插入系统光盘并开机后会进入bootloader提供的图形界面,选择第一项即开始加载内核并启动anaconda图形配置接口;我们也可按ESC键进入bootloader文本界面,在boot提示符后可输入多种引导参数
■引导参数:
CentOS 6:
text:启动anaconda文本配置接口
repo:指定安装源
http://server/path/to/repo/
ftp://username:[email protected]/path/to/repo
网络配置:
ip=
netmask=
gateway=
dns=
ifname=: 指定此地址配置到地的网络接口
指定使用的kickstart文件及其位置
ks=cdrom:/path/to/ksfile
ks=http://server/path/to/ksfile
ks=ftp://username:[email protected]/path/to/ksfile
例如:http://172.16.0.1/centos6.x86_64.cfg
如果额外加载驱动程序:
dd=
CentOS 7:
指定安装源:
inst.repo=
指定额外需要加载驱动:
inst.dd=
指定kickstart文件及其位置:
inst.ks=
指定使用TUI界面:
inst.text
inst.cmdline:必须与kickstart文件一同使用
网络功能选项:
ip=method
可用method:dhcp, dhcp6, auto6
ip=interface:method
ip=IP::GATEWAY:NETMASK:HOSTNAME:INTERFACE:none
nameserver=
3、anaconda
anaconda是redhat、centos、fedora等linux系统的安装管理程序。它可以提供文本或图形界面供用户选择配置,并根据配置把位于光盘或其它源上的数据包安装到主机上。另外,它还支持Kickstart等脚本提供自动安装的功能
■anaconda接口:
text接口
GUI接口
■安装过程分为两个阶段:
安装前的配置阶段:(既可交互式进行,亦可直接读取kickstart配置文件自动完成)
键盘类型
安装过程中的语言
支持使用语言
时区
选择要使用磁盘设备
分区、格式化配置
选择要安装的包
管理员密码
安装阶段:
在目标磁盘创建分区、执行分区格式化
将选定的程序包安装至目标磁盘
安装bootloader
■第一次启动后的配置:
iptables
selinux
core kdump
■建议单独分区:/,/home,/usr,/var,swap
不能单独分区:/proc, /sys, /etc, /bin, /sbin, /lib, /media, /mnt, /dev
/boot:单独分区与否,取决于rootfs所在设备的类型
4、kickstart
在常规系统安装中需要手动选择安装选项,kickstart文件则定义好了这些安装配置,anaconda会自动读取该文件,并根据文件的配置来安装系统,不用再经过繁琐的人为选择了
kickstart可以在安装时通过网络获取,如http,nfs,ftp等方式,也可以将其存放在系统光盘中
系统安装结束后,anaconda还会生成一个与本次安装配置相同的kickstart文件,此文件路径为/root/anaconda-ks.cfg
[[email protected] cdrom]# cat /root/anaconda-ks.cfg # Kickstart file automatically generated by anaconda. #version=DEVEL install cdrom lang en_US.UTF-8 keyboard us network --onboot no --device eth0 --bootproto dhcp --noipv6 rootpw --iscrypted $6$O6iF6HJMYbZnfjz6$NpjS5/QneMFmgRQ70n/4RhYui8IlnoVJnzyKGIFrwBYQ3Iwus.L.wSqce3MX/Fum5dWSLjf1vgM4igU856p1h1 firewall --service=ssh authconfig --enableshadow --passalgo=sha512 selinux --enforcing timezone --utc Asia/Shanghai bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet" # The following is the partition information you requested # Note that any partitions you deleted are not expressed # here so unless you clear all partitions first, this is # not guaranteed to work #clearpart --none #part /boot --fstype=ext4 --size=200 #part / --fstype=ext4 --size=10240 #part swap --size=2048 repo --name="CentOS" --baseurl=cdrom:sr0 --cost=100 %packages @base @core @debugging @basic-desktop @desktop-debugging @desktop-platform @directory-client @fonts @input-methods @internet-browser @java-platform @legacy-x @network-file-system-client @print-client @remote-desktop-clients @server-platform @server-policy @workstation-policy @x11 mtools pax oddjob sgpio device-mapper-persistent-data abrt-gui samba-winbind certmonger pam_krb5 krb5-workstation libXmu
kickstart文件:
命令段
软件包段
%packages
pack_name
@group
-pack_name: 不安装的包,但如果被依赖,也会被安装
脚本段
%pre
安装前脚本
%post
安装后脚本
kickstart图形配置接口:
yum install system-config-kickstart
配置命令:
system-config-kickstart
配置完成后的语法检查命令:
ksvalidator /path/to/ks_file
[[email protected] ~]# yum -y install system-config-kickstart ... [[email protected] ~]# system-config-kickstart Could not open display because no X server is running. Try running ‘system-config-kickstart --help‘ for a list of options.
在Xshell中执行system-config-kickstart命令时出现错误提示:“Could not open display because no X server is running”,解决办法如下:
[[email protected] ~]# system-config-kickstart #执行该命令后会出现如下kickstart配置界面 Xlib: extension "RANDR" missing on display "localhost:10.0". /usr/share/system-config-kickstart/kickstartGui.py:103: GtkWarning: GtkSpinButton: setting an adjustment with non-zero page size is deprecated xml = gtk.glade.XML ("/usr/share/system-config-kickstart/system-config-kickstart.glade", domain="system-config-kickstart") Loaded plugins: fastestmirror, refresh-packagekit Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * epel: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com Checking for new repos for mirrors Checking for new repos for mirrors
我们可以以现有的/root/anaconda-ks.cfg文件为模板来进行配置:“File”-->“Open File”打开如下界面,载入选中的anaconda-ks.cfg后再进行适当的修改即可
二、示例:手动制作CentOS 6.5安装光盘镜像
1、复制一份现有光盘上的isolinux目录作为安装引导文件
mkdir /tmp/myiso
cp -r /media/cdrom/isolinux /tpm/myiso
2、提供kickstart文件,并将其保存于/tpm/myiso/isolinux下。(本例中以阿里云镜像站点提供的Packages作为安装源)
system-config-kickstart
3、在isolinux.cfg中指明kickstart文件位置,可以实现完全自动化安装。当然我们也可以在“boot:”提示符下手动指定
3、基于isolinux目录创建引导盘
mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --boot-info-table -V "CentOS 6.5 x86_64 boot" -b isolinux/isolinux.bin -c isolinux/boot.cat -o /root/boot.iso myiso/
-V:指定光盘ID
-b:指定在制作可开机光盘时所需的开机映像文件
-o:指定输出的映像文件名称
[[email protected] ~]# mkdir /tmp/myiso [[email protected] ~]# cp -r /media/cdrom/isolinux /tmp/myiso [[email protected] ~]# ll /tmp/myiso/isolinux total 37160 -r--r--r-- 1 root root 2048 Nov 19 08:00 boot.cat -r--r--r-- 1 root root 84 Nov 19 08:00 boot.msg -r--r--r-- 1 root root 334 Nov 19 08:00 grub.conf -r--r--r-- 1 root root 33392971 Nov 19 08:00 initrd.img -r--r--r-- 1 root root 24576 Nov 19 08:00 isolinux.bin -r--r--r-- 1 root root 936 Nov 19 08:00 isolinux.cfg -r--r--r-- 1 root root 165080 Nov 19 08:00 memtest -r--r--r-- 1 root root 151230 Nov 19 08:00 splash.jpg -r--r--r-- 1 root root 2215 Nov 19 08:00 TRANS.TBL -r--r--r-- 1 root root 162860 Nov 19 08:00 vesamenu.c32 -r-xr-xr-x 1 root root 4128368 Nov 19 08:00 vmlinuz [[email protected] ~]# chmod -R u+w /tmp/myiso/isolinux [[email protected] ~]# ll /tmp/myiso/isolinux total 37160 -rw-r--r-- 1 root root 2048 Nov 19 08:00 boot.cat -rw-r--r-- 1 root root 84 Nov 19 08:00 boot.msg -rw-r--r-- 1 root root 334 Nov 19 08:00 grub.conf -rw-r--r-- 1 root root 33392971 Nov 19 08:00 initrd.img -rw-r--r-- 1 root root 24576 Nov 19 08:00 isolinux.bin -rw-r--r-- 1 root root 936 Nov 19 08:00 isolinux.cfg -rw-r--r-- 1 root root 165080 Nov 19 08:00 memtest -rw-r--r-- 1 root root 151230 Nov 19 08:00 splash.jpg -rw-r--r-- 1 root root 2215 Nov 19 08:00 TRANS.TBL -rw-r--r-- 1 root root 162860 Nov 19 08:00 vesamenu.c32 -rwxr-xr-x 1 root root 4128368 Nov 19 08:00 vmlinuz [[email protected] ~]# system-config-kickstart ...
配置完后将kickstart文件保存至/tmp/myiso/isolinux下
[[email protected] ~]# vim /tmp/myiso/isolinux/ks.cfg #对kickstart文件做适当地修改 #platform=x86, AMD64, or Intel EM64T #version=DEVEL # Firewall configuration firewall --enabled --service=ssh # Install OS instead of upgrade install # Use network installation url --url="http://mirrors.aliyun.com/centos/6/os/x86_64/" repo --name="CentOS" --baseurl=http://mirrors.aliyun.com/centos/6/os/x86_64/ --cost=100 #指定安装源 # Root password rootpw --iscrypted $1$Bmn0VLX0$2o2vCmHL.aWp3zhewY1S.. # System authorization information auth --useshadow --passalgo=sha512 # Use text mode install text firstboot --disable # System keyboard keyboard us # System language lang en_US # SELinux configuration selinux --disabled # Installation logging level logging --level=info # Reboot after installation reboot # System timezone timezone Asia/Shanghai # Network information network --bootproto=dhcp --device=eth0 --onboot=on #如果使用网络安装源,则必须配置网络参数 # System bootloader configuration bootloader --append="crashkernel=auto rhgb quiet" --location=mbr --driveorder="sda" # Partition clearing information clearpart --all # Disk partitioning information part /boot --fstype="ext4" --size=200 part pv.008001 --size=51200 volgroup vg0 --pesize=8192 pv.008001 logvol / --fstype="ext4" --name=root --vgname=vg0 --size=10240 #图形窗口中无法配置lvm,这里为手动编辑的 logvol swap --name=swap --vgname=vg0 --size=2048 logvol /var --fstype="ext4" --name=var --vgname=vg0 --size=20480 %packages ... [[email protected] ~]# ksvalidator !$ #语法检查无误 [[email protected] ~]# vim /tmp/myiso/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 ks=cdrom:/isolinux/ks.cfg #在linux标签下指定kickstart文件位置以实现全自动化安装 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 [[email protected] ~]# cd /tmp [[email protected] tmp]# mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --boot-info-table -V "CentOS 6.5 x86_64 boot" -b isolinux/isolinux.bin -c isolinux/boot.cat -o /root/boot.iso myiso/ #针对myiso目录创建光盘镜像 I: -input-charset not specified, using utf-8 (detected in locale settings) genisoimage 1.1.9 (Linux) Scanning myiso/ Scanning myiso/isolinux Excluded: myiso/isolinux/TRANS.TBL Excluded by match: myiso/isolinux/boot.cat Writing: Initial Padblock Start Block 0 Done with: Initial Padblock Block(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 Descriptor Start Block 18 Done with: Joliet Volume Descriptor Block(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) 2 Writing: Joliet directory tree Start Block 31 Done with: Joliet directory tree Block(s) 2 Writing: Directory tree cleanup Start Block 33 Done with: Directory tree cleanup Block(s) 0 Writing: Extension record Start Block 33 Done with: Extension record Block(s) 1 Writing: The File(s) Start Block 34 26.70% done, estimate finish Thu Nov 19 10:07:43 2015 53.31% done, estimate finish Thu Nov 19 10:07:43 2015 80.01% done, estimate finish Thu Nov 19 10:07:43 2015 Total translation table size: 4701 Total rockridge attributes bytes: 1438 Total directory bytes: 2534 Path table size(bytes): 26 Done with: The File(s) Block(s) 18577 Writing: Ending Padblock Start Block 18611 Done with: Ending Padblock Block(s) 150 Max brk space used 0 18761 extents written (36 MB)
将该镜像制作成光盘或拷贝到宿主机上,在待安装系统的主机开机前接上。如下图,测试成功