自动重装系统

以前做过了通过网络用kickstart安装系统,但现在没有dhcp服务器,网络启动没有办法实现,而现在一周要重装好几遍系统,每次拿光盘去启动太麻烦了,于是就搜了一下有没有直接从硬盘启动安装的,果然是有的,设好之后,重装只要一条命令再等10分钟就可以了,方便了不少。

以下是设置的步骤:

1. 要有一台nfs服务器,当然ftp和http服务器也可以,我比较喜欢用nfs。
安装的系统是centos,所以将centos的安装文件从光盘从拷出来。

mount -t iso9660 -o loop,ro /tmp/XXX.iso /mnt/cdrom
cp -var /mnt/cdrom/. /XXX


2. 设置好kickstart的配置文件

# Kickstart file automatically generated by anaconda.

reboot
install
nfs --server=192.168.1.1 --dir=/XXX
lang en_US.UTF-8
langsupport --default=en_US.UTF-8 en_US.UTF-8
keyboard us
rootpw --iscrypted $1$dIlRPoXu$49cW3VcWUGQ3owGnCoSiO/
firewall --disabled
selinux --enforcing
authconfig --enableshadow --enablemd5
timezone Asia/Beijing
bootloader --location=mbr
clearpart --all --drives=sda
part /boot --fstype ext3 --size=100 --asprimary
part / --fstype ext3 --size=10000 --asprimary
part /usr --fstype ext3 --size=5000
part /home --fstype ext3 --size=5000
part swap --size=2000
part /tmp --fstype ext3 --size=2000
part /var --fstype ext3 --size=100 --grow --asprimary
network --device eth0 --bootproto static --ip 192.168.1.2 --netmask 255.255.255.0 --gateway 192.168.1.254 --nameserver 211.9.226.5 --hostname TEST

%packages
kernel-smp
grub
e2fsprogs

%post
#!/bin/bash

chkconfig smartd off
chkconfig sendmail off
echo "nameserver 211.9.226.5
nameserver 210.22.70.3
nameserver 202.96.209.5
" > /etc/resolv.conf


3. 编写设置的脚本

#!/bin/sh

printf "Input IP: "
read IP
printf "Input Hostname: "
read Hostname
mkdir -p /mnt/tmp
umount /mnt/tmp >/dev/null 2>&1
echo 'Wait please'
mount -t nfs -o soft,intr,timeo=30 192.168.1.1:/XXX /mnt/tmp
mkdir -p /boot/install
cp /mnt/tmp/images/pxeboot/initrd.img /boot/install/
cp /mnt/tmp/images/pxeboot/vmlinuz /boot/install/
cp /mnt/tmp/ks.cfg /boot/install/
umount /mnt/tmp
sed -i -r -e "s/--ip\s+[0-9\.]+/--ip $IP/g" -e "s/--hostname\s+\w+/--hostname $Hostname/" /boot/install/ks.cfg
cp /boot/grub/menu.lst /boot/grub/menu.lst.bak
echo "
default=0
timeout=20
title Install
kernel (hd0,0)/install/vmlinuz root=/dev/ram devfs=mount,dall ramdisk_size=8192 ks=hd:sda1:/install/ks.cfg network=static ip=$IP netmask=255.255.255.0 gateway=192.168.1.254
initrd (hd0,0)/install/initrd.img
" > /boot/grub/menu.lst
sed -n -e "/^title/,100p" /boot/grub/menu.lst.bak >> /boot/grub/menu.lst
echo 'You can reboot now'

其中hd(0,0)对应于sda1。

4. 在需要重装的机器上运行上面的脚本,然后reboot


5. 等待,应该很快的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值