系統管理之系統安裝及自動化安裝

概述:

    上篇我們討論了下關于Linux系統的啟動流程和grub相關的內容,本篇將介紹一下Linux的系統安裝相關的內容,具體分為:

    1、系統安裝程序anaconda的介紹

    2、kickstart文件的介紹

    3、實戰:利用ks文件實現無人值守安裝和制作iso引導文件進行安裝

第一章    系統上安裝程序anaconda的介紹

    1、CentOS的安裝過程啟動流程:(以光盤為例)

        MBR:在光盤的文件isolinux目錄中有boot.cat,這個相當于bootloader

        stage2:isolinux/isolinux.bin  相當于grub的第二階段,也就是相當于/boot/grub下的文件,顯示出啟動菜單的。

        isolinux.bin的配置文件時isolinux.cfg,也就類似于grub的配置文件

            配置文件中,每個對應的菜單選項:

            加載內核:isolinux/vmlinuz

            向內核傳遞參數:append initrd=initrd.img

        裝載根文件系統,并啟動anaconda應用程序,默認界面是圖形界面,但前提是需要512M以上的內存

            若需要顯式指定啟動文本接口,則想啟動內核傳遞一個參數text即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
isolinux.cfg文件的詳解(顯示出光盤啟動時菜單項的相關配置)
#####################################################################################
[root@localhost ~]# mount /dev/sr0 /mnt
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# cd /mnt
[root@localhost mnt]# ls
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
[root@localhost mnt]# ls isolinux/
boot.cat  boot.msg  grub.conf  initrd.img  isolinux.bin  
isolinux.cfg  memtest  splash.jpg  TRANS.TBL  vesamenu.c32  vmlinuz
[root@localhost mnt]# vim isolinux/isolinux.cfg 
 
default vesamenu.c32
#prompt 1
timeout 600                ###指定顯示的菜單界面的等待用戶選擇的超時時長,600相當于60秒
 
display boot.msg
 
menu background splash.jpg                ###菜單的背景圖片
menu title Welcome to CentOS 6.8!         ###菜單的title信息
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                     ###第一個菜單項的定義,label為linux
  menu label ^Install or upgrade an existing system     ###該菜單顯示出來的提示信息
  menu default         ###定義當超過等待用戶選擇的超時時長,而用戶沒有做出選擇時,默認執行的菜單項
  kernel vmlinuz       ###定義該菜單項用的內核信息
  append initrd=initrd.img           ###定義該菜單項的ramdisk文件的信息,和附加給內核的選項參數的信息
     ###修改附加給內核參數的信息可以有兩種方法:
         ##<1>選擇到某菜單項顯示界面的條目,按TAB鍵,然后在后面直接輸入要附加的參數
         ##<2>在菜單項顯示界面,按ESC鍵,進入boot提示符界面,然后輸入要啟動的菜單項的label信息,然后跟上要額外附加的參數
