PXE 网络安装 windows 或 linux

目标

管理一个局域网,网络内的电脑配置不一,安装系统是个很烦人的活儿。以前一直用 Windows Server 的部署服务 WDS 来给客户机安装系统,也尝试在 WDS 中添加 pxe Ubuntu Live CD 的引导。但是 Windows Server 启动太慢了,占用资源也多,近期把 Windows Server 换成了 Ubuntu。

ISC-DHCP-SERVER

# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#

allow booting;
allow bootp;

option domain-name "linux";
option domain-name-servers 111.11.11.1;
option option-128 code 128=string;
option option-128 code 129=text;
option rfc3442-classless-static-routes code 121 = array of integer 8;
option ms-classless-static-routes code 249 = array of integer 8;

option space pxelinux;
option pxelinux.magic code 208 = string;
option pxelinux.configfile code 209 = text;
option pxelinux.pathprefix code 210 = text;
option pxelinux.reboottime code 211 = unsigned integer 32;

option architecture-type code 93 = unsigned integer 16;

option space ipxe;
option ipxe-encap-opts code 175 = encapsulate ipxe;
option ipxe.priority code 1 = signed integer 8;
option ipxe.keep-san code 8 = unsigned integer 8;
option ipxe.skip-san-boot code 9 = unsigned integer 8;
option ipxe.syslogs code 85 = string;
option ipxe.cert code 91 = string;
option ipxe.privkey code 92 = string;
option ipxe.crosscert code 93 = string;
option ipxe.no-pxedhcp code 176 = unsigned integer 8;
option ipxe.bus-id code 177 = string;
option ipxe.san-filename code 188 = string;
option ipxe.bios-drive code 189 = unsigned integer 8;
option ipxe.username code 190 = string;
option ipxe.password code 191 = string;
option ipxe.reverse-username code 192 = string;
option ipxe.reverse-password code 193 = string;
option ipxe.version code 235 = string;
option iscsi-initiator-iqn code 203 = string;
# Feature indicators
option ipxe.pxeext code 16 = unsigned integer 8;
option ipxe.iscsi code 17 = unsigned integer 8;
option ipxe.aoe code 18 = unsigned integer 8;
option ipxe.http code 19 = unsigned integer 8;
option ipxe.https code 20 = unsigned integer 8;
option ipxe.tftp code 21 = unsigned integer 8;
option ipxe.ftp code 22 = unsigned integer 8;
option ipxe.dns code 23 = unsigned integer 8;
option ipxe.bzimage code 24 = unsigned integer 8;
option ipxe.multiboot code 25 = unsigned integer 8;
option ipxe.slam code 26 = unsigned integer 8;
option ipxe.srp code 27 = unsigned integer 8;
option ipxe.nbi code 32 = unsigned integer 8;
option ipxe.pxe code 33 = unsigned integer 8;
option ipxe.elf code 34 = unsigned integer 8;
option ipxe.comboot code 35 = unsigned integer 8;
option ipxe.efi code 36 = unsigned integer 8;
option ipxe.fcoe code 37 = unsigned integer 8;
option ipxe.vlan code 38 = unsigned integer 8;
option ipxe.menu code 39 = unsigned integer 8;
option ipxe.sdi code 40 = unsigned integer 8;
option ipxe.nfs code 41 = unsigned integer 8;

option client-architecture code 93 = unsigned integer 16;

option ipxe.no-pxedhcp 1;

default-lease-time 600;
max-lease-time 7200;
ddns-update-style none;
authoritative;
log-facility local7;
option ip-forwarding true;
option mask-supplier false;

subnet 192.168.14.0 netmask 255.255.255.0 {
    authoritative;
    range 192.168.14.12 192.168.14.252;
    option domain-name-servers 111.11.11.1;
    default-lease-time 600;
    max-lease-time 7200;
    option broadcast-address 192.168.14.255;
    option routers 192.168.14.1;
    ping-check true;
    # DHCP option 60 PXEClient
    #option vendor-class-identifier "PXEClient";
    option vendor-encapsulated-options 01:04:00:00:00:00:ff;

    class "pxeclient" {
        match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";

        # For iPXE Boot files
        if exists user-class and option user-class = "iPXE" {
            if option client-architecture = encode-int ( 16, 16 ) {
                option vendor-class-identifier "HTTPClient";
                filename "http://192.168.14.195/ipxe/ipxe.efi";
            } else {
                filename "http://192.168.14.195/ipxe/menu.ipxe";
            }
        } elsif option client-architecture = 00:00 {
            filename "undionly.kpxe"; # for booting legacy PXE
        } else {
            filename "ipxe.efi";      # for booting UFEI PXE
        }
    }

    next-server 192.168.14.195;

    host music1{
        hardware ethernet 00:00:00:d1:00:00;
        fixed-address 192.168.14.3;
    }
}

