PXE + KickStart: Use the virt-install tutorial to automatically install the linux system,

Source: Internet
Author: User

PXE + KickStart: Use the virt-install tutorial to automatically install the linux system,

Environment: Red Hat Enterprise Linux Server release 7.2 (Maipo)

Required Software: dhcp, tftp-server, system-config-kickstart, syslinux

Firewalled, selinux: Disabled

1. install and configure the DHCP service

[Root @ foundation76 ~] # Cat/etc/dhcp/dhcpd. conf

# Option definitions common to all supported networks... option domain-name "example.com"; # domain name option domain-name-servers 172.25.254.76; # specify DNS Server default-lease-time 600; # default lease period max-lease-time 7200; # log-facility local7; # log level A slightly different configuration for an internal subnet. subnet 172.25.254.0 netmask 255.255.255.0 {#172.25.254.0 network segment range 172.25.254.100 172.25.254.130; # address pool option domain-name-servers limit; option domain-name "example.com"; option routers limit; # gateway default-lease-time 600; max-lease-time 7200; next-server 172.25.254.76; # filename "pxelinux.0"; # Name of the Startup File}

[Root @ foundation76 ~] # Systemctl start dhcpd

[Root @ foundation76 ~] # Systemctl enable dhcpd. service

2. install and configure tftp-server

The dependency package is xinetd, And the tftp service is managed by xinetd.

[Root @ foundation76 ~] # Vim/etc/xinetd. d/tftp

