感谢支持
我们一直在努力

通过PXE安装虚拟机

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


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


1.1 dnsmasq


apt-get install dnsmasq


vim /etc/dnsmasq.conf


bogus-priv


filterwin2k


interface=eth0


dhcp-range=192.168.100.172,192.168.100.180,12h


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


dhcp-boot=pxelinux.0


enable-tftp


tftp-root=/var/ftpd


dhcp-authoritative



/etc/init.d/dnsmasq restart


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


1.2 PXE
mkdir /var/www/ubuntu


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


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


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


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


1.3 Apache


apt-get install apache2


vi /etc/apache2/sites-available/default


<VirtualHost *>


ServerName ubuntu


DocumentRoot /var/www/ubuntu


<Directory /var/www/ubuntu>


Options ExecCGI FollowSymLinks


AllowOverride all


allow from all


Order allow,deny


</Directory>


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


</VirtualHost>


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


/etc/init.d/apache2restart

1.4KickStart
vi /var/www/Ubuntu/ks.cfg#System language


lang en_US


#Language modules to install


langsupport en_US


#System keyboard



keyboard us


#System mouse


mouse


#System timezone


timezone Asia/Chongqing



#Root password


rootpw –disabled


#Initial user gaojinbo/gaojinbo.com


user hua –fullname hua –passwordpassword


#Reboot after installation


reboot



#Use text mode install


text


#Install OS instead of upgrade


install


#Use Web installation


url –urlhttp://192.168.100.171/ubuntu



#System bootloader configuration


bootloader –location=mbr


#Clear the Master Boot Record


zerombr yes


#Partition clearing information


clearpart –all –initlabel



#Disk partitioning information


part / –fstype ext4 –size 10000


part swap –size 5000



auth –useshadow –enablemd5


network –bootproto=dhcp –device=eth0


#network –bootproto=static–ip=192.168.5.168 –netmask=255.255.255.0 –gateway=192.168.100.1–nameserver=221.5.88.88 –device=eth0



firewall –disabled


skipx


%packages


@openssh-server


1.5ubuntu-server.seed
vi /var/www/ubuntu/ubuntu-server.seed# Suggest LVM by default.


d-i partman-auto/init_automatically_partition stringsome_device_lvm


d-i partman-auto/init_automatically_partition seen false


# Always install the server kernel.


d-i base-installer/kernel/override-image string linux-server


# Install the Ubuntu Server seed.


tasksel tasksel/force-tasks string server


# Only install basic language packs.


d-i pkgsel/language-pack-patterns string


# No language support packages.


d-i pkgsel/install-language-support boolean false


# Only ask the UTC question if there are


d-i clock-setup/utc boolean false


d-i clock-setup/ntp boolean false


d-i apt-setup/use_mirror boolean false


d-i netcfg/get_ipaddress string 127.0.0.1


d-i mirror/http://hostname string 127.0.0.1


d-i apt-setup/restricted boolean false



# No boot splash screen.


d-i debian-installer/splash boolean false


# Install the debconf oem-config frontend (if in OEM mode).


d-i oem-config-udeb/frontend string debconf


# Add the network and tasks oem-config steps by default.


oem-config oem-config/steps multiselect language, \


timezone, keyboard, user, network, tasks


1.6 注意点
用虚机为pxeclient测试的话,应每测试一次新建一个虚机.新建出的虚机的网络配置如下:


  <network>
  <name>test</name>
  <forward mode=’nat’/>
  <ip address=”192.168.123.1″ netmask=”255.255.255.0″>
    <tftp root=”/var/ftpd” />
    <dhcp>
      <range start=”192.168.123.2″ end=”192.168.123.254″ />
      <bootp file=”pxelinux.0″ />
    </dhcp>
  </ip>
</network>

赞(0) 打赏
转载请注明出处:服务器评测 » 通过PXE安装虚拟机
分享到: 更多 (0)

听说打赏我的人,都进福布斯排行榜啦!

支付宝扫一扫打赏

微信扫一扫打赏