Apache2

lonely@lonely-Ubuntu:/srv/www$ tree -L 3
.
├── ipxe
│   ├── gparted-live.ipxe
│   ├── memdisk
│   ├── menu.ipxe
│   ├── ubuntu-live.ipxe
│   ├── ubuntu-live-nfs.ipxe
│   ├── wimboot
│   ├── winpe-amd64.ipxe
│   └── winpe-x86.ipxe
├── linux
│   ├── gparted
│   │   ├── filesystem.squashfs
│   │   ├── initrd.img
│   │   └── vmlinuz
│   ├── gparted-live-1.2.0-1-amd64.iso
│   ├── gparted-live-1.2.0-1-i686.iso
│   ├── hirsute-desktop-amd64.iso
│   ├── memdisk
│   └── ubuntu
│       ├── boot
│       ├── boot.catalog
│       ├── casper
│       ├── dists
│       ├── EFI
│       ├── install
│       ├── md5sum.txt
│       ├── pool
│       ├── preseed
│       └── ubuntu
├── tools
│   ├── ChromeSetup.exe
│   ├── Dism++10.1.1001.10_d4ba4eb035254b3326d6adc6638bc9c8daea7018.zip
│   ├── Firefox Setup 87.0.exe
│   ├── QQPinyin_Setup_6.6.6304.400.exe
│   ├── QQWubi_Setup_2.3.622.400.exe
│   ├── sogou_pinyin_102a.exe
│   ├── SPlayer-Setup-4.9.4.exe
│   ├── sysdiag-full-5.0.59.0-20210411.exe
│   └── weasel-0.14.3.0-installer.exe
└── winpe
    ├── amd64
    │   ├── fwfiles
    │   ├── media
    │   └── mount
    ├── LICENSE.txt
    ├── README.txt
    ├── src
    │   ├── assert.h
    │   ├── bootapp.h
    │   ├── byteswap.h
    │   ├── callback.S
    │   ├── cmdline.c
    │   ├── cmdline.h
    │   ├── compiler.h
    │   ├── coverity-model.c
    │   ├── cpio.c
    │   ├── cpio.h
    │   ├── ctype.h
    │   ├── die.c
    │   ├── efi
    │   ├── efiblock.c
    │   ├── efiblock.h
    │   ├── efiboot.c
    │   ├── efiboot.h
    │   ├── efi.c
    │   ├── efifile.c
    │   ├── efifile.h
    │   ├── efiguid.c
    │   ├── efi.h
    │   ├── efimain.c
    │   ├── efipath.c
    │   ├── efipath.h
    │   ├── efireloc.c
    │   ├── errno.h
    │   ├── huffman.c
    │   ├── huffman.h
    │   ├── i386.i
    │   ├── int13.c
    │   ├── int13.h
    │   ├── ipxe
    │   ├── lznt1.c
    │   ├── lznt1.h
    │   ├── lzx.c
    │   ├── lzx.h
    │   ├── main.c
    │   ├── Makefile
    │   ├── pause.c
    │   ├── pause.h
    │   ├── peloader.c
    │   ├── peloader.h
    │   ├── prefix.S
    │   ├── rotate.h
    │   ├── script.lds
    │   ├── sha1.c
    │   ├── sha1.h
    │   ├── startup.S
    │   ├── stdarg.h
    │   ├── stddef.h
    │   ├── stdint.h
    │   ├── stdio.c
    │   ├── stdio.h
    │   ├── stdlib.h
    │   ├── string.c
    │   ├── string.h
    │   ├── strings.h
    │   ├── vdisk.c
    │   ├── vdisk.h
    │   ├── vsprintf.c
    │   ├── wchar.h
    │   ├── wctype.h
    │   ├── wimboot.h
    │   ├── wimboot.i386
    │   ├── wimboot.x86_64
    │   ├── wim.c
    │   ├── wimfile.c
    │   ├── wimfile.h
    │   ├── wim.h
    │   ├── wimpatch.c
    │   ├── wimpatch.h
    │   ├── x86_64.i
    │   ├── xca.c
    │   └── xca.h
    └── x86
        ├── fwfiles
        ├── media
        └── mount

