Linux自動安裝實現

來源:互聯網
上載者:User

原理:
使用光碟片安裝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,自動安裝啟動

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.