label vesa
  menu label Install system with ^basic video driver
  kernel vmlinuz
  append initrd=initrd.img 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 -

    1.png

    2.png

    3.png

        注意:上述內容一般位于引導設備,例如通過光盤,U盤,網絡等;后續的anaconda機器安裝到的程序包等可以來自于程序包倉庫,此倉庫的位置可以為:本地光盤、本地硬盤、ftp server、http server、nfs server。安裝過程中,如果想手動指定安裝倉庫,可以在安裝界面下按ESC鍵,然后進入boot提示符界面,鍵入: linux(菜單項的label,不一定是linux) method  表示詢問用戶,讓用戶選擇安裝方法

    2、安裝過程中的引導選項:

        安裝界面下按ESC,進入boot提示符,然后輸入指定菜單項的label然后加上相關選項,或者在某個菜單項后,按tab鍵,然后直接輸出相關選項

        常見的選項有:

            text  文本安裝方式

            method  手動指定使用的安裝方法

            與網絡相關的引導選項:

                ip=IPADDR

                netmask=MASK

                getaway=GATEWAY

                dns=DNS_ADDR

            遠程訪問功能相關的引導選項:

                vnc

                vncpassword="PASSWORD"

            啟動緊急救援模式:

                rescue

            裝載額外驅動:

                dd

            自動化安裝的配置文件路徑選項:ks=/PATH  指明kictstart配置文件

                如果kicstart文件在光盤上,則應寫成:

                    ks=cdrom:/PATH/TO/KICKSTART_FILE

                如果kickstart文件在某個硬盤上,則應寫成

                    ks=hd:/DEVICE/PATH/TO/KICKSTART_FILE

                如果kickstart文件在http服務器上,則應寫成

                    ks=http://HOST:PORT/PATH/TO/KICKSTART_FILE

                    ks=https://HOST:PORT/PATH/TO/KICKSTART_FILE

                如果kickstart文件在ftp服務器上,則應寫成

                    ks=ftp://HOST:PORT/PATH/TO/KICKSTART_FILE

    3、anaconda的工作過程:分兩個階段

        <1>安裝前配置階段:

            安裝過程使用的語言

            鍵盤類型

            安裝目標存儲設備

                    basic storage:本地磁盤

                    special storage:如ISCSI或SAN等

            主機名稱

            配置網絡接口

            時區

            root賬戶密碼

            分區方式及MBR安裝位置

            創建一個普通用戶

            選定要安裝的程序包

        <2>安裝階段:

            在目標磁盤創建分區,并執行格式化

            將選定的程序包,安裝至指定的目標位置

            安裝bootloader

        <3>首次啟動(與anaconda本身沒關系):

            iptables是否要啟用

            selinux是否要啟用

            core dump 核心轉儲(要求內存大于2G),當某一時刻內核崩潰時,將崩潰那一刻內存中的數據存儲到磁盤上,供后期分析崩潰原因

    4、anaconda的安裝前相關配置方式

        <1>交互式配置方式

        <2>支持通過讀取配置文件中事先定義好的配置項自動完成配置:遵循特定的語法格式,此文件即為kickstart文件

