无人值守安装linux

无人值守安装

新建一个适配器

安装需要的软件 dhcp tftp-erver xinetd syslinux vsftpd

[root@localhost ~]# yum -y install dhcp tftp-server xinetd syslinux vsftpd

修改dhcp配置文件

``
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf

  subnet 192.168.2.0 netmask 255.255.255.0 {   #声明一个网段
    range 192.168.2.50 192.168.2.100;    #地址池
    next-server 192.168.2.10;    #tftp服务器的ip
    filename "pxelinux.0";         #引导文件的第一个文件名称  (isolinux.bin)
  }

``

编辑tftp的配置文件

``

  [root@localhost ~]# vim /etc/xinetd.d/tftp
  disable                 = no

``

去到tftp的传输目录拷贝一些必要的虚拟机配置内容

``

  [root@localhost dhcp]# cd /var/lib/tftpboot/   #tftp的传输目录
  [root@localhost tftpboot]# cp /usr/share/syslinux/pxelinux.0 ./    #引导程序
  [root@localhost tftpboot]# mount /dev/sr0 /lang
  mount: /dev/sr0 写保护,将以只读方式挂载
  [root@localhost tftpboot]# cp /lang/images/pxeboot/vmlinuz ./    #虚拟的内核
  [root@localhost tftpboot]# cp /lang/images/pxeboot/initrd.img ./   #虚拟的根文件系统
  [root@localhost tftpboot]# cp /lang/isolinux/vesamenu.c32 ./    #菜单
  [root@localhost tftpboot]# cp /lang/isolinux/splash.png ./     #背景图片
  [root@localhost tftpboot]# cp /lang/isolinux/boot.* ./    #提示信息
  [root@localhost tftpboot]# mkdir pxelinux.cfg      #创建引导程序的配置文件的目录
  [root@localhost tftpboot]# cp /lang/isolinux/isolinux.cfg pxelinux.cfg/default   #引导程序默认的配置文件

``

因为要让程序自动安装 所以要选择默认的安装配置 只能创建一个目录 让其加载default的配置文件

``

  [root@localhost tftpboot]# vim pxelinux.cfg/default 
   1 default linux    #把菜单选择成默认安装linux的选项
   64   append initrd=initrd.img inst.stage2=ftp://192.168.2.10/centos ks=ftp://192.168.2.10/centos/ks.cfg quiet
  #指定ftp服务器的地址和kickstart配置文件的地址

``

去到ftp的共享目录将镜像里面的内容拷贝到共享目录里面

``

  [root@localhost tftpboot]# cd /var/ftp/
  [root@localhost ftp]# mkdir centos
  [root@localhost ftp]# cp -r /lang/* centos/

``

复制本机的kickstart文件

[root@localhost ftp]# cp /root/anaconda-ks.cfg centos/ks.cfg

编辑的本机kickstart文件

``

  [root@localhost ftp]# vim centos/ks.cfg
  # Use CDROM installation media
  url --url=ftp://192.168.2.10/centos
  最后面添加
  reboot
  eula --agreed

``

给kickstart文件可读权限

[root@localhost ftp]# chmod +r centos/ks.cfg

重启所有服务

``

  [root@localhost ftp]# systemctl restart dhcpd
  [root@localhost ftp]# systemctl restart tftp
  [root@localhost ftp]# systemctl restart xinetd
  [root@localhost ftp]# systemctl restart vsftpd

``
验证
创建一个虚拟机,内存要在2g以上 网络适配器要在同一个网段内

原文地址:https://www.cnblogs.com/hzcya1995/p/13309058.html