25 directories, 101 files

NFS

lonely@lonely-Ubuntu:/etc/ganesha$ cat ganesha.conf
###################################################
#
# Ganesha Config Example
#
# This is a commented example configuration file for Ganesha.  It is not
# complete, but only has some common configuration options.  See the man pages
# for complete documentation.
#
###################################################

## These are core parameters that affect Ganesha as a whole.
NFS_CORE_PARAM {
        ## Allow NFSv3 to mount paths with the Pseudo path, the same as NFSv4,
        ## instead of using the physical paths.
        mount_path_pseudo = true;

        ## Configure the protocols that Ganesha will listen for.  This is a hard
        ## limit, as this list determines which sockets are opened.  This list
        ## can be restricted per export, but cannot be expanded.
        #Protocols = 3,4,9P;
}

## These are defaults for exports.  They can be overridden per-export.
EXPORT_DEFAULTS {
        ## Access type for clients.  Default is None, so some access must be
        ## given either here or in the export itself.
        Access_Type = RW;
}

## Configure settings for the object handle cache
MDCACHE {
        ## The point at which object cache entries will start being reused.
        Entries_HWMark = 100000;
}

## Configure an export for some file tree
EXPORT
{
        ## Export Id (mandatory, each EXPORT must have a unique Export_Id)
        Export_Id = 46;

        ## Exported path (mandatory)
        Path = /srv/nfs/ubuntu;

        ## Pseudo Path (required for NFSv4 or if mount_path_pseudo = true)
        Pseudo = /ubuntu;

        ## Restrict the protocols that may use this export.  This cannot allow
        ## access that is denied in NFS_CORE_PARAM.
        #Protocols = 3,4;

        ## Access type for clients.  Default is None, so some access must be
        ## given. It can be here, in the EXPORT_DEFAULTS, or in a CLIENT block
        Access_Type = RW;

        ## Whether to squash various users.
        Squash = no_root_squash;

        ## Allowed security types for this export
        #Sectype = sys,krb5,krb5i,krb5p;

        ## Exporting FSAL
        FSAL {
                Name = VFS;
        }
}

## Configure an export for some file tree
EXPORT
{
        ## Export Id (mandatory, each EXPORT must have a unique Export_Id)
        Export_Id = 28;

        ## Exported path (mandatory)
        Path = /srv/lonely;

        ## Pseudo Path (required for NFSv4 or if mount_path_pseudo = true)
        Pseudo = /lonely;

        ## Restrict the protocols that may use this export.  This cannot allow
        ## access that is denied in NFS_CORE_PARAM.
        #Protocols = 3,4;

        ## Access type for clients.  Default is None, so some access must be
        ## given. It can be here, in the EXPORT_DEFAULTS, or in a CLIENT block
        Access_Type = RW;

        ## Whether to squash various users.
        Squash = no_root_squash;

        ## Allowed security types for this export
        #Sectype = sys,krb5,krb5i,krb5p;

        ## Exporting FSAL
        FSAL {
                Name = VFS;
        }
}

## Configure logging.  Default is to log to Syslog.  Basic logging can also be
## Configure logging.  Default is to log to Syslog.  Basic logging can also be
## configured from the command line
LOG {
        ## Default log level for all components
        Default_Log_Level = WARN;

        ## Configure per-component log levels.
        Components {
                FSAL = INFO;
                NFS4 = EVENT;
        }

        ## Where to log
        Facility {
                name = FILE;
                destination = "/var/log/ganesha.log";
                enable = active;
        }
}

nfs directory

sudo mount -o loop /srv/www/linux/hirsute-desktop-amd64.iso /mnt
sudo cp -a -r -v /mnt/. /srv/nfs/ubuntu/
showmount -e

menu.ipxe

lonely@lonely-Ubuntu:/srv/www/ipxe$ cat menu.ipxe
#!ipxe

set menu-timeout 5000
set submenu-timeout ${menu-timeout}

:start
menu iPXE boot menu
item --gap --             Welcome to use iPXE network boot system!
item --gap --             ------------------------- Operating systems ------------------------------
item --key w menu-winpe     Windows Preinstallation Environment...
item --key l menu-live      Linux Live Environments...
item --key b salstar        Chain http://boot.salstar.sk
item --gap --             ------------------------- Advanced options -------------------------------
item --key c config       Configure settings
item shell                Drop to iPXE shell
item reboot               Reboot computer
item
item --key x exit         Exit iPXE and continue BIOS boot
choose --timeout ${menu-timeout} --default menu-winpe selected || goto cancel
set menu-timeout 0
goto ${selected}

