内容:

1、利用kickstart进行自动化安装linux系统

2、制作光盘、U盘启动盘


一、系统自动化安装

    1、anaconda

    由前面的学习我们知道,系统的启动流程:

        bootloader-->kernel(initramfs)-->rootfs-->/sbin/init

    所以,bootloader完全可以由光盘来进行引导,在引导的过程中在借助kickstart来进程自动安装

Anaconda是RedHat、CentOS、Fedora等Linux的安装管理程序。它可以提供文本、图形等安装管理方式,并支持Kickstart等脚本提供自动安装的功能。

    此外,其还支持许多启动参数,熟悉这些参数可为安装带来很多方便。该程序的功能是把位于光盘或其他源上的数据包,根据设置安装到主机上。

    为实现该定制安装,它提供一个定制界面,可以实现交互式界面供用户选择配置(如选择语言,键盘,时区等信息)。Anaconda的大部分模块用Python编写,有少许的载入模块用C编写。


    2、kickstart文件的格式可以分为三个部分

        命令段:指明各种安装前配置,如键盘类型等;

        程序包段:指明要安装的程序包组或程序包,不安装的程序包等;

%packages

@group_name

package

-package

%end

        脚本段:

%pre: 安装前脚本

        运行环境:运行于安装介质上的微型Linux环境

%post: 安装后脚本

        运行环境:安装完成的系统;


Anaconda支持的管理模式: 

    (1)Kickstart提供的自动化安装; 

    (2)对一个RedHat实施upgrade; 

    (3)Rescuse模式对不能启动的系统进行故障排除。 


要进入安装步骤,需要先有一个引导程序引导启动一个特殊的Linux安装环境系统;引导有多种方式: 

    (1)基于网络方式的小型引导镜像,需要提供小型的引导镜像; 

    (2)U盘引导,通过可引导存储介质中的小型引导镜像启动安装过程;  

    (3)基于PXE的网络安装方式,要提供PXE的完整安装环境; 

    (4)其他bootloder引导(如GRUB)。 

可用的安装方式:本地CDROM、硬盘驱动器、网络方式(NFS、FTP、HTTP)。 



3、kickstart文件创建

    创建kickstart文件的方式:

        (1) 直接手动编辑;

        依据某模板修改:

        在系统安装完成后都会在/root/目录下生成一个anaconda-ks.cfg的配置,配置记录了安装系统的选项和参数:

[20:29 root@Centos6.8~]# cat 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$dC0KOoM3deDYui88$dudZzmHQdSg.J.pQkxe1XSxC4Plkq/DEMO1Pj/PBBJEh/GvdZQ1HzFp4LXbvEO5bWhhmEiAuweoLqvCHMxu0J.
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=50000
#part /testdir --fstype=ext4 --size=20000
#part swap --size=4000
repo --name="CentOS"  --baseurl=cdrom:sr0 --cost=100
%packages
@base
@core
@debugging
@basic-desktop
@desktop-debugging
@desktop-platform
@directory-client
@fonts
@general-desktop
@graphical-admin-tools
@input-methods
@internet-applications
@internet-browser
@java-platform
@kde-desktop
@legacy-x
@network-file-system-client
@office-suite
@print-client
@remote-desktop-clients
@server-platform
@server-policy
@workstation-policy
@x11
mtools
pax
python-dmidecode
oddjob
wodim
sgpio
genisop_w_picpath
device-mapper-persistent-data
abrt-gui
qt-mysql
samba-winbind
certmonger
pam_krb5
krb5-workstation
xterm
xorg-x11-xdm
libXmu
rdesktop



        (2) 可使用图形化的创建工具:system-config-kickstart(该工具系统没有自带,需要安装system-config包)

        推荐使用图形化的工具来进行创建:



在图形终端输入命令:system-config-kickstart来运行kickstart脚本创建向导

wKiom1fYtXaw10trAAE7uyaIjgI273.png



输入要安装的linux镜像文件的位置,支持多种方式

wKiom1fYtXfh4PTiAAC6GbRdOTU452.png



grub选项

wKioL1fYtXewVV7YAADvpumA_go946.png



提前做好分区计划

wKiom1fYtXizLUEIAAEKXwB3c1E540.png



配置网络信息

wKioL1fYtXiBOIzTAADXcNI8qnM712.png



配置其他选项

wKioL1fYtXnBZ_peAAC4w05T0TI192.png



选择需要安装的软件包

wKiom1fYtXnwUsAZAAET8br3Odw288.png



可编写系统安装前后的脚本

wKiom1fYtXqyBiFxAAC4GZykGYY149.png



重要的一步:在光盘启动时,按esc键进入boot模式,输入kickstart的配置文件路径

wKioL1fYtXqDluZGAAALPRk6Fgs763.png



回车后自动安装

wKiom1fYtXqjTQJ9AAAZiHhp9GE721.png


    编写完成后自动生成的kickstart脚本如下:

[21:09 root@Centos6.8~]# cat mylinux-ks.cfg 
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="http://10.1.0.1/cobbler/ks_mirror/CentOS-6-x86_64/"
# Root password
rootpw --iscrypted $1$LY.D8e4v$UnqW3SAJSZyg9hxr.YjAo/
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --enforcing
# Do not configure the X Window System
skipx
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone --isUtc Asia/Shanghai
# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all  
# Disk partitioning information
part / --fstype="ext4" --size=20000
part /boot --fstype="ext4" --size=200
part swap --fstype="swap" --size=4000
%post
echo "welcome to use mylinux" >> /etc/issue
echo -e "[base]\nbaseurl=/msic/cd\ngpgcheck=0" > /etc/yum.repo.d/base.repo
%end
%packages
@base
@basic-desktop
@desktop-debugging
@desktop-platform
@fonts
@general-desktop
@graphical-admin-tools
@input-methods
@kde-desktop
@legacy-x
@remote-desktop-clients
@x11
%end



更多内容请关注我的博客

    4、kickstart文件使用(自动安装系统):



挂载光盘进入救援模式,在选择菜单出按esc间,进入命令模式,输入kickstart文件的位置:linux ks=

eg.

DVD drive: ks=cdrom:/PATH/TO/KICKSTART_FILE
Hard drive: ks=hd:device:/directory/KICKSTART_FILE
HTTP server: ks=http://host:port/path/to/KICKSTART_FILE
FTP server: ks=ftp://host:port/path/to/KICKSTART_FILE
HTTPS server: ks=https://host:port/path/to/KICKSTART_FILE
NFS server:ks=nfs:host:/path/to/KICKSTART_FILE



二、制作光盘和U盘启动盘

    创建引导光盘:

#cp/media/cdrom/isolinux/ /tmp/myiso/
#vi /tmp/myiso/isolinux/isolinux.cfg
initrd=initrd.imgtext ks=cdrom:/myks.cfg
#cp/root/myks.cfg/tmp/myiso/
#cd /tmp
# mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --boot-info-table -V "CentOS 6.6 x86_64 boot" -b isolinux/isolinux.bin-c isolinux/boot.cat -o /root/boot.isomyiso/

  创建U盘启动盘:

#dd if=/dev/sr0 of=/dev/sdb

更多内容请关注我的博客