现在的位置: 首页 > 综合 > 正文

redhat用kickstart.cfg自动安装后,挂载ISO镜像并从中拷贝文件

2014年08月12日 ⁄ 综合 ⁄ 共 947字 ⁄ 字号 评论关闭
# copy files from the rhel.iso image to system                                                                                      
if [ ! -b /tmp/cdrom ];then
  echo "make cdrom node using mknod" >> /root/ins.log
  # get the major number
  major=$(lsblk |grep rom | awk '{print $2}' |awk -F : '{print $1}')
  # get the minor number
  minor=$(lsblk |grep rom | awk '{print $2}' |awk -F : '{print $2}')
  echo "major=${major}  minor=${minor}" >> /root/ins.log
  # make sure we have what we need; create device node if so
  [ -n "$major" -a -n "$minor" ] && mknod /tmp/cdrom b ${major} ${minor}
fi

echo "mount the iso to /mnt/source" >> /root/ins.log
[ ! -d /mnt/source ] && mkdir -p /mnt/source
mount -t iso9660 -o ro /tmp/cdrom /mnt/source

这样的话我们的安装镜像rhel.iso就挂载到/mnt/source目录下,在kickstart.cfg的%post下添加拷贝文件的脚本

# copy the id_rsa.pub to authorized_keys
[ ! -d /root/.ssh ]  && mkdir -p /root/.ssh
cat /mnt/source/id_rsa.pub >> /root/.ssh/authorized_keys
[ $? -ne 0 ] && echo "copy id_rsa.pub to authorized_keys failed." >> /root/ins.log

原始问题:

redhat可以利用kickstart.cfg文件的内容进行自动化安装,并且在kickstart.cfg文件中加入%post标签就可以在安装结束后执行一些脚本,这些脚本放在%post标签后面。

但一个问题是,当安装好OS后,如果我们想从原始的ISO镜像拷贝文件到安装好的系统,那么必需对其进行挂载,以上代码实现了其功能

抱歉!评论已关闭.