linux镜像默认系统盘是多少,定制Linux镜像批量部署初始应用

主要用途:

自动安装操作系统(swap分区交互输入),系统安装后并自动执行一些自定义脚本

以Rhel6.5x86_64光盘为例!

1、挂载光盘到/mnt下,拷贝内容到新建目录mount /dev/cdrom /mnt

mkdir /opt/iso

cp -rT /mnt /opt/iso

2、修改isolinux.cfg文件vim  /opt/iso/isolinux/isolinux.cfg

default vesamenu.c32 改为 default linux

timeout 600          改为 timeout 30  3秒

label linux

menu label ^Install or upgrade an existing system

menu default

kernel vmlinuz

append initrd=initrd.img

改为:

label linux

menu label ^Install or upgrade an existing system

menu default

kernel vmlinuz

append initrd=initrd.img ks=cdrom:/ks.cfg

其中的ks.cfg位于/opt/iso/下,cdrom:/的路径就是/opt/iso

3、定义ks.cfg文件#platform=x86, AMD64, or Intel EM64T

#version=DEVEL

firewall --disabled  #禁用防火墙

install          #新的安装

cdrom            #安装介质为cdrom

text            #文本安装

keyboard us

lang en_US.UTF-8

selinux --disabled   #禁用selinux

skipx

logging --level=info

rootpw  --iscrypted $6$Mq/o.xHPh3L2wpJj$1IinnbXglCDM.ZyNVWocMHEsIlRc.oyU4In.1GTrRESIfa2Wb4IAVo8Xma3YHCirHXSyyM.Zt1VzXZyKCWAm00

authconfig --enableshadow --passalgo=sha512 #经过加密的密码 --iscrypted代表密码已经被加密,如rootpw 123456密码直接为123456

reboot

timezone  Asia/Shanghai

network  --bootproto=static --device=eth0 --ip=10.0.1.1 --netmask=255.255.255.0 --onboot=on

network  --bootproto=static --device=eth1 --onboot=on

bootloader --location=mbr

zerombr

clearpart --all

part /boot --fstype="ext4" --size=200  #启动分区200M

#part swap --fstype="swap" --size=4096 #Swap注释,从配置文件读取(用户交互输入)

part / --fstype="ext4" --grow --size=1 #剩余的空间全部给/

%include /tmp/mydata.txt          #包括用户输入的自定义的内容

%packages                    #以下为默认安装的一些包

@base

@client-mgmt-tools

@console-internet

@core

@debugging

@directory-client

@hardware-monitoring

@java-platform

@large-systems

@network-file-system-client

@performance

@perl-runtime

@server-platform

@server-policy

@X Window System

@Desktop

@Graphics Creation Tools

@chinese-support

pax

python-dmidecode

oddjob

sgpio

device-mapper-persistent-data

samba-winbind

certmonger

pam_krb5

krb5-workstation

perl-DBD-SQLite

firefox

%pre                   #安装前定义的脚本,切换到rry6终端,用于交互输入Swap分区

#!/bin/bash

exec  /dev/tty6

chvt 6

clear

echo -n "Please input the swap size(M)-32G(32768)-64G(65536)-Or-Other: "

read Size

echo -e "part swap --fstype="swap" --size=${Size}" >> /tmp/mydata.txt

exec  /dev/tty1

chvt 1

#

%post --nochroot      #从光盘拷贝文件到安装后的系统,光盘的/目录为/mnt/source/下,也就是/opt/iso下,/mnt/sysp_w_picpath/为装完系统后的/目录

cp /mnt/source/test.tar.gz /mnt/sysp_w_picpath/opt/         #把光盘/opt/iso下的test.tar.gz 拷贝的安装后系统的/opt目录下

#

%post                  #安装系统后要执行的命令,此处的/目录即为装完系统后的真实的/目录

sed -i '/^id/s/3/5/g' /etc/inittab       #把系统启动级别改为5

cd /opt

tar -zxf test.tar.gz -C /opt           #把/opt下的test.tar.gz解压到/opt

cd /opt/test/123 #进入某目录,就相当于真实操作系统的命令

bash /opt/test/123/test.sh #执行某目录下的脚本

%end

更多ks.cfg参数参考:rm -f repodata/*.gz repodata/*.*.bz2 repodata/*.repomd.xml

declare -x discinfo=`head -1 .discinfo`

createrepo -u media://$discinfo -g repodata/2a7e0c1da38a40e2961c0cec6acca8b8446d974b1fc055216ebde88bb4a19eb9-c6-x86_64-comps.xml .

5、重新封装ISOcd /opt/iso

mkisofs -R -l -r -T -no-emul-boot -J -c isolinux/boot.cat -b isolinux/isolinux.bin -o /root/test.iso -boot-load-size 4 -boot-info-table -no-bak .

把镜像重新封装到/root/test.iso,test.iso即为制作好的镜像,上边的参数不要修改,除非很清楚在干什么

主要有几个注意点:

1、光盘安装的时候,光盘的临时目录为/mnt/source/(把USB刻录为CD-ROM时,此目录为/mnt/stage2)

2、安装过程系统的目录为/mnt/sysp_w_picpath/

如果定制的ISO过大(超过4G),将无法刻录到一般的光盘,可以刻录到U盘,把U盘做一个光盘来用

U盘需要量产,可以参考http://jingyan.baidu.com/article/20095761bd435ecb0721b4bb.html

用U盘来模拟CD-ROM会出现以下错误(iso在vmware中启动无问题)

报错一:No driver find

Unabled to find any devices of the type

needed for this installation type.

Woulud you like to manually select your

device or use a driver Disk?

解决方法:

在从光盘启动后,快速按Esc键,输入"linux all-generic-ide irqpoll pci=nommconf“

报错二:Unable to read group information from repositories. This

is a problem with the generation of your install tree

解决方法:

重置repodata,然后重新生成镜像rm -f repodata/*.gz repodata/*.*.bz2 repodata/*.repomd.xml

declare -x discinfo=`head -1 .discinfo`

createrepo -u media://$discinfo -g repodata/2a7e0c1da38a40e2961c0cec6acca8b8446d974b1fc055216ebde88bb4a19eb9-c6-x86_64-comps.xml .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值