硬件准备:

PC一台 (笔记本或台式机)

路由器一台 (家用TP-LINK)

 

软件准备:

ubuntu ISO http://releases.ubuntu.com/14.04/ubuntu-14.04-server-amd64.iso

VirtalBox http://download.virtualbox.org/virtualbox/4.2.6/VirtualBox-4.2.6-82870-Win.exe (高版本创建的虚拟机不能网络启动,不知道是不是我系统问题。请自行测试)

 

结构图:

1

第一步:制做虚拟机

1.制做虚拟机 bootloader

给此虚拟机设置两块网卡

第一块网卡连接方式 桥接网卡

第二块网卡连接方式 内部网络

用 ubuntu-14.04-server-amd64.iso 给此虚拟机安装 ubuntu 系统。

3

2 

4

5

修改 bootloader /etc/network/interfaces 为

6    

重启网卡

ifdown eth1 && ifup eth1

2.制做虚拟机 N1

不用安装操作系统

设置启动顺序 网络 放在第一位

设置每台虚拟机的网卡,只需设置一块网卡就够了

网卡连接方式 内部网络

内存稍微给大点

7

8

第二步:在 bootloader 上安装软件

aptitude install dnsmasq atftp apache2-mpm-prefork

# dnsmasq 用来伺服 DNS, TFTP, DHCP 服务

# atftp 用来测试tftp server

# apache2-mpm-prefork 用来伺服 preseed 文件和源软件包源(用 ubuntu-14.04-server-amd64.iso 做软件包源)

# 在apche根目录下建立以下目录,netboot 用于TFTP根目录,ubuntu 用于mount ubuntu-14.04-server-amd64.iso镜像

mkdir -p /var/www/html/netboot

mkdir -p /var/www/html/ubuntu

mount -o loop /dev/cdrom /var/www/html/ubuntu

# 下载netboot.tar.gz文件到netboot目录

cd /var/www/html/netboot

wget -O http://mirrors.163.com/ubuntu/dists/trusty/main/installer-amd64/current/p_w_picpaths/netboot/netboot.tar.gz

tar zxvf /tmp/netboot.tar.gz

rm -f /tmp/netboot.tar.gz

rm -rf pxelinux.cfg

mkdir pxelinux.cfg

   

cat > pxelinux.cfg/default << EOT

default install        
label install        
     kernel ubuntu-installer/amd64/linux        
     append DEBCONF_DEBUG=5 auto=true priority=critical url=http://10.10.10.13/trusty.seed vga=788 initrd=ubuntu-installer/amd64/initrd.gz -- quiet 

EOT

   

cat >> /etc/dnsmasq.conf << EOT

# DHCP 地址范围        
dhcp-range=10.10.10.50,10.10.10.150,255.255.255.0,12h        
# DHCP 网关地址        
dhcp-option=3,10.10.10.13        
# DNS 地址        
dhcp-option=6,10.10.10.13        
enable-tftp        
# TFTP 根目录        
tftp-root=/var/www/html/netboot        
dhcp-boot=pxelinux.0        

EOT

service dnsmasq restart

cat > /var/www/html/trusty.seed << 'EOT'