第二章    kickstart文件的介紹

    1、kickstart文件的格式:三部分組成

        命令段:指定各種系統真正執行安裝前的配置選項,如鍵盤類型,語言、分區等參數信息

            必備命令:

            可選命令:

        程序包段:指明要安裝的程序包,以及包組,也包括不安裝的程序包

            %packages  指明程序包段開始

            %end   指明程序包段結束

            段內內容:

                @GROUP_PACKAGE_NAME  表示要安裝一個包組

                PACKAGE   表示要安裝一個包

                -PACKAGE   表示不安裝的包,即使指明了不安裝,但有可能還是會安裝,因為有可能別的包安裝時依賴該包,那么該包也會被安裝上去

        腳本段:

            %pre   安裝操作真正開始之前的腳本,結束用%end

            %post   安裝后運行的腳本,結束用%end

            安裝前腳本和安裝后腳本的運行環境是不一樣的,因為腳本本身是命令的集合,但安裝前的腳本中使用的命令,主要是安裝介質,如光盤,上面自帶的一個小的系統所提供的,命令及其有限。但是安裝后腳本可以很豐富,因為安裝后的腳本,運行環境是安裝好的系統,提供了更多的可用的命令

    2、kickstart文件中命令段中的先關命令:

        <1>必備命令

            authconfig:認證方式配置 

                    authconfig –enableshadow –passalgo=sha512

                    表示基于shadow文件進行認證,密碼加密方式是sha512

            bootloader:定義bootloader的安裝位置及相關設定

                    bootloader –location=mbr –driveorder=sda –append="crashkernel=auto rhgb quiet"

                    表示bootloader安裝位置在mbr中,驅動優先選擇sda,附加給grub中內核的參數為crashkernel=auto rhgb quiet,表示內核崩潰后的處理方式,auto一般表示核心轉儲,quiet表示展開內核的過程不顯示

            keyboard:設置鍵盤類型

                    keyboard us   美式英語鍵盤

            lang:語言類型

                    lang zh_CN.UTF-8

            part:分區布局及分區使用方式

                    part /boot –fstype=ext4 –size=200

                    part pv.008002  –size=51200

                    pv.008002表示創建的是一個物理卷,及該物理卷的ID號,pv大小為51200M

            rootpw:管理員密碼

                    rootpw  –iscrypted $6$2owvccL5jQV4….

                    表示管理員加密后的密碼

                        生成密碼的方式:

                        openssl passwd -1 -salt `openssl rand -hex 4`

                        表表示用openssl生成密碼,-1表示利用md5方式加密,salt表示密碼段的雜質,雜質由openssl隨機生成8位

            timezone:指定時區

            timezone Asia/Shanghai

            補充:分區相關的其他指令

                clearpart:清除分區

                clearpart –none  –drives=sda  表示清空磁盤分區

                volgroup:創建卷組

                volgroup myvg –pesize=4096  pv.008002  表示在pv.008002物理卷上創建名為myvg的卷組,pe大小為4096字節,可以有多個物理卷

                logvo:創建邏輯卷

                logvo  /home  –fstype=ext4  –name=lv_home  –vgname=myvg  –size=5120    表示在myvg卷組上創建邏輯卷,邏輯卷名稱為lv_home,邏輯卷大小為5120M,分區掛載至/home ;文件系統類型為ext4;

        <2>可選的命令:

            install | upgrade :安裝或升級

            text   安裝界面類型,text為文本界面,默認為圖形界面

            network   配置網絡接口

                    network –onboot yes –device eth0 –bootproto dhcp –noipv6

                    network –onboot yes –device eth0 –bootproto=static –ip=10.1.32.68 –netmask=255.255.0.0 –gateway=10.1.0.1 –nameserver=10.1.0.1

            firewall:防火墻

                    firewall –service=ssh

                    表示防火墻啟用了,但是防火墻放行了對本機ssh的訪問

                    firewall –disabled 

                    表示禁用防火墻

            selinux:

                    selinux –disabled  表示禁用selinux

            halt、poweroff、reboot:表示系統安裝完成后的行為是關機或重啟

            repo:指明安裝時指明的倉庫

            repo –name=“CentOS” –baseurl=cdrom:sr0 –cost=100

            url:表示指明安裝時使用的repo源為url格式

                   url –url=http://10.1.0.1/cobbler/ks_mirror/centos-6.8-x86_64/  表示利用url指向的地址作為安裝時的倉庫,如果用網絡安裝,則要保證安裝時網卡配置好,能夠更url地址連通

    

            注意:當repo和url同時存在時,url的優先級高

    3、kickstart文件的創建

        <1>可以使用 yum install system-config-kickstart 這個是一個生成kickstart配置文件的圖形化工具

            然后用xshell連接linux主機時,使用-X選項,表示在windows界面打開linux圖形化工具,如:ssh -X root@10.1.32.68

運行system-config-kickstart命令,出現圖形化工具,即可開始配置

        <2>利用現有的kickstart現有的模板進行修改,本機安裝后再/root目錄下有個anaconda-ks.cfg,可利用此文件進行修改后生成自己的ks配置文件

        ksvalidator ks.cfg   可以檢查kickstart配置文件的語法

    5.png

    6.png

    7.png

    生成的ks文件詳解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#platform=x86, AMD64, 或 Intel EM64T  
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$QzMtsmtx$U3pKecgCxMLpfzt6QSVHo/
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url=" 
# System language
lang zh_CN
# Firewall configuration
firewall --disabled
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
 
# Network information
network  --bootproto=static --device=eth0 --gateway=10.1.0.1 --ip=10.1.32.100 --nameserver=8.8.8.8 --netmask=255.255.0.0
# Reboot after installation
reboot
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --asprimary --fstype="ext4" --size=512
part /var --asprimary --fstype="ext4" --size=10000
part / --fstype="ext4" --size=20000
part swap --asprimary --fstype="swap" --size=200
 
%packages
@Base
@Core
%end
 
