透过PXE安装设想机

本文在一个虚拟机(Ubuntu
11.04 server)中建立PXE Server, 然后在KVM中通过PXE安装一个虚拟机(Ubuntu
11.04 Server ). 这两个虚拟机显然都处在同一个局域网内.

1.关闭防火墙

因为PXE虚要裸机在启动时通过DHCP协议去找PXE server要IP,
所以对于跨局域网的PXE安装需要DHCP中继, 这不在本文的讨论范围内, 可参照:
PXE跨局域网之系统自动安装
http://www.linuxidc.com/Linux/2012-07/65146.htm

 图片 1

1.1 dnsmasq

2.PXE环境准备

apt-get install dnsmasq

2.1服务器静态IP设置

vim /etc/dnsmasq.conf

    sudo vi /etc/network/interfaces

bogus-priv

 图片 2

filterwin2k

启动eth1网络

interface=eth0

    sudo ifup eth1

dhcp-range=192.168.100.172,192.168.100.180,12h

 图片 3

dhcp-host=52:54:00:ed:00:f7,192.168.100.178

2.2安装服务

dhcp-boot=pxelinux.0

2.2.1 安装dnsmasq作为dncp服务

enable-tftp

sudo apt-get install dnsmasq

tftp-root=/var/ftpd

配置dhcp文件  

dhcp-authoritative

    sudo vi /etc/dnsmasq.conf

/etc/init.d/dnsmasq restart

图片 4

注意:如果想要为pxe
client分配固定IP,可使用dhcp-host参数.采用这种方式的好处是可以避免将已经网络的IP搞乱.
如果使用KVM提供的虚机作为pxe client来测试时,
应该每测试一次新建一个虚机(千万不能重复测试).

    bogus-priv

1.2 PXE mkdir /var/www/ubuntu

    filterwin2k

mount -o loop/bak//kvmimages/ubuntu-11.10-server-amd64.iso /mnt

    interface=eth1