### Localization    
d-i debian-installer/locale string en_US.utf8    
d-i console-setup/ask_detect boolean false    
d-i keyboard-configuration/layoutcode string us    
### Network configuration    
d-i netcfg/choose_interface select auto    
d-i netcfg/get_hostname string uos1404    
d-i netcfg/get_domain string local    
d-i netcfg/wireless_wep string    
### Mirror settings    
d-i mirror/country string manual    
d-i mirror/http/hostname string 10.10.10.13    
d-i mirror/http/directory string /ubuntu    
d-i mirror/http/proxy string    
#d-i mirror/suite select trusty    
### Clock and time zone setup    
d-i clock-setup/utc boolean true    
d-i time/zone string Asia/Shanghai    
d-i clock-setup/ntp boolean true    
### Partitioning    
d-i partman-auto/method string lvm    
d-i partman-lvm/device_remove_lvm boolean true    
d-i partman-md/device_remove_md boolean true    
d-i partman-lvm/confirm boolean true    
d-i partman-partitioning/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-md/confirm boolean true    
d-i partman-partitioning/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-lvm/confirm_nooverwrite boolean true    
d-i partman-auto-lvm/new_vg_name string uos    
d-i partman-basicfilesystems/no_mount_point boolean yes    
d-i partman-auto/choose_recipe select atomic    
#d-i partman-auto/choose_recipe select boot-root    
d-i partman-auto/expert_recipe string               \    
    boot-root ::                                    \    
        256 256 256 ext2                            \    
            $primary{ } $bootable{ }                \    
            method{ format } format{ }              \    
            use_filesystem{ } filesystem{ ext2 }    \    
            mountpoint{ /boot }                     \    
        .                                           \    
        4096 4096 4096 ext4                         \    
            $primary{ }                             \    
            method{ format } format{ }              \    
            use_filesystem{ } filesystem{ ext4 }    \    
        .                                           \    
        256 256 256 linux-swap                      \    
            $lvmok{ }                               \    
            method{ swap } format{ }                \    
            lv_name{ swap }                         \    
        .                                           \    
        1 2 100000 ext4                             \    
            $lvmok{ }                               \    
            method{ format } format{ }              \    
            use_filesystem{ } filesystem{ ext4 }    \    
            lv_name{ root }                         \    
            mountpoint{ / }                         \    
        .    
### Account setup    
d-i passwd/user-fullname string mole    
d-i passwd/username string mole    
d-i passwd/user-password password mole    
d-i passwd/user-password-again password mole    
d-i passwd/user-uid string 10000    
d-i user-setup/allow-password-weak boolean true    
d-i user-setup/encrypt-home boolean false    
### Apt setup    
d-i apt-setup/backports boolean false    
d-i apt-setup/security_host string 10.10.10.13    
d-i apt-setup/security_path string /ubuntu    
d-i apt-setup/no_mirror boolean true    
### Package selection    
tasksel tasksel/first multiselect server, openssh-server    
#d-i pkgsel/update-policy select none    
#d-i pkgsel/upgrade select none    
### Boot loader installation    
d-i grub-installer/only_debian boolean true    
d-i grub-installer/with_other_os boolean true    
### Kernel boot params    
d-i debian-installer/quiet  boolean false    
d-i debian-installer/splash boolean false    
### Finishing up the installation    
d-i finish-install/reboot_in_progress note    
d-i debian-installer/exit/poweroff boolean true    
### Bug fixed    
# see http://ubuntuforums.org/showthread.php?t=2215103&p=13015013    
d-i partman/early_command string umount /media || true; debconf-set partman-auto/disk "$(list-devices disk | head -n1)"    
# see http://www.michaelm.info/blog/?p=1378    
# If you use the server CD build the source package    
d-i live-installer/net-p_w_picpath string http://10.10.10.13/ubuntu/install/filesystem.squashfs

EOT

然后启动N1虚拟机完成自动安装

脚本:

https://code.csdn.net/u011288901/download/blob/master/pxe.zip


后记:

如果你不想用光盘镜像做源,你可以直接用国内镜像做安装源,如:mirrors.163.com

去掉 /var/www/html/trusty.seed 中 Bug fixed 部分,并将 10.10.10.13 替换为 mirrors.163.com

### Bug fixed      
# see http://ubuntuforums.org/showthread.php?t=2215103&p=13015013      
d-i partman/early_command string umount /media || true; debconf-set partman-auto/disk "$(list-devices disk | head -n1)"      
# see http://www.michaelm.info/blog/?p=1378      
# If you use the server CD build the source package      
d-i live-installer/net-p_w_picpath string http://10.10.10.13/ubuntu/install/filesystem.squashfs

   

为了进行多机器安装,而保留以下载的deb包,我们可以安装 apt-cacher-ng 作为包的缓存代理

aptitude install apt-cacher-ng

去掉 /var/www/html/trusty.seed 中 Bug fixed 部分,并将 10.10.10.13 替换为 10.10.10.13:3142

要详细配置 apt-cacher-ng,请自行查找资料

参考:

https://help.ubuntu.com/community/Installation/QuickNetboot

https://help.ubuntu.com/14.04/installation-guide/amd64/apb.html

http://ftp.dc.volia.com/pub/debian/preseed/partman-auto-recipe.txt

https://help.ubuntu.com/14.04/installation-guide/example-preseed.txt


E-mail: jmole.chen@gmail.com