%post
echo  "nwclinux,do not login">>/etc/issue
mkdir /etc/yum.repos.d/back
mv /etc/yum.repos.d/*.repo  /etc/yum.repos.d/back
cat /etc/yum.repos.d/nwc.repo <<EOF
[base]
name="test base repo"
baseurl=http://10.1.0.1/cobbler/ks_mirror/6/
gpgcheck=0
EOF
 
[ ! -d /root/.ssh ] && mkdir /root/.ssh && chmod og=--- /root/.ssh
 
cat >> /root/.ssh/authorized_keys << EOF
sh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA1ZfkFc+UkS47PUn/oofOInvCFF/oDR617m6uWi5zML0I17MKP0yRUthEsJKolzllpkUtfn0reNmvvYAZ9/
fsgcMNv3zGWHZaRyeeXsOxm44zkuVWfvcdYCJkSQaJqrKgOoFB4xPig8Up45opos/k6TLTKfFv/vsRV6/4FRgTpFRzcVXP9ambL8TfOH9tSwGp0QKR6CD
KCqdk55wOudEuk0eTF+VEcWMzxtBns8a9U6Gi+g+RLAwfe4VtpKouWKVSM6BCfiVUQGXQPKaGgF/DzaR08gWuJv5+RlVJFNbMdulBLamuWC1pEvDHASgw
CMlqZxiOCmTrECly4ca3ds/yrw== root@localhost.localdomain
%end

第三章    實戰:利用ks文件實現無人值守安裝和制作iso引導文件進行安裝

    1、利用系統光盤引導,手動指定ks文件路徑,借助網絡上的軟件源進行自動化無人值守安裝

        環境:

            相關系統均為CentOS6.8,生成ks文件放在10.1.32.118的ftp服務器上,需要安裝系統的終端,通過本地掛載系統光盤鏡像進行引導,顯示出安裝的相關菜單選項時,指明ks文件為ftp服務器上的nwcks.cfg。

            在ks文件中,明確定義安裝時使用的網絡倉庫為環境中的一臺軟件包倉庫http服務器,地址為10.1.0.1,實現最小化安裝,指明新裝的機器的IP地址為手工指定,指定為10.1.32.100

        步驟:

        <1>根據需要,生成ks文件

        ks文件的生成,此處采用修改現有的系統上ks文件,然后加上相關配置形成,最終的ks文件為:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
[root@localhost ~]# service vsftpd status
vsftpd (pid 1690) is running...
[root@localhost ~]# vim /var/ftp/pub/nwcks.cfg 
[root@localhost ~]# cat /var/ftp/pub/nwcks.cfg
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# 管理員密碼
rootpw --iscrypted $1$QzMtsmtx$U3pKecgCxMLpfzt6QSVHo/
# 時區
timezone Asia/Shanghai
# 安裝時的軟件包倉庫路徑,url表示是http的,也可用repo關鍵字指明其他倉庫路徑
url --url="http://10.1.0.1/cobbler/ks_mirror/6"
# System language
lang zh_CN
# Firewall configuration
firewall --disabled
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
 
# 安裝時網絡的指定,本處指明為靜態
network  --bootproto=static --device=eth0 --gateway=10.1.0.1 --ip=10.1.32.100 --nameserver=8.8.8.8 --netmask=255.255.0.0
# Reboot after installation
reboot
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# 指定磁盤分區方式
part /boot --asprimary --fstype="ext4" --size=512
part /var --asprimary --fstype="ext4" --size=10000
part / --fstype="ext4" --size=20000
part swap --asprimary --fstype="swap" --size=200
 
#指定安裝的軟件包,本處為最小化安裝
%packages
@Base
@Core
%end
 
 
#指定安裝后執行的相關操作,該issue文件,改yum倉庫,增加對某機器的ssh公鑰,實現該機器登錄新裝的系統時免密登錄
%post
echo  "nwclinux,do not login">>/etc/issue
mkdir /etc/yum.repos.d/back
mv /etc/yum.repos.d/*.repo  /etc/yum.repos.d/back
cat /etc/yum.repos.d/nwc.repo <<EOF
[base]
name="test base repo"
baseurl=http://10.1.0.1/cobbler/ks_mirror/6/
gpgcheck=0
EOF
 
[ ! -d /root/.ssh ] && mkdir /root/.ssh && chmod og=--- /root/.ssh
 
cat >> /root/.ssh/authorized_keys << EOF
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA44A8s8v1MAzPGIu4iJhL2F0QKVTq0mBGu0kAZeadHvX/jVYnTkTDk8OURjQThxnZELlqViel1WCeOw4i7
hwxM1qO+8hs505p39PoKj3WZ/P4Pvi4xRKfEsRF7jMW3cS84y3nE1KVpNuyzwSQlWk9sgNRMC4CIm2ZvSrSmBeyl1Tp8TQo/Ut6v0q2TfHlFh9UbGSpOa
1I2WkfJaU2kCPsk2/89GZFDDEZiCknYIeW6B1p+2xUqqSyaJHa+B7QAXe5dLvAVu1XqMPJKhv2de4HoN3871bwZtFzRCFtXzPJ09AhRkZQ4aKYxGtIS5o
LTIsfZUTVtFtHa3b3C0cJra6r7Q== root@localhost.localdomain
EOF
%end
[root@localhost ~]#

        blob.png        

        <2>新建虛擬機,掛載系統光盤,進行引導

        blob.png

        blob.png

        <3>在安裝顯示出來的菜單項中,指定ks文件的路徑,然后執行安裝

        blob.png

        blob.png

        

        <4>安裝完成后驗證是否成功

        blob.png

        

    2、創建光盤引導鏡像,利用網絡上的倉庫作為安裝時的程序包的來源進行系統自動化安裝

        思路:與上個實驗一樣,只是本實驗中不是利用系統光盤進行引導,而是自己制作一個具有引導功能的iso文件,利用制作好的iso文件進行引導,剩余的步驟根上個實驗一樣。

        環境:與上述實驗一致,ks文件也一致,只是本實驗中,不再在引導完成后在安裝菜單項里面手動輸入ks文件路徑,而是在制作引導盤時,直接將ks文件寫入到iso文件中,直接啟動安裝

        步驟:

        <1>制作iso引導文件

            a、創建光盤的文件的目錄,假設為/tmp/mycd,將系統光盤的isolinux這個微型系統拷貝到/tmp/mycd

1
2
3
4
5
6
7
8
9
    [root@localhost ~]# mount /dev/sr0 /mnt    
    mount: block device /dev/sr0 is write-protected, mounting read-only
    [root@localhost ~]# mkdir /tmp/mycd
    [root@localhost ~]# cp -r /mnt/isolinux/ /tmp/mycd/
    [root@localhost ~]# ls /tmp/mycd/
    isolinux
    [root@localhost ~]# ls /tmp/mycd/isolinux/
    boot.cat  boot.msg  grub.conf  initrd.img  isolinux.bin  
    isolinux.cfg  memtest  splash.jpg  TRANS.TBL  vesamenu.c32  vmlinuz

            

            b、根據需要,修改拷/tmp/mycd/isolinux/目錄下,islinux.cfg文件,修改安裝啟動時菜單項的信息,在響應的信息后面加上ks文件的路徑指向,這樣,我們在執行安裝時就不用手動添加ks文件的路徑了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
default vesamenu.c32
#prompt 1
timeout 1000    ##修改超時時間為100s
 
display boot.msg
 
menu background splash.jpg
menu title niwenchao test boot iso!!!
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為nwcmin,作為默認的菜單項,內核為vmlinuz,ks文件路徑為ftp上的路徑
label nwcmin   
  menu label ^Install min linux system
  menu default
  kernel vmlinuz
  append initrd=initrd.img ks=ftp://10.1.32.118/pub/nwcks.cfg
 
##新增一個菜單項,label為nwcdesktop,指定ks文件路徑為本iso鏡像的根下的nwcks.cfg,也可以指定為別的位置的ks文件
##注意,本實驗中,此處ks文件指定為本iso鏡像上的文件,則需要將對應的ks文件拷貝到/tmp/mycd目錄下
##通過指定不同的ks文件,即可以實現不同菜單項安裝不同的系統,只是在ks文件中定義好各個ks文件需要安裝的包和相關操作即可
label nwcdesktop
  menu label ^Install desktop linux system
  kernel vmlinuz
  append initrd=initrd.img ks=cdrom:/nwcks.cfg
   
label linux
  menu label ^Install or upgrade an existing system
  kernel vmlinuz
  append initrd=initrd.img
label vesa
  menu label Install system with ^basic video driver
  kernel vmlinuz
  append initrd=initrd.img 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 -

       

            e、利用命令將/tmp/mycdboot創建為iso鏡像

                 先 cd /tmp目錄中,不能cd到/tmp/mycdboot目錄中

                 然后執行:mkisofs -R -J -T -v –no-emul-boot –boot-load-size 4 –boot-info-table -V "nwc test" -c isolinux/boot.cat  -b  isolinux/isolinux.bin -o /tmp/testboot.iso mycd/

                注意:此命令要安裝genisoimage軟件包

                        -V 指定光盤名稱

                        -c 指定光盤里面微型系統的grub1階段的程序

                        -b 指定光盤里面微型系統的grub2階段的程序

                        -o 指定創建生成的iso文件存儲的路徑及名稱

                        最后指定對哪個目錄下的而文件創建iso鏡像

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
[root@localhost tmp]# mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --boot-info-table -V "nwc test"
-c isolinux/boot.cat  -b  isolinux/isolinux.bin -o /testdir/testboot.iso mycd/
I: -input-charset not specified, using utf-8 (detected in locale settings)
genisoimage 1.1.9 (Linux)
Scanning mycd/
Scanning mycd/isolinux
Excluded: mycd/isolinux/TRANS.TBL
Excluded by match: mycd/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
 22.37% done, estimate finish Wed Sep 14 21:21:04 2016
 44.66% done, estimate finish Wed Sep 14 21:21:04 2016
 67.02% done, estimate finish Wed Sep 14 21:21:04 2016
 89.29% done, estimate finish Wed Sep 14 21:21:04 2016
Total translation table size: 4704
Total rockridge attributes bytes: 1441
Total directory bytes: 2048
Path table size(bytes): 26
Done with: The File(s)                             Block(s)    22215
Writing:   Ending Padblock                         Start Block 22249
Done with: Ending Padblock                         Block(s)    150
Max brk space used 0
22399 extents written (43 MB)
[root@localhost tmp]
[root@localhost tmp]# ll /testdir/testboot.iso 
-rw-r--r-- 1 root root 45873152 9月  14 21:21 /testdir/testboot.iso
[root@localhost tmp]#

        

        <2>制作ks文件(與上個實驗一樣)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
[root@localhost ~]# cat /var/ftp/pub/nwcks.cfg
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# 管理員密碼
rootpw --iscrypted $1$QzMtsmtx$U3pKecgCxMLpfzt6QSVHo/
# 時區
timezone Asia/Shanghai
# 安裝時的軟件包倉庫路徑,url表示是http的,也可用repo關鍵字指明其他倉庫路徑
url --url="http://10.1.0.1/cobbler/ks_mirror/6"
# System language
lang zh_CN
# Firewall configuration
firewall --disabled
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
 
# 安裝時網絡的指定,本處指明為靜態
network  --bootproto=static --device=eth0 --gateway=10.1.0.1 --ip=10.1.32.100 --nameserver=8.8.8.8 --netmask=255.255.0.0
# Reboot after installation
reboot
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# 指定磁盤分區方式
part /boot --asprimary --fstype="ext4" --size=512
part /var --asprimary --fstype="ext4" --size=10000
part / --fstype="ext4" --size=20000
part swap --asprimary --fstype="swap" --size=200
 
#指定安裝的軟件包,本處為最小化安裝
%packages
@Base
@Core
%end
 
 
#指定安裝后執行的相關操作,該issue文件,改yum倉庫,增加對某機器的ssh公鑰,實現該機器登錄新裝的系統時免密登錄
%post
echo  "nwclinux,do not login">>/etc/issue
mkdir /etc/yum.repos.d/back
mv /etc/yum.repos.d/*.repo  /etc/yum.repos.d/back
cat /etc/yum.repos.d/nwc.repo <<EOF
[base]
name="test base repo"
baseurl=http://10.1.0.1/cobbler/ks_mirror/6/
gpgcheck=0
EOF
 
[ ! -d /root/.ssh ] && mkdir /root/.ssh && chmod og=--- /root/.ssh
 
cat >> /root/.ssh/authorized_keys << EOF
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA44A8s8v1MAzPGIu4iJhL2F0QKVTq0mBGu0kAZeadHvX/jVYnTkTDk8OURjQThxnZELlqViel1WCeOw4i7
hwxM1qO+8hs505p39PoKj3WZ/P4Pvi4xRKfEsRF7jMW3cS84y3nE1KVpNuyzwSQlWk9sgNRMC4CIm2ZvSrSmBeyl1Tp8TQo/Ut6v0q2TfHlFh9UbGSpOa
1I2WkfJaU2kCPsk2/89GZFDDEZiCknYIeW6B1p+2xUqqSyaJHa+B7QAXe5dLvAVu1XqMPJKhv2de4HoN3871bwZtFzRCFtXzPJ09AhRkZQ4aKYxGtIS5o
LTIsfZUTVtFtHa3b3C0cJra6r7Q== root@localhost.localdomain
EOF
%end
[root@localhost ~]#

        <3>新建虛擬機,將制作好的iso文件作為虛擬機啟動時的光盤引導,然后執行安裝

        (先將制作好的iso文件導出到windows上)

        blob.png

        1.png

        2.png

        <4>執行安裝

        blob.png

        blob.png

        blob.png

        blob.png

        blob.png

        <5>安裝完成后驗證是否成功

        blob.png

原創文章,作者:wencx,如若轉載,請注明出處:http://www.www58058.com/46848

(0)
wencxwencx
上一篇 2016-09-16
下一篇 2016-09-16

相關推薦

  • fstab配置文件、swap分區,文件關聯

    fstab配置文件、swap分區,文件關聯,lvm 掛載點和/etc/fstab ? 配置文件系統體系 ? 被mount、 fsck和其它程序使用 ? 系統重啟時保留文件系統體系 ? 可以在設備欄使用文件系統卷標 ? 使用mount -a 命令掛載/etc/fstab中的所有文件…

    Linux干貨 2016-09-01
  • 馬哥教育21期網絡班—第12周課程+練習—-LAMP練習下

    在LAMP架構中,請分別以fpm工作為獨立守護進程的方式來支持http yum groupinstall "Development Tools" "Server Platform Development"——>安裝包組1、編譯安裝Apacheht…

    Linux干貨 2016-09-26
  • 馬哥教育網絡班N22期+第7周課程練習

    1、創建一個10G分區,并格式為ext4文件系統; (1) 要求其block大小為2048, 預留空間百分比為2, 卷標為MYDATA, 默認掛載屬性包含acl; mke2fs -t ext4 -b 2048 -L MYDATA -m 2 /dev/sdb1 tune2…

    Linux干貨 2016-10-24
  • Linux發展史

    1、Linux是什么     Linux 是一套 Unix-like 的作業系統,是 Unix 的一種,它控制整個系統基本服務的核心程式 (kernel) 是由 Linus 帶頭開發出來的,「Linux」這個名稱便是以「Linus's Minix」來命名,Linus 選擇用「大眾公有版權」 (GPL)的方式來發行這份程…

    Linux干貨 2016-10-19
  • 管理SYSTEMd

    核心概念unit,systemctl管理系統服務,

    Linux干貨 2018-01-04
  • 內核編譯

    內核編譯 程序包的編譯安裝 ./configure,make,make install./configure檢查編譯環境依賴關系,并設定參數make 執行編譯操作make install 安裝二進制庫文件幫助文檔配置文件 前提:開發環境(開發工具,開發庫),頭文件:/usr/include 開源:源代碼 發行版,就是把源代碼拿過來,組織成程序。  …

    Linux干貨 2016-09-19
欧美性久久久久