很多小伙伴都不知道可以利用PXE安装虚拟机,其实这是可以的。下面小编就把学习到的方法分享给大家。希望对大家有帮助。
方法如下:
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
ServerName ubuntu
DocumentRoot /var/www/ubuntu
Options ExecCGI FollowSymLinks
AllowOverride all
allow from all
Order allow,deny
ErrorLog/var/log/apache2/error-ubuntu.log
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
以上就是利用PXE安装虚拟机的方法了。值得注意的一点是我们如果要用虚机为pxeclient测试的话,应每测试一次新建一个虚机。