某些场合,很有可能需要启动ISO或者USB盘,自带Linux系统,然后拯救当前损坏的系统
或者直接启动一个LIVE CentOS系统,去做某些事,比如用MegaRaid划分Raid、测试系统等等
这时候就需要制作出来一个LIVE CD的系统了
制作步骤如下:
一、安装live-tools
1yum -y install livecd-tools
二、准备Kickstart文件centos7-live-docker.ks
1lang en_GB.UTF-8
2keyboard us
3timezone Asia/Shanghai --isUtc
4
5#selinux --enforcing
6selinux --disabled
7
8#firewall --enabled --service=cockpit
9firewall --disabled
10
11#xconfig --startxonboot
12part / --size 8192 --fstype ext4
13services --enabled=NetworkManager,sshd --disabled=network
14
15
16# Root password
17auth --useshadow --enablemd5
18rootpw --plaintext Kalaisadog2021
19
20repo --name=base --baseurl=http://mirror.centos.org/centos/7/os/x86_64/
21repo --name=updates --baseurl=http://mirror.centos.org/centos/7/updates/x86_64/
22repo --name=extras --baseurl=http://mirror.centos.org/centos/7/extras/x86_64/
23repo --name=epel --baseurl=http://dl.fedoraproject.org/pub/epel/7/x86_64/
24
25%packages
26@core
27kernel
28dracut
29bash
30firewalld
31NetworkManager
32e2fsprogs
33rootfiles
34docker
35openssh-server
36
37#By zhang ranrui
38unzip
39net-tools
40binutils
41wget
42bash-completion
43bc
44dmidecode
45dmraid
46dmraid-events
47lvm2
48lvm2-libs
49kpartx
50mdadm
51parted
52xfsdump
53xfsprogs
54gdisk
55bzip2
56extundelete
57libHX
58libHX-devel
59autoconf
60gcc
61gcc-c++
62make
63screen
64telnet
65
66%end
67
68%post
69
70systemctl enable docker
71
72# By Zhang Ranrui, Add your custom script
73#wget http://www.rendoumi.com/soft/other/xfs_irecover -O /usr/local/bin/xfs_irecover
74#chmod 755 /usr/local/bin/xfs_irecover
75
76echo "Banner /etc/issue" >> /etc/ssh/sshd_config
77
78sed -i "s/After=network\.target/After=network-online\.target\nWants=network-online\.target/g" /usr/lib/systemd/system/rc-local.service
79
80chmod 755 /etc/systemd/system/rc.local.service.d
81chmod 644 /etc/systemd/system/rc.local.service.d/local.conf
82
83chmod 755 /etc/rc.d/rc.local
84systemctl enable rc-local
85systemctl start rc-local
86
87# FIXME: it'd be better to get this installed from a package
88cat > /etc/rc.d/init.d/livesys << EOF
89#!/bin/bash
90#
91# live: Init script for live image
92#
93# chkconfig: 345 00 99
94# description: Init script for live image.
95### BEGIN INIT INFO
96# X-Start-Before: display-manager
97### END INIT INFO
98
99. /etc/init.d/functions
100
101if ! strstr "\`cat /proc/cmdline\`" rd.live.image || [ "\$1" != "start" ]; then
102 exit 0
103fi
104
105if [ -e /.liveimg-configured ] ; then
106 configdone=1
107fi
108
109exists() {
110 which \$1 >/dev/null 2>&1 || return
111 \$*
112}
113
114# Make sure we don't mangle the hardware clock on shutdown
115ln -sf /dev/null /etc/systemd/system/hwclock-save.service
116
117livedir="LiveOS"
118for arg in \`cat /proc/cmdline\` ; do
119 if [ "\${arg##rd.live.dir=}" != "\${arg}" ]; then
120 livedir=\${arg##rd.live.dir=}
121 return
122 fi
123 if [ "\${arg##live_dir=}" != "\${arg}" ]; then
124 livedir=\${arg##live_dir=}
125 return
126 fi
127done
128
129# enable swaps unless requested otherwise
130swaps=\`blkid -t TYPE=swap -o device\`
131if ! strstr "\`cat /proc/cmdline\`" noswap && [ -n "\$swaps" ] ; then
132 for s in \$swaps ; do
133 action "Enabling swap partition \$s" swapon \$s
134 done
135fi
136if ! strstr "\`cat /proc/cmdline\`" noswap && [ -f /run/initramfs/live/\${livedir}/swap.img ] ; then
137 action "Enabling swap file" swapon /run/initramfs/live/\${livedir}/swap.img
138fi
139
140mountDockerDisk() {
141 # support label/uuid
142 if [ "\${dockerdev##LABEL=}" != "\${dockerdev}" -o "\${dockerdev##UUID=}" != "\${dockerdev}" ]; then
143 dockerdev=\`/sbin/blkid -o device -t "\$dockerdev"\`
144 fi
145
146 # if we're given a file rather than a blockdev, loopback it
147 if [ "\${dockerdev##mtd}" != "\${dockerdev}" ]; then
148 # mtd devs don't have a block device but get magic-mounted with -t jffs2
149 mountopts="-t jffs2"
150 elif [ ! -b "\$dockerdev" ]; then
151 loopdev=\`losetup -f\`
152 if [ "\${dockerdev##/run/initramfs/live}" != "\${dockerdev}" ]; then
153 action "Remounting live store r/w" mount -o remount,rw /run/initramfs/live
154 fi
155 losetup \$loopdev \$dockerdev
156 dockerdev=\$loopdev
157 fi
158
159 # if it's encrypted, we need to unlock it
160 if [ "\$(/sbin/blkid -s TYPE -o value \$dockerdev 2>/dev/null)" = "crypto_LUKS" ]; then
161 echo
162 echo "Setting up encrypted Docker device"
163 plymouth ask-for-password --command="cryptsetup luksOpen \$dockerdev EncDocker"
164 dockerdev=/dev/mapper/EncDocker
165 fi
166
167 # and finally do the mount
168 mount \$mountopts \$dockerdev /var/lib/docker
169 # if we have /home under what's passed for persistent home, then
170 # we should make that the real /home. useful for mtd device on olpc
171 if [ -d /var/lib/docker/docker ]; then mount --bind /var/lib/docker/docker /var/lib/docker ; fi
172 [ -x /sbin/restorecon ] && /sbin/restorecon /var/lib/docker
173}
174
175findDockerDisk() {
176 for arg in \`cat /proc/cmdline\` ; do
177 if [ "\${arg##dockerdisk=}" != "\${arg}" ]; then
178 dockerdev=\${arg##dockerdisk=}
179 return
180 fi
181 done
182}
183
184if strstr "\`cat /proc/cmdline\`" dockerdisk= ; then
185 findDockerDisk
186elif [ -e /run/initramfs/live/\${livedir}/docker.img ]; then
187 dockerdev=/run/initramfs/live/\${livedir}/docker.img
188fi
189
190# if we have a persistent /home, then we want to go ahead and mount it
191if ! strstr "\`cat /proc/cmdline\`" nodockerdisk && [ -n "\$dockerdev" ] ; then
192 action "Mounting persistent /var/lib/docker" mountDockerDisk
193fi
194
195# make it so that we don't do writing to the overlay for things which
196# are just tmpdirs/caches
197mount -t tmpfs -o mode=0755 varcacheyum /var/cache/yum
198mount -t tmpfs vartmp /var/tmp
199[ -x /sbin/restorecon ] && /sbin/restorecon /var/cache/yum /var/tmp >/dev/null 2>&1
200
201if [ -n "\$configdone" ]; then
202 exit 0
203fi
204
205# add fedora user with no passwd
206action "Adding live user" useradd \$USERADDARGS -c "Live System User" liveuser
207passwd -d liveuser > /dev/null
208usermod -aG wheel,docker liveuser > /dev/null
209
210# Remove root password lock
211passwd -d root > /dev/null
212(echo Kalaisadog2021; echo Kalaisadog2021)|passwd root --stdin
213
214# turn off firstboot for livecd boots
215systemctl --no-reload disable firstboot-text.service 2> /dev/null || :
216systemctl --no-reload disable firstboot-graphical.service 2> /dev/null || :
217systemctl stop firstboot-text.service 2> /dev/null || :
218systemctl stop firstboot-graphical.service 2> /dev/null || :
219
220# don't use prelink on a running live image
221sed -i 's/PRELINKING=yes/PRELINKING=no/' /etc/sysconfig/prelink &>/dev/null || :
222
223# turn off mdmonitor by default
224systemctl --no-reload disable mdmonitor.service 2> /dev/null || :
225systemctl --no-reload disable mdmonitor-takeover.service 2> /dev/null || :
226systemctl stop mdmonitor.service 2> /dev/null || :
227systemctl stop mdmonitor-takeover.service 2> /dev/null || :
228
229# don't enable the gnome-settings-daemon packagekit plugin
230gsettings set org.gnome.settings-daemon.plugins.updates active 'false' || :
231
232# don't start cron/at as they tend to spawn things which are
233# disk intensive that are painful on a live image
234systemctl --no-reload disable crond.service 2> /dev/null || :
235systemctl --no-reload disable atd.service 2> /dev/null || :
236systemctl stop crond.service 2> /dev/null || :
237systemctl stop atd.service 2> /dev/null || :
238
239# Mark things as configured
240touch /.liveimg-configured
241
242# add static hostname to work around xauth bug
243# https://bugzilla.redhat.com/show_bug.cgi?id=679486
244echo "localhost" > /etc/hostname
245
246# Fixing the lang install issue when other lang than English is selected . See http://bugs.centos.org/view.php?id=7217
247/usr/bin/cp /usr/lib/python2.7/site-packages/blivet/size.py /usr/lib/python2.7/site-packages/blivet/size.py.orig
248/usr/bin/sed -i "s#return self.humanReadable()#return self.humanReadable().encode('utf-8')#g" /usr/lib/python2.7/site-packages/blivet/size.py
249
250EOF
251
252# bah, hal starts way too late
253cat > /etc/rc.d/init.d/livesys-late << EOF
254#!/bin/bash
255#
256# live: Late init script for live image
257#
258# chkconfig: 345 99 01
259# description: Late init script for live image.
260
261. /etc/init.d/functions
262
263if ! strstr "\`cat /proc/cmdline\`" rd.live.image || [ "\$1" != "start" ] || [ -e /.liveimg-late-configured ] ; then
264 exit 0
265fi
266
267exists() {
268 which \$1 >/dev/null 2>&1 || return
269 \$*
270}
271
272touch /.liveimg-late-configured
273
274# read some variables out of /proc/cmdline
275for o in \`cat /proc/cmdline\` ; do
276 case \$o in
277 ks=*)
278 ks="--kickstart=\${o#ks=}"
279 ;;
280 xdriver=*)
281 xdriver="\${o#xdriver=}"
282 ;;
283 esac
284done
285
286# if liveinst or textinst is given, start anaconda
287if strstr "\`cat /proc/cmdline\`" liveinst ; then
288 plymouth --quit
289 /usr/sbin/liveinst \$ks
290fi
291if strstr "\`cat /proc/cmdline\`" textinst ; then
292 plymouth --quit
293 /usr/sbin/liveinst --text \$ks
294fi
295
296# configure X, allowing user to override xdriver
297if [ -n "\$xdriver" ]; then
298 cat > /etc/X11/xorg.conf.d/00-xdriver.conf <<FOE
299Section "Device"
300 Identifier "Videocard0"
301 Driver "\$xdriver"
302EndSection
303FOE
304fi
305
306EOF
307
308chmod 755 /etc/rc.d/init.d/livesys
309/sbin/restorecon /etc/rc.d/init.d/livesys
310/sbin/chkconfig --add livesys
311
312chmod 755 /etc/rc.d/init.d/livesys-late
313/sbin/restorecon /etc/rc.d/init.d/livesys-late
314/sbin/chkconfig --add livesys-late
315
316# enable tmpfs for /tmp
317systemctl enable tmp.mount
318
319
320# enable docker
321systemctl enable docker.service
322
323# work around for poor key import UI in PackageKit
324rm -f /var/lib/rpm/__db*
325releasever=$(rpm -q --qf '%{version}\n' --whatprovides system-release)
326basearch=$(uname -i)
327rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
328echo "Packages within this LiveCD"
329rpm -qa
330# Note that running rpm recreates the rpm db files which aren't needed or wanted
331rm -f /var/lib/rpm/__db*
332
333# go ahead and pre-make the man -k cache (#455968)
334/usr/bin/mandb
335
336# save a little bit of space at least...
337rm -f /boot/initramfs*
338# make sure there aren't core files lying around
339rm -f /core*
340
341# convince readahead not to collect
342# FIXME: for systemd
343
344cat >> /etc/rc.d/init.d/livesys << EOF
345
346
347# disable updates plugin
348cat >> /usr/share/glib-2.0/schemas/org.gnome.settings-daemon.plugins.updates.gschema.override << FOE
349[org.gnome.settings-daemon.plugins.updates]
350active=false
351FOE
352
353# Show the system-config-keyboard tool on the desktop
354mkdir /home/liveuser/Desktop -p >/dev/null
355cat /usr/share/applications/system-config-keyboard.desktop | sed '/NotShowIn/d' |sed 's/Terminal=false/Terminal=true/' > /home/liveuser/Desktop/system-config-keyboard.desktop
356cat /usr/share/applications/liveinst.desktop | sed '/NoDisplay/d' > /home/liveuser/Desktop/liveinst.desktop
357chmod +x /home/liveuser/Desktop/*.desktop
358chown -R liveuser:liveuser /home/liveuser
359
360# Liveuser face
361if [ -e /usr/share/icons/hicolor/96x96/apps/fedora-logo-icon.png ] ; then
362 cp /usr/share/icons/hicolor/96x96/apps/fedora-logo-icon.png /home/liveuser/.face
363 chown liveuser:liveuser /home/liveuser/.face
364fi
365
366# make the installer show up
367if [ -f /usr/share/applications/liveinst.desktop ]; then
368 # Show harddisk install in shell dash
369 sed -i -e 's/NoDisplay=true/NoDisplay=false/' /usr/share/applications/liveinst.desktop
370 # need to move it to anaconda.desktop to make shell happy
371 #cp /usr/share/applications/liveinst.desktop /usr/share/applications/anaconda.desktop
372fi
373 cat >> /usr/share/glib-2.0/schemas/org.gnome.shell.gschema.override << FOE
374[org.gnome.shell]
375favorite-apps=['liveinst.desktop','firefox.desktop', 'evolution.desktop', 'empathy.desktop', 'rhythmbox.desktop', 'shotwell.desktop', 'libreoffice-writer.desktop', 'nautilus.desktop', 'gnome-documents.desktop', 'anaconda.desktop']
376FOE
377
378
379# set up auto-login
380cat > /etc/gdm/custom.conf << FOE
381[daemon]
382AutomaticLoginEnable=True
383AutomaticLogin=liveuser
384FOE
385
386# Turn off PackageKit-command-not-found while uninstalled
387if [ -f /etc/PackageKit/CommandNotFound.conf ]; then
388 sed -i -e 's/^SoftwareSourceSearch=true/SoftwareSourceSearch=false/' /etc/PackageKit/CommandNotFound.conf
389fi
390
391# make sure to set the right permissions and selinux contexts
392chown -R liveuser:liveuser /home/liveuser/
393restorecon -R /home/liveuser/
394
395# Fixing default locale to us
396localectl set-keymap us
397localectl set-x11-keymap us
398EOF
399
400
401# rebuild schema cache with any overrides we installed
402glib-compile-schemas /usr/share/glib-2.0/schemas
403
404
405%end
注意,上面注释了两个地方,都可以添加软件或者运行脚本
三、build出iso文件
1livecd-creator --verbose -c centos7-live-docker.ks --cache=cache -f centos7-live-docker
然后就会得到centos7-live-docker.iso的文件,注意在build过程中的报错信息,多数是无法下载包导致的。
直接加载ISO文件启动或者刻录到USB上启动,就可以进入这个自制的Live系统了
千万注意,启动一定要选Bios legacy,不要用Uefi。
相关一些有用的链接: