Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3759659
  • 博文数量: 880
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 6155
  • 用 户 组: 普通用户
  • 注册时间: 2016-11-11 09:12
个人简介

To be a better coder

文章分类

全部博文(880)

文章存档

2022年(5)

2021年(60)

2020年(175)

2019年(207)

2018年(210)

2017年(142)

2016年(81)

分类: LINUX

2018-07-13 15:28:01

ks文件主要分为三个部分:

a)系统安装及配置

b)自定义安装准备(%post --nochroot

c)用户自定义安装(%post

系统安装及配置一般写在ks.cfg文件最前面,系统安装设置以%post --nochroot为结束标志,接着是用户自定义安装准备部分,以“%post --nochroot”作为开始,以“%post”作为结束,自定义安装部分以“%post”作为开始。一般方便可以直接由root下面的 anaconda-ks.cfg修改。

可用vim直接进行修改也可以用system-config-kickstart图形化工具进行修改

[shell]# vim ks.cfg

修改后内容如下

#platform=x86, AMD64, Intel EM64T

#version=DEVEL

# Firewall configuration关闭防火墙

firewall --disabled

# Install OS instead of upgrade覆盖安装

install

# Use CDROM installation media从光驱安装

cdrom

repo --name="CentOS" --baseurl=file:///mnt/source --cost=100

# Root password

rootpw --iscrypted $1$Ro9DjGl8$6bU7DsgPlc9YSAjs1Jj4s1

# System authorization information

auth --useshadow --passalgo=sha512 --enablefingerprint

# Use graphical mode install //图形化安装

graphical

firstboot --disable

# System keyboard //美式键盘

keyboard us

# System language //美式英语

lang en_US

# SELinux configuration //关闭SELinux

selinux --disabled

# Installation logging level

logging --level=info

# Reboot after installation //安装完成后重启

reboot

# System timezone //时区

timezone America/New_York

# Network information设置静态ip

network --bootproto=static --device=eth0 --gateway=192.168.1.1 --ip=192.168.1.2 --netmask=255.255.255.0 --onboot=on

# System bootloader configuration

bootloader --location=mbr --append="crashkernel=auto rhgb quiet"

# Clear the Master Boot Record清除mbr

zerombr

# Partition clearing information //删除所有分区 初始化卷标

clearpart --all --initlabel

# Disk partitioning information系统分区

part /boot --asprimary --fstype="ext4" --ondisk=sda --size=100

part swap --asprimary --fstype="swap" --ondisk=sda --size=2048

part / --asprimary --fstype="ext4" --grow --ondisk=sda --size=1

part /var --fstype="ext4" --ondisk=sda --size=20480

#安装后运行脚本

%post

#RecData格式化硬盘并挂载到/RecData目录下

disk_num=`parted -l | grep "Disk /dev/" | wc -l`

disk1=`parted -l | awk '/Disk \/dev/{print $2}'|sed 's/://g'|sed -n '1p'`

disk2=`parted -l | awk '/Disk \/dev/{print $2}'|sed 's/://g'|sed -n '2p'`

sda_num=`parted $disk1 -s print | awk '/^ /{print $1}'| wc -l`

sdb_num=`parted $disk2 -s print | awk '/^ /{print $1}'| wc -l`

if [ "$disk_num" -gt 1 ]; then

       if [ "$sda_num" -eq 0 ]; then

               parted $disk1 -s mklabel gpt

               parted $disk1 -s -- mkpart primary 0 -1

               mkfs.ext4 ${disk1}1

      sda_num=1

       fi

       if [ "$sdb_num" -eq 0 ]; then

               parted $disk2 -s mklabel gpt

               parted $disk2 -s -- mkpart primary 0 -1

               mkfs.ext4 ${disk2}1

      sdb_num=1

       fi

   

       if [ "$sda_num" -eq 1 ]; then

               uuid=`blkid ${disk1}1 | awk '/dev/{print $2}'|sed 's/"//g'`

      if [ -z "$uuid" ]; then

          uuid=${disk1}1

          fsck.ext4 -y ${disk1}1 &

          sleep 60

           killall -9 fsck.ext4

      fi

               mkdir -p /RecData

      mount ${disk1}1 /RecData

      mkdir -p /RecData/{Rec,RecN}

      echo "$uuid /RecData ext4 defaults 0 0" >> /etc/fstab

   fi

       if [ "$sdb_num" -eq 1 ]; then

               uuid=`blkid ${disk2}1 | awk '/dev/{print $2}'|sed 's/"//g'`

       if [ -z "$uuid" ]; then

          uuid=${disk2}1

          fsck.ext4 -y ${disk2}1 &

          sleep 60

          killall -9 fsck.ext4

      fi

               mkdir -p /RecData

      mount ${disk2}1 /RecData

      mkdir -p /RecData/{Rec,RecN}

      echo "$uuid /RecData ext4 defaults 0 0" >> /etc/fstab

   fi

fi

#mount cdrom挂载光驱

mkdir -p /media/cdrom

mount -o loop /dev/cdrom /media/cdrom

#install media center从光碟拷贝媒体中心安装包并进行安装

cp -rf /media/cdrom/MediaCentOS/MediaCenterInstall*.tar.gz /opt/.

cd /opt

chmod 755 -R *

tar xfv MediaCenterInstall*.tar.gz

cd /opt/MediaCenterInstall*/MediaCenter

sh install.sh

cd /opt/MediaCenterInstall*/LiveNode

sh install.sh

rm -rf /opt/MediaCenterInstall*

#boot echo定制系统启动信息(将CentOS字样替换成MediaCentOS

echo "MediaCentOS Linux release 6.0 (Based on CentOS 6.0)" > /etc/centos-release

sed -i 's/CentOS Linux release 6.0 (Final)/MediaCentOS Linux release 6.0 (Based on CentOS 6.0)/g' /etc/issue

sed -i 's/CentOS Linux release 6.0 (Final)/MediaCentOS Linux release 6.0 (Based on CentOS 6.0)/g' /etc/issue.net

sed -i 's/localhost.localdomain/MediaCentOS/g' /etc/sysconfig/network

sed -i 's/CentOS/MediaCentOS/g' /etc/rc.d/rc.sysinit

sed -i 's/rhgb/ /g' /boot/grub/grub.conf

#close cdrom安装完成弹出光碟

eject

#reboot一切执行完毕后重启

reboot -f

%end

#安装包信息

%packages

@base

@console-internet

@core

@debugging

@directory-client

@hardware-monitoring

@java-platform

@large-systems

@network-file-system-client

@performance

@perl-runtime

@server-platform

@server-policy

certmonger

krb5-workstation

nscd

nss-pam-ldapd

oddjob

pam_krb5

pam_ldap

pax

perl-DBD-SQLite

sgpio

 

%end

阅读(2667) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~