Service tftp {socket_type = dgramprotocol = udpwait = yesuser = rootserver =/usr/sbin/in. tftpdserver_args =-s/var/lib/tftpboot-c # shared directory disable = no # yes --> no enable tftp service per_source = 11cps = 100 2 flags = IPv4}

[Root @ foundation76 ~] # Systemctl start xinetd

[Root @ foundation76 ~] # Systemctl enable xinetd

3. Copy the boot file required by the client from the centos image to the tftp shared directory.

[Root @ foundation76 ~] # Yum install httpd-y # install the http service and mount the centos Image

[Root @ foundation76 ~] # Mount/iso/CentOS-7-x86_64-DVD-1611.iso/var/www/html/centos/

[Root @ foundation76 ~] # Cp/var/www/html/centos/isolinux/*/var/lib/tftpboot/

[Root @ foundation76 ~] # Mkdir/var/lib/tftpboot/pxelinux. cfg

[Root @ foundation76 ~] # Cp/var/www/html/centos/isolinux. cfg/var/lib/tftpboot/pxelinux. cfg/default

[Root @ foundation76 ~] # Yum install syslinux # obtain the boot file pxelinux.0

[Root @ foundation76 ~] # Cp/usr/share/syslinux/pxelinux.0/var/lib/tftpboot/

[Root @ foundation76 ~] # Systemctl start httpd

Modify the startup configuration file

[Root @ foundation76 ~] # Vim/var/lib/tftpboot/pxelinux. cfg/default

Timeout 600 # The default timeout value is 60 s. If the timeout value is exceeded, no operation is performed, start the corresponding labellabel linux1 # label menu item menu label ^ Auto Install CentOS Linux 7 menu default # default boot item kernel vmlinuz # System kernel File append initrd = initrd. img inst. ks = http: // 172.25.254.76/ks. cfg inst. repo = http: // 172.25.254.76/centos quiet # inst. ks specifies the automatic response file ks. cfg; inst. repo specifies the image file

4. Use kickstart to create an automatic response File

[Root @ foundation76 ~] # Yum install system-config-kickstart-y

[Root @ foundation76 ~] # System-config-kickstart

Specify the time zone Asia/Shanghai, set the root user password, specify the installation and restart

Specify the installation source http: // 172.25.254.76/centos

Install a new boot loader on MBR

Create required partitions/,/boot, and swap, clear Master boot records, delete all existing partitions, and initialize disk tags.

Add Nic eth0

Authentication does not need to be modified. Disable firewalld.

Do not install graphical interfaces

The Package Selection item reports an error. You must manually specify

Pre-Installation Script & Post-Installation Script is the Script to be run by the system before and after Installation.

You can configure the YUM source or related services in advance in Post-Installation Script.

Click File in the upper left corner to save the configuration.

[Root @ foundation76 ~] # Vim/var/www/html/ks. cfg # specify the software package to be installed at the end

# Platform = x86, AMD64, or Intel EM64T # version = DEVEL # Install OS instead of upgradeinstall # Keyboard layoutskeyboard 'use' # Root passwordrootpw -- iscrypted $1 $ VDAOIANN $ cipher/# System timezonetimezone Asia/Shanghai # Use installationurl -- url = "http: // users/centos "# System authentication agelang en_US # Firewall configurationfirewall -- disabled # System authorization ionionauth -- useshadow -- passalgo = sha512 # Use graphical installgraphical # SELinux restart -- disabled # Do not configure the X window Systemskipx # Network informationnetwork -- bootproto = dhcp -- device = eth0 # Reboot after installationreboot # System bootloader configurationbootloader -- location = mbr # Clear the Master Boot Recordzerombr # Partition clearing informationclearpart -- all -- initlabel # disk partitioning informationpart/boot -- fstype = "xfs" -- size = 200 part swap -- fstype = "swap" -- size = 500 part/-- fstype = "xfs" -- grow -- size = 1% packages # Start With % packages @ base # base group package lftp # lftp tool @ core # core group package % end # end with % end

[Root @ foundation76 ~] # Ksvalidator/var/www/html/ks. cfg # Check whether the syntax of the ks. cfg file is correct.

So far, the client can be started to implement automatic installation through PXE.

Test:

Run the "virt-install" command on the kvm Virtual Machine to create a virtual host and test the automatic deployment of the linux system with pxe + kickstart unattended.

Basic usage of virt-install:

Options:

-H # view help

-- Connect = URL # The default connection is hypervisor, and the default connection is qemu: // system

-N NAME, -- name NAME # specifies the Virtual Machine NAME

-- Ram # specify the VM memory size (MB)

-- File # specify the Virtual Machine Disk file

-- File-size # specify the Virtual Machine disk size (G)

-- Vcpus # specifies the number of virtual CPUs of a Virtual Machine

-- Cdrom # set the path of the CD device or image

-- Location # specify other installation sources, such as http: // host/path

-- Extra-args # attaches the kernel command line parameters to the installer when you execute the Client installation from the specified location of the "-- location" option. For example, "ks = http: // 172.25.254.116/ks. cfg" specifies the automatic response File

-- Pxe # Start With PXE boot

-- Import # import existing virtual machines

-- OS-type # specify the operating system type

-- Network # specify the virtual network used by the VM

[Root @ foundation76 Desktop] # cat pxe_install.sh # create a VM and boot it in pxe Mode

#!/bin/bashvirt-install \--name $1 \--ram 1024 \--file /var/lib/libvirt/images/$1.qcow2 \--file-size 10 \--pxe \--network bridge=br0 

[Root @ foundation76 Desktop] #./pxe_install.sh world # Run the shell script to create the world VM.

We can see that PXE + kickstart is successfully installed on linux.

Other common parameters of virt-install can be used together:

1. The script automatically creates and installs the linux system by specifying the location of the network image and the location of the ks. cfg automatic response script file.

#!/bin/bashvirt-install \--name $1 \--ram 1024 \--file /var/lib/libvirt/images/$1.qcow2 \--file-size 8 \--location http://172.25.254.16/rhel7.2 \--extra-args "ks=http://172.25.254.116/ks.cfg" &

2. This script specifies to boot and install the linux operating system from the local optical drive.

#!/bin/bashvirt-install \--name $1 \--ram 1024 \--file /var/lib/libvirt/images/$1.qcow2 \--file-size 8 \--cdrom /home/kiosk/Desktop/rhel-server-7.2-x86_64-dvd.iso &  &>/dev/null

3. This script imports the existing virtual machine named node based on the existing node. qcow2 disk file.

#!/bin/bashvirt-install \--name node \--ram 1024 \--file /var/lib/libvirt/images/node.qcow2 \--import &

4. This script can be used to start and install the linux operating system from the local optical drive and connect to the virtual machine interface using VNC.

#!/bin/bashvirt-install \--name $1 \--ram 1024 \--file /var/lib/libvirt/images/$1.qcow2 \--file-size 8 \--cdrom /home/kiosk/Desktop/rhel-server-7.2-x86_64-dvd.iso \--vnc \--vncport=6000 \--vnclisten=172.25.254.16 &

5. This script can be used to reset an existing virtual host.

#!/bin/bashvirsh destroy $1rm -fr /var/lib/libvirt/images/$1.qcow2qemu-img create -f qcow2 -b /var/lib/libvirt/images/hello.qcow2/var/lib/libvirt/images/$1.qcow2virsh start $1virt-viewer $1 &

Complete !!!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.