Skip to content

Kickstart による自動インストール用 .iso ファイルを作成するには

Kickstart や Preseed といった方法を使うことで、Linux のインストールを自動化することが出来ます。各々、以下のように利用出来るディストリビューションが異なります。

  • Kickstart
    • RedHat Etnerprise Linux, Fedora, CentOS 等の RedHat 系ディストリビューションのインストールを自動化する手法
  • Preseed
    • Debian や Ubuntu 等の Debian 系ディストリビューションのインストールを自動化する手法

今回は Kickstart 用の .iso ファイルを作成してみます。

作業方針とパラメータ

作業は以下の方針 / 目的で行います。

  1. 作業は CentOS 7.1.1503 上で行う
  2. CentOS 7.1.1503 を自動インストールする .iso ファイルを作成する
  3. VMware 用に作成する .iso ファイルを作成する
  4. 「部分的な自動化」では無く、「完全な自動化」とする(全てのパラメータを応答ファイルで指定しておき、インストールは完全無人化する)
  5. 作成した .iso ファイルは VMware で利用する

作業時の主なパラメータは以下の通りです。

項目
作業環境 CentOS 7.1.1503
ベースイメージ CentOS-7-x86_64-Everything-1503-01.iso
ベースイメージの展開先 ~/base
作成する .iso ファイル CentOS-7-x86_64-Kickstart-1503-01.iso
ユーザ名 root
パスワード password

作業の流れ

作業の流れは以下の通りです。作業は全て Linux(今回は CentOS 7.1.1503)上で行います。

  1. 必要ツールのインストール
  2. ベースイメージのダウンロード、及び展開
  3. 応答ファイルの作成
  4. 再 .iso ファイル化

ベースイメージ(.iso)を展開し、中の応答ファイルを Kickstart 用に書き換え、再度、.iso ファイル化しなおす… という流れになります。

必要ツールのインストール

.iso ファイルを作成する際に必要なので mkisofs をインストールしておきます。

1
yum -y install mkisofs

ベースイメージのダウンロード、及び展開

ベースとなる .iso ファイルを用意します。今回は IIJ 社のサーバから直接、ダウンロードしました。

1
curl -O http://ftp.iij.ad.jp/pub/linux/centos/7/isos/x86_64/CentOS-7-x86_64-Everything-1503-01.iso

ダウンロードした .iso ファイルの中身(応答ファイル)を書き換えることになるので、展開しておきます。展開先は ~/base としました。

1
2
3
mount -t iso9660 -o loop CentOS-7-x86_64-Everything-1503-01.iso /mnt
mkdir ~/base
find /mnt -maxdepth 1 -mindepth 1 -exec cp -rp {} ~/base/ \;

応答ファイルの作成

Kickstart で自動インストールを行うには、インストール用パラメータを記載した応答ファイルを用意しておきます。今回は ~/base/isolinux/ks.cfg というファイルを以下の内容で新規作成しました。

root ユーザのパスワードは rootpw で指定します。平文で書くことも、暗号化して書くことも出来ます。暗号化する場合は openssl passwd -1 コマンドで暗号化した文字列を取得することが出来ます。

zerombr 指定をしないと VMware 上の仮想マシンで Kickstart する場合に「パーティション情報が無い!」とエラーになり、自動インストールが妨げられてしまう為、zerombr の指定を忘れないようにします。インストールするパッケージやパッケージグループを変更する場合は、%packages 以下を適宜、修正します。

 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
#version=RHEL7

cmdline
install
cdrom

lang en_US.UTF-8
keyboard --vckeymap=jp106 --xlayouts='jp106'
timezone Asia/Tokyo --isUtc --nontp

network --bootproto=dhcp --device=link --ipv6=auto --activate
network --hostname=localhost

#rootpw --plaintext password
rootpw --iscrypted $1$2c5VfLZS$WKO3i5/aJrKMDe9fudZ/p0

zerombr
bootloader --location=mbr

