This project aims to create a PXE guest to install other servers (for now CentOS7 en CoreOS)
The PXE server will contain the following services:
- Named
- TFTP
- DHCP
- Nginx
export PXE_STAGE=/opt/stage/pxe
mkdir -p ${PXE_STAGE}
cd ${PXE_STAGE}
export CENTOS_ISO=CentOS-7-x86_64-DVD-1810.iso
curl -s http://mirrors.up.pt/pub/centos/7.6.1810/isos/x86_64/CentOS-7-x86_64-DVD-1810.iso -O ${PXE_STAGE}/CentOS-7-x86_64-DVD-1810.iso
cat > ${PXE_STAGE}/pxe-net.xml <<EOF
<network>
<name>pxe-net</name>
<bridge name="pxe-br0" />
<forward/>
<ip address="192.168.40.1" netmask="255.255.255.0" />
</network>
EOF
sudo virsh net-define ${PXE_STAGE}/pxe-net.xml
sudo virsh net-autostart pxe-net
sudo virsh net-start pxe-net
mkdir -p ${PXE_STAGE}/guests/pxe/
virt-install \
-n pxe \
-v \
--description="PXE machine" \
--os-type=Linux \
--os-variant=generic \
--ram=512 \
--vcpus=1 \
--graphics=vnc \
--disk path=${PXE_STAGE}/guests/pxe/pxe.img,bus=virtio,size=10 \
--cdrom=${PXE_STAGE}/${CENTOS_ISO} \
--network=bridge:pxe-br0,model=virtio,mac=52:54:00:e2:87:5a
When the guest boots will present a graphical interface, the PXE server is installed with the minimum packages
To start de installation vncviewer should be used:
vncviewer :0
- IP: 192.168.40.10
- Gateway: 192.168.40.1
- DNS: 192.168.40.1
- Hostname: pxe.demobox.local
- Root password: Welcome1
- Keyboard:
- Timezone:
for mac in `virsh domiflist pxe |grep -o -E "([0-9a-f]{2}:){5}([0-9a-f]{2})"` ; do ip n |grep $mac |grep -o -P "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" ; done
ssh-keygen -R 192.168.40.10 -f ~/.ssh/known_hosts
ssh-keyscan -t rsa 192.168.40.10 >> ~/.ssh/known_hosts
ssh-copy-id [email protected]
ssh [email protected] shutdown -h now
cat > ${PXE_STAGE}/pxe-cdrom.xml <<EOF
<disk type='block' device='cdrom'>
<driver name='qemu' type='raw'/>
<source dev='${PXE_STAGE}/${CENTOS_ISO}'/>
<target dev='hda' bus='ide'/>
<readonly/>
</disk>
EOF
virsh update-device pxe ${PXE_STAGE}/pxe-cdrom.xml
virsh domblklist pxe
virsh start pxe
The hosts_names is a list of guest to be installed, the mac addresses should match with the parameter --network network=pxe-net,model=virtio,mac=52:54:00:e2:87:5c
in the virt-install
pxeservers:
hosts:
192.168.122.219:
hosts_names: ["pxe-boot","pxe-master1","pxe-agent1"]
hosts_ips: ["192.168.30.100","192.168.30.101","192.168.30.102"]
hosts_mac_addrs: ["52:54:00:e2:87:5c","52:54:00:e2:87:5d","52:54:00:e2:87:5e"]
hosts_roles: ["boot","master","agent"]
ansible-playbook -i conf/hosts pxe.yml
ssh [email protected] reboot
virsh destroy pxe;virsh undefine pxe;rm -rf ${PXE_STAGE}/guests/pxe/
virsh net-destroy pxe-net
virsh net-undefine pxe-net
Now the guests for the other applications can be created
- Insert a cdrom in the guest drive:
virsh change-media pxe hda --insert /opt/stage/CentOS-7-x86_64-DVD-1708.iso
- Eject the cdrom:
virsh attach-disk pxe " " hda --type cdrom --mode readonly
- Start a guest:
virsh start pxe
- List the block devices of a guest:
virsh domblklist pxe
- List the network devices of a guest:
virsh domiflist pxe-boot