歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux管理 >> Linux維護

Linux利用PXE安裝虛擬機的方法

之前和友人聊天,知道可以利用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測試的話,應每測試一次新建一個虛機。

Copyright © Linux教程網 All Rights Reserved