clearpart --all --initlabel
part / --fstype=xfs --grow --asprimary --size=1

auth --enableshadow --passalgo=sha512
firstboot --disabled
selinux --disabled
firewall --disabled

%packages --nobase
@core
@development
emacs
git
nmap
ntp
ntpdate
open-vm-tools-desktop
tcpdump
unzip
vim
wget
%end

%pre
mkdir /mnt/cdrom
mount -o ro /dev/cdrom /mnt/cdrom
%end

%post --log=/root/ks-post.log
%end

reboot

次に ~/base/isolinux/isolinux.cfg を修正します(このファイルは元々、存在しているはずです)。

  1. 先頭行の default vesamenu.c32 をコメントアウトする
  2. default setup を追加する
  3. label check から menu default 行を削除する
  4. label setup を追加する

長くなりますが不要部分も含め、最終的に ~/base/isolinux/isolinux.cfg は以下となりました。

  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
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#default vesamenu.c32
default setup
timeout 600

display boot.msg

## Clear the screen when exiting the menu, instead of leaving the menu displayed.
## For vesamenu, this means the graphical background is still displayed without
## the menu itself for as long as the screen remains in graphics mode.
menu clear
menu background splash.png
menu title CentOS 7
menu vshift 8
menu rows 18
menu margin 8
#menu hidden
menu helpmsgrow 15
menu tabmsgrow 13

## Border Area
menu color border * #00000000 #00000000 none

## Selected item
menu color sel 0 #ffffffff #00000000 none

## Title bar
menu color title 0 #ff7ba3d0 #00000000 none

## Press [Tab] message
menu color tabmsg 0 #ff3a6496 #00000000 none

## Unselected menu item
menu color unsel 0 #84b8ffff #00000000 none

## Selected hotkey
menu color hotsel 0 #84b8ffff #00000000 none

## Unselected hotkey
menu color hotkey 0 #ffffffff #00000000 none

## Help text
menu color help 0 #ffffffff #00000000 none

## A scrollbar of some type? Not sure.
menu color scrollbar 0 #ffffffff #ff355594 none

## Timeout msg
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none

## Command prompt text
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none

## Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.

menu tabmsg Press Tab for full configuration options on menu items.

menu separator # insert an empty line
menu separator # insert an empty line

label setup
  menu default
  kernel vmlinuz
  append ks=cdrom:/isolinux/ks.cfg initrd=initrd.img text

label linux
  menu label ^Install CentOS 7
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet

label check
  menu label Test this ^media & install CentOS 7
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rd.live.check quiet

menu separator # insert an empty line

## utilities submenu
menu begin ^Troubleshooting
  menu title Troubleshooting

label vesa
  menu indent count 5
  menu label Install CentOS 7 in ^basic graphics mode
  text help
    Try this option out if you're having trouble installing
    CentOS 7.
  endtext
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 xdriver=vesa nomodeset quiet

label rescue
  menu indent count 5
  menu label ^Rescue a CentOS system
  text help
    If the system will not boot, this lets you access files
    and edit config files to try to get it booting again.
  endtext
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rescue quiet

label memtest
  menu label Run a ^memory test
  text help
    If your system is having issues, a problem with your
    system's memory may be the cause. Use this utility to
    see if the memory is working correctly.
  endtext
  kernel memtest

menu separator # insert an empty line

label local
  menu label Boot from ^local drive
  localboot 0xffff

menu separator # insert an empty line
menu separator # insert an empty line

label returntomain
  menu label Return to ^main menu
  menu exit

menu end

再 .iso ファイル化

最後に、修正した内容で .iso ファイルを再作成します。

1
2
cd ~/base
mkisofs -v -r -J -o ../CentOS-7-x86_64-Kickstart-1503-01.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table .

これで Kickstart 用の .iso ファイルは完成です。パラメータに記載している通り、この .iso ファイルを利用して作成した CentOS にはユーザ名「root」、パスワード「password」でログイン可能です。