VirtualBox 模擬ubuntu14.04無人值守安裝

硬件準備:

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/images/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-image 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-image 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: [email protected]

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章