歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux自動安裝實現

Linux自動安裝實現

日期:2017/2/28 14:35:20   编辑:Linux教程

原理:
使用光盤安裝linux系統過程:

第一步,POST自檢
第二步,MBR引導,這裡使用的GRUB是CDROM中isolinux/文件夾中的grub.conf。
第三步,啟動帶有安裝、升級、修復等選項的選擇菜單,這是由isolinux.bin啟動的。
第四步,vmlinuz(initrd)掛載根文件系統。
第五步,啟動anaconda安裝界面。而anaconda

詳細解析:

第二步中,grub.conf菜單中定義了第三步中的引導內容。
所以這裡的顯示內容可以自定義

[root@CentOS6 cdrom]# cat isolinux/grub.conf
#debug --graphics
default=0
splashimage=@SPLASHPATH@
timeout 5
hiddenmenu
title @PRODUCT@ @VERSION@
kernel @KERNELPATH@
initrd @INITRDPATH@
title Install system with basic video driver
kernel @KERNELPATH@ xdriver=vesa nomodeset askmethod
initrd @INITRDPATH@
title rescue
kernel @KERNELPATH@ rescue askmethod
initrd @INITRDPATH@

第三步,進入啟動界面,這裡定義了啟動界面的各種顯示內容,
由isolinux.bin執行,由isolinux.cfg提供配置文件。

display boot.msg
引用boot.msg,其配置文件為boot.cfg
menu background splash.jpg
menu title Welcome to CentOS 6.4!最上面顯示的內容
menu color border 0 #ffffffff #00000000定義界面的顏色顯示
menu color sel 7 #ffffffff #ff000000
定義選項
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 -

第五步,真正進入安裝時,需要加載Packages/anaconda-VERSION.rpm文件
anaconda程序可以實現圖形、字符方式的安裝,而在這兩種方式下,
也可以選擇交互式安裝或自問自答的自動安裝。


anaconda安裝詳解:
其自動安裝的配置文件是口kickstart。kickstart可以手動編寫,可以文本方式生成,也可以
圖形方式生成。(ks.cfg文件在安裝完成後會在root家目錄下生成anaconda.cfg詳細配置)

下面是圖形生成的步驟:
1,安裝system-config-kickstart

yum install system-config-kickstart

2,啟動system-config-kickstart

system-config-kickstart &

3,配置kickstart

Basic Configuration:
Encrypt root password表示加密root的密碼串
Target Architecture:表示平台
Reboot system after installation安裝後的動作是重啟,需要勾上。
Perform installation in text text mode (grphical is default)
安裝界面默認使用圖形界面,所以這個需要勾上。
Perform installlation in interactive mode使用交互式模式,不勾。
Install Method:安裝源
HTTP Server:安裝源的IP
HTTP Directory:目錄
Boot Loader Options:引導選項
Install new boot loader安裝新的bootloader,下面是使用舊的。
Use GRUB password:GRUB要不要加密。
Install boot loader on Master Boot Record(MBR)
將bootloader裝入MBR中
Install boot loasder on first sector of the boot partition
將bootloader裝入某一個分區中引導。
kernel parameters:crashkernel=auto rhgb quiet使用靜默模式。
Partition Information定義分區
Network Configuration網絡配置
Authentication認證,默認sha512就可以
pre
post這裡不用指定#!/bin/bash

4,保存kickstart配置文件。
文件默認保存名字為ks.cfg

5,檢查ks.cfg配置文件的錯誤。

# ksvalidator 2ks.cfg

kscfg配置文件詳解:
命令段:
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled禁用防火牆
# Install OS instead of upgrade
install默認動作是安裝
# Use network installation
url --url="ftp://1.0.0.12/centos/"使用FTP安裝源
repo --name="CentOS" --baseurl="ftp://1.0.0.12/centos"
# Root password
rootpw --iscrypted $1$dpCtQEn6$pC3UGFPZEJJ5nVftiaScq0
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text使用文本安裝方式
# System keyboard
keyboard us使用美式英語鍵盤
# System language
lang zh_CN設置默認語言
# SELinux configuration
selinux --disabled禁用SELINUX
# Do not configure the X Window System
skipx
# Installation logging level
logging --level=info
# Reboot after installation
reboot安裝完成時的動作
# System timezone
timezone Asia/Shanghai
# Network information
network --bootproto=static --device=eth0 --ip=1.0.0.7 --netmask=255.0.0.0 --onboot=on
# System bootloader configuration
bootloader --append="crashkernel=auto rhgb quiet" --location=mbr --driveorder="sda"
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel清空磁盤分區
# Disk partitioning information磁盤分區
part /boot --asprimary --fstype="ext4" --ondisk=sda --size=100
part / --asprimary --fstype="ext4" --ondisk=sda --size=20480
part swap --asprimary --fstype="swap" --ondisk=sda --size=500
腳本段:
%post
touch /tmp/abc.txt
%end
軟件包段:
%packages
@base
@basic-desktop
@chinese-support
@core
@debugging
@desktop-debugging
@desktop-platform
@desktop-platform-devel
@development
@directory-client
@fonts

使用引導光盤引導後的選擇:
點擊兩次"ESC"鍵,進入命令行模式,然後

linux ip=1.0.0.7 netmask=255.0.0.0 ks=ftp://1.0.0.12/pub/ks.cfg

ftp安裝源自動安裝linux詳細步驟:
1,制作引導光盤:
# mount /dev/cdrom /media/cdrom/
# mkdir /root/myboot
# cp /media/cdrom/isolinux/ /root/myboot/isolinux
# cd /root/myboot/isolinux
# chmod +w ./*
# chmod +x vmlinuz
# mkisofs -R -J -T -v -no-emul-boot -boot-load-size 4 -boot-info-table -V "MageEdu Testing Image" (-V跟光盤標簽) -b isolinux/isolinux.bin (明確指定isolinux.bin的存放位置) -c isolinux/boot.cat (指定boot.cat的位置) -o /tmp/boot.iso (指定輸出位置) /root/myboot/ (指定輸入源)

2,制作ftp安裝源

# yum install vsfptd
# service vsftpd start
# mkdir /var/ftp/CentOS
# mount /media/cdrom /var/ftp/CentOS,

3,將制作好的ks.cfg文件放到ftp目錄
# cp /root/ks.cfg /var/ftp/pub

4,將前面的boot.iso掛載到目標主機的光驅,啟動後兩次"ESC"鍵,然後就輸入:
linux ip=1.0.0.7 netmask=255.0.0.0 ks=ftp://1.0.0.12/pub/ks.cfg

5,自動安裝啟動

Copyright © Linux教程網 All Rights Reserved