:menu-winpe
menu Windows Preinstallation environments
item winpe-x86       Boot Windows Preinstallation environments x86
item winpe-amd64       Boot Windows Preinstallation environments x64
item
item --key 0x08 back      Back to top menu...
choose --timeout ${submenu-timeout} --default winpe-amd64 selected && goto ${selected} || goto start

:menu-live
menu Linux Live Environments
item ubuntu-live          Boot Ubuntu LiveCD from http
item ubuntu-live-nfs      Boot Ubuntu LiveCD from nfs
item gparted-live         Boot Gparted LiveCD
item
item --key 0x08 back      Back to top menu...
choose --timeout ${submenu-timeout} --default ubuntu-live selected && goto ${selected} || goto start

:salstar
chain http://boot.salstar.sk

:ubuntu-live
chain ubuntu-live.ipxe


:ubuntu-live-nfs
chain ubuntu-live-nfs.ipxe

:gparted-live
chain gparted-live.ipxe


:winpe-x86
chain winpe-x86.ipxe


:winpe-amd64
chain winpe-amd64.ipxe


:pxelinux
echo Loading pxelinux ...
set next-server 192.168.14.195
set 209:string pxelinux.cfg/default
set 210:string tftp://${next-server}/
kernel ${url}pxelinux.0
boot

:cancel
echo You cancelled the menu, dropping you to a shell

:shell
echo Type 'exit' to get the back to the menu
shell
set menu-timeout 0
set submenu-timeout 0
goto start

:failed
echo Booting failed, dropping to shell
goto shell

:reboot
reboot

:exit
exit

:config
config
goto start

:back
set submenu-timeout 0
goto start

ipxe directory

lonely@lonely-Ubuntu:/srv/www/ipxe$ ls
gparted-live.ipxe  menu.ipxe         ubuntu-live-nfs.ipxe  winpe-amd64.ipxe
memdisk            ubuntu-live.ipxe  wimboot               winpe-x86.ipxe

configuration file

ipxe boot ubuntu live cd from nfs

lonely@lonely-Ubuntu:/srv/www/ipxe$ cat ubuntu-live-nfs.ipxe
#!ipxe

set server_ip 192.168.14.195
set nfs_path /ubuntu
kernel http://192.168.14.195/linux/ubuntu/casper/vmlinuz
initrd http://192.168.14.195/linux/ubuntu/casper/initrd
imgargs vmlinuz initrd=initrd boot=casper netboot=nfs ip=dhcp nfsroot=${server_ip}:${nfs_path} nosplash --
boot

ipxe boot ubuntu live cd from http

lonely@lonely-Ubuntu:/srv/www/ipxe$ cat ubuntu-live.ipxe
#!ipxe

# See http://manpages.ubuntu.com/manpages/precise/man7/casper.7.html for casper cmdline details
echo Booting Ubuntu Live for education
kernel http://192.168.14.195/linux/ubuntu/casper/vmlinuz
initrd http://192.168.14.195/linux/ubuntu/casper/initrd
imgargs vmlinuz initrd=initrd root=/dev/ram0 ip=dhcp url=http://192.168.14.195/linux/hirsute-desktop-amd64.iso splash --
boot

ipxe boot winpe x32

lonely@lonely-Ubuntu:/srv/www/ipxe$ cat winpe-x86.ipxe
#!ipxe

kernel wimboot
set arch x86
initrd http://192.168.14.195/winpe/${arch}/media/Boot/BCD                     BCD
initrd http://192.168.14.195/winpe/${arch}/media/Boot/boot.sdi                boot.sdi
initrd http://192.168.14.195/winpe/${arch}/media/sources/boot.wim             boot.wim
boot

ipxe boot winpe x64

lonely@lonely-Ubuntu:/srv/www/ipxe$ cat winpe-amd64.ipxe
#!ipxe

kernel wimboot
set arch amd64
initrd http://192.168.14.195/winpe/${arch}/media/Boot/BCD                     BCD
initrd http://192.168.14.195/winpe/${arch}/media/Boot/boot.sdi                boot.sdi
initrd http://192.168.14.195/winpe/${arch}/media/sources/boot.wim             boot.wim
boot
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值