cp /mnt/preseed/ubuntu-server.seed /var/www/ubuntu
cp -a /mnt/* /var/www/ubuntu
cp -r /mnt/install/netboot/* /var/ftpd/

    dhcp-range=10.0.4.100,10.0.4.200,12h

vim /var/ftpd/pxelinux.cfg/default
default linux
label linux
    kernel ubuntu-installer/amd64/linux
    append ks=
preseed/url= vga=normal
initrd=ubuntu-installer/amd64/initrd.gz —

    dhcp-host=08:00:27:0f:9b:1E,10.0.4.10

注意, 上述ks,与preseed应该配置一个Web服务器指向/var/www/ubuntu目录.

    dhcp-boot=pxelinux.0

1.3 Apache

    enable-tftp

apt-get install apache2

    tftp-root=/var/ftpd

vi /etc/apache2/sites-available/default

    dhcp-authoritative

<VirtualHost *>

创建tftp目录

ServerName ubuntu

    sudo mkdir –p /var/ftpd

DocumentRoot /var/www/ubuntu

启动dnsmasq服务

<Directory /var/www/ubuntu>

    sudo service dnsmasq start

Options ExecCGI FollowSymLinks

2.2.3 安装apache2服务,提供需要安装的操作系统文件

AllowOverride all

sudo apt-get install apache2

allow from all

浏览器验证httpd服务正常

Order allow,deny

 图片 5

</Directory>

apache2配置可以访问安装文件目录

ErrorLog/var/log/apache2/error-ubuntu.log

    sudo vi sites-enabled/000-default.conf

</VirtualHost>

 图片 6

sudo ln -s
/etc/apache2/sites-available/default/etc/apache2/sites-enabled/ubuntu

    sudo vi /etc/apache2/apache2.conf

/etc/init.d/apache2restart

 图片 7

图片 8

    sudo mkdir -p  /var/www/ubuntu

重启apache2目录

    sudo service apache2 restart

浏览器验证httpd服务正常

 图片 9

2.3.复制ubuntu14.04操作系统全目录,内核与启动镜像文件

挂载ubuntu –server.iso镜像     sudo mount /dev/cdrom /mnt

复制pxe启动文件和操作系统文件

    sudo cp  -vr /mnt/install/netboot/*  /var/ftpd

 图片 10

    cp –varf  /mnt/* /var/www/ubuntu

 图片 11

创建ks.cfg脚本

sudo touch /var/www/ubuntu/ks.cfg

#Generated by Kickstart Configurator

#platform=x86

#System language

lang en_US

#Language modules to install

langsupport en_US

#System keyboard

keyboard us

#System mouse

mouse

#System timezone

timezone Asia/Shanghai

#Root password

rootpw –iscrypted $1$NmOzxhNQ$Y5NsgGIYUumYf7UBFthqs/

#Initial user

user –disabled

#Reboot after installation

reboot

#Use text mode install

text

#Install OS instead of upgrade

install

#Use Web installation

url –url

#System bootloader configuration

bootloader –location=mbr 

#Clear the Master Boot Record

zerombr yes

#Partition clearing information

clearpart –all –initlabel 

#Disk partitioning information

part /boot –fstype ext4 –size 500 

part swap –size 4096 

part / –fstype ext4 –size 1 –grow –maxsize 1 

#System authorization infomation

auth  –useshadow  –enablemd5 

#Network information

network –bootproto=dhcp –device=eth0

#Firewall configuration

firewall –disabled –ssh 

#Do not configure the X Window System

skipx

%packages

@openssh-server

sudo touch /var/www/ubuntu/ubuntu-server.seed

### Localization.

d-i auto-install/enable boolean true

d-i debian-installer/locale string en_US

#d-i localechooser/translation/warn-light boolean true

#d-i localechooser/translation/warn-severe boolean true

d-i console-setup/ask_detect boolean false

d-i keyboard-configuration/layoutcode string us

d-i keyboard-configuration/modelcode string SKIP

### Net interface setting.

d-i netcfg/choose_interface select eth0

d-i netcfg/dhcp_failed note

d-i netcfg/get_hostname string ubuntu

d-i netcfg/get_domain string ubuntu

### Mirror setting. use the local proxy.

d-i mirror/country string manual

d-i mirror/protocol string http

d-i mirror/http/hostname string 10.0.4.10

d-i mirror/http/directory string /ubuntu/

d-i mirror/http/proxy string

### Clock and timezone setting. use local ntp.

d-i clock-setup/utc boolean true

d-i time/zone string Asia/Chongqing

d-i clock-setup/ntp boolean true

### Partioning setting.

#d-i partman-auto/disk string /dev/sda

#d-i partman-auto-lvm/guided_size string max

#d-i partman-auto/choose_recipe select atomic

d-i partman-auto/method string regular

#d-i partman-lvm/confirm boolean true

#d-i partman-lvm/confirm boolean true

#d-i partman-lvm/confirm_nooverwrite boolean true

d-i partman-lvm/device_remove_lvm boolean true

d-i partman-lvm/device_remove_md boolean true

d-i partman/choose_recipe select atomic

d-i partman/default_filesystem string ext4

d-i partman/confirm_write_new_label boolean true

d-i partman/choose_partition select finish

d-i partman/confirm boolean true

d-i partman/confirm_nooverwrite boolean true

#d-i partman/confirm_write_new_label boolean true

### Account setting.

d-i passwd/root-login boolean false

d-i passwd/user-fullname string test

d-i passwd/username string test

d-i passwd/user-password password test

d-i passwd/user-password-again password test

d-i user-setup/allow-password-weak boolean true

d-i user-setup/encrypt-home boolean false

d-i live-installer/net-image string

### Package selection.

d-i pkgsel/include string openssh-server

d-i pkgsel/upgrade select none

d-i pkgsel/update-policy select none

tasksel tasksel/first multiselect standard, ubuntu-server

### Boot loader installation.

d-i grub-installer/only_debian boolean true

d-i grub-installer/with_other_os boolean true

### finishing up the installation.

d-i finish-install/reboot_in_progress note

### Running custom commands.

#d-i preseed/late_command string echo “hello” >> /root/test

2.4启动选择安装配置文件

    sudo vi /var/ftpd/pxelinux.cfg/default

# D-I config version 2.0

#include ubuntu-installer/amd64/boot-screens/menu.cfg

#default ubuntu-installer/amd64/boot-screens/vesamenu.c32

#prompt 0

#timeout 0

default linux

label linux

kernel ubuntu-installer/amd64/linux

append ks=
 preseed/url=
vga=normal initrd=ubuntu-installer/amd64/initrd.gz –-

2.5 新建虚拟机测试pxe结果

图片 12

图片 13

相关文章