Installing Windows over a network from a Linux server. PXE - loading everything! Mastering multiboot over a local network Installation over a Linux network via Windows

( 2018-04-10 )

PXE is an environment for booting a computer using a network card without using local media. The application possibilities are quite wide: from simply initial system boot to launching full-fledged working systems without using a local disk.

Some time ago, the author of these lines came into the hands of an old IBM ThinkCentre S51 8171 with a faulty CD drive. There were also problems with booting from a flash drive created using UNetBootin, and the last hope remained: loading the installer via PXE. The following will briefly describe the experience gained.

The IBM ThinkCentre S51 8171 has very good hardware for a machine manufactured in 2006: Pentium 4 540, 2x512MB DDR, 30GB ATA HDD. But in 2018 it looks faded, although even now it can be used in many ways. The main problem: the processor does not support EMT64 and therefore the operating system must be 32-bit. Fortunately, Ubuntu 16.04 exists in the i386 edition and it was decided to install it.

It was decided to use home server under Ubuntu management 16.04. To distribute addresses to local network isc-dhcp-server is used. The rest of the server configuration is quite typical. To create a PXE environment, we need a -server. We will use the "tftpd-hpa" package. Let’s install it, as well as (just in case) a tftp client:

Apt-get install tftpd-hpa tftp-hpa

By default, tftpd-hpa uses the "/var/lib/tftpboot" directory. If for some reason you need to change this, you need to edit the “/etc/default/tftpd-hpa” file accordingly and restart the “tftpd-hpa” service. But we are quite happy with the default configuration.

A list of available Ubuntu 16.04 installers for PXE booting and network installation can be found on this page. We are interested in the archive called "netboot.tar.gz" for the i386 architecture. Download and unpack it into the tftp server directory:

Wget http://archive.ubuntu.com/ubuntu/dists/xenial-updates/main/installer-i386/current/images/netboot/netboot.tar.gz mkdir -p /var/lib/tftpboot/ubuntu/tar zxfv netboot.tar.gz -C /var/lib/tftpboot/ubuntu/

This completes the preparation of the TFTP server and all that remains is to configure the DHCP server. The whole configuration comes down to adding the line:

# Path to the file "pxelinux.0" relative to the TFTP server directory filename "ubuntu/pxelinux.0";

This line can be added to the description of a subnet, a group of hosts, or even a specific host. The main thing is that the machine for which all this is being done receives the required configuration. After this, you can turn on the machine and select PXE boot to begin installing the system. After downloading the installer, the installation will proceed as usual, as if it had been downloaded from the "MinimalCD".

We could end here, but there is another interesting point: automatic installation. The Ubuntu installer partially supports the kickstart configuration format from RedHat Linux. You can read more. If there is a need to use a script automatic installation then you first need to create a script file and place it on a web server on the local network, then you need to slightly modify the file “/var/lib/tftpboot/ubuntu/ubuntu-installer/i386/boot-screens/txt.cfg”:

#append vga=788 initrd=ubuntu-installer/i386/initrd.gz --- quiet append ks=http://192.168.2.1/ks.cfg vga=788 initrd=ubuntu-installer/i386/initrd.gz -- - quiet

Here the "ks=" parameter specifies the URL where the kickstart configuration script is located. We will leave a more detailed study of this topic to the reader.

That's all. Have a nice work!

For a long time it remained a mystery to me why there are only two options in Ubuntu installation disk– Desktop and Alternate. In Debian, in addition to the usual full installation disks that install the full GNOME or KDE at once, there is also a NetInstall disk designed for installing the system over the network.

A boot CD in this version is designed to launch an installer that installs the minimum required set of packages. Everything else is downloaded and installed from the network if necessary. This option requires greater qualifications of the user performing the installation, but provides flexibility in installing only the necessary system components. This also saves disk space.

It turned out that Ubuntu also has an installation disk option designed for installation over a network. It's just that the download link is not located on home page site. And it is hidden at the following address.

I was interested in the question of what minimum size you can get an installed Ubuntu without performing special tricks. For the test, it was decided to install Ubuntu from a minimal disk in VirtualBox.

The minimum disk image size is 11MB. This is not much, and allows you to pump it out at any, even the lowest speed.

But during installation, it is advisable to have a faster Internet channel. Because the minimal disk, apart from the installer itself, does not contain anything. Therefore, during the installation process everything will download. Really everything!

First attempt installing Ubuntu I undertook from a minimal disk by connecting to the Internet via ADSL at a speed of 128 kbps. The installation (mostly downloading packages) took several hours.

For a repeat experiment, we were able to find a connection at a significantly higher speed.

When booting from a minimal disk, we are first greeted with a text prompt:

and then the standard boot graphical(!) Ubuntu menu:

The existing "Command-line install" item does not mean that the installation will be done from the command line. In any case, the installer starts in text mode.

The “Advanced options” item contains an additional menu:

allowing you to perform Expert install. When you select it, a menu appears with installation actions, allowing you to perform them in almost random order:

I select the item “Install”.

The text installer is normal. Same as in Alternate disk. The only difference is that the packages are not taken from the disk, but are downloaded over the network.

The installer traditionally asks for the language:

configures the keyboard layout:

then prompts you to select a repository:

which by default is offered local for the selected country:

Today, more and more tasks are being automated, and virtualization is increasingly being used to maximize the efficiency of servers. But you still have to install operating systems. Everyone does it in their own way: some have pockets full of different images for all occasions, others carry a “purse” with discs, or even two, in the old fashioned way. As a rule, administrators do this work with little pleasure. Let's look at how to reduce time for trivial tasks, how to teach computers to install systems on their own, without the participation of an administrator at all, using only a local network.

So, today we will learn: install Windows and Linux over the network, load small ISO images, useful software (all sorts of Kaspersky, Acronis, WinPE, memtests), deploy thin clients and manage them. So that, for example, an accountant working with 1C via RDP doesn’t beat you up because her Windows crashed, and the report needed to be prepared yesterday... Or a stingy boss who doesn’t want to update his computer admired your professionalism when will see how Windows 8 flies on old computers... A server that provides boot over the network (PXE) will help us achieve our insidious goals.

Anyone system administrator I have a universal USB drive in my stash for emergency computer resuscitation. Agree, it would be much better to have the same functionality using just one network card. It should also be noted that it is possible to simultaneously work with several nodes at once. So, based on our needs, we have two solutions: use PXE or LTSP.

LTSP is not very suitable for us: it is designed to load the OS installed on the server itself over the network, which allows the use of LTSP server applications. This is not exactly what we need. PXE is a tool for booting a computer over a network without using local storage media, just like LTSP. PXE allows you to organize a multi-boot boot menu, similar to a universal “USB resuscitator”.


What will we implement?

It all started with the need to have at hand a tool for remote installation of Ubuntu/Debian Server over the network, with the ability to boot a Live CD of a small system, like SliTaz or Kolibri OS.
As they say, appetite comes with eating: we didn’t have time to implement what we planned, and a number of “wants” were added to the plan. As a result, the list turned out to be quite impressive.

  1. Thinstation Linux-based thin clients.
  2. Linux section.
    1. Installing Ubuntu 14.04 x86.
    2. Installing Ubuntu 14.04 x64.
    3. Installing Ubuntu 12.04 x86.
    4. Installing Ubuntu 12.04 x64.
  3. Windows partition.
    1. Installing Windows 2012.
    2. Installing Windows 7.
  4. Acronis.
    1. Windows PE with a package of useful software.
    2. Acronis True Image.
      1. Legacy BIOS.
      2. UEFI.
    3. Acronis Disk Director.
      1. Legacy BIOS.
      2. UEFI.
  5. Kaspersky Rescue v 10.
  6. ERD Commander from 5 to 8 via ISO image.
  7. Memtest.

We put everything together and take off

As a distribution kit for the server, the choice fell on Ubuntu Server 04.14.2 LTS. You can choose any other OS, the only difference will be in the syntax. So let's get started. We will need TFTP, DHCP (not necessarily installed on the same server; a router can act as a DHCP server), a service for organizing an NFS network file system. We will consider only those settings that interest us within the topic. First of all, let's install everything you need, after making all the updates:

Continuation is available only to members

Option 1. Join the “site” community to read all materials on the site

Membership in the community within the specified period will give you access to ALL Hacker materials, increase your personal cumulative discount and allow you to accumulate a professional Xakep Score rating!

Not long ago I was faced with a situation where I needed to install Windows on a laptop over the network, because... there were no other options. Because I already had a similar experience, but a long time ago, so there was a need to refresh my knowledge, although in the end it turned out that it was necessary to understand it all over again =).

Introduction

During the description, I will assume that we already have a Linux server and download from it via pxe.

To work we need the following software:

  • hpa-tftpd
  • samba
  • pxelinux
  • dhcpd

We will skip setting up dhcpd, pxelinux, and samba. Only changes that need to be made to the configuration of these services will be described.

Preparing the necessary files

First, let's create a directory structure in the working directory of the tftp server.

mkdir /tftpboot/install

mkdir /tftpboot/install/win

cd /tftpboot

ln -s install/win win

Next, copy all installation files and folders from the Windows disk to the folder /tftpboot/install/win. As you will notice the file names are all in uppercase. To correct this oversight, do the following in the /tftpboot/install/win/i386 folder:

ls -1 |awk ‘(system(“mv “$0″ “tolower($0)))’

After this, you should copy from this folder to the root of the tftp server following files: startrom.n12, SETUPLDR.BIN(you need to rename it to ntldr) BOOTFONT.BIN, ntdetect.com. They can be packed and then the last letter of the extension will be replaced with an underscore character. You can unpack them using the utility cabextract.


floppyless = "1"
msdosinitiated = "1"
; Needed for second stage
OriSrc = "\\10.0.0.254\WINXP\win\i386″
OriType = "4"
LocalSourceOnCD = 1
DisableAdminAccountOnDomainJoin = 1


OsLoadOptions = "/noguiboot/fastdetect"
; Needed for first stage
SetupSourceDevice = "\Device\LanmanRedirector\10.0.0.254\WINXP\win"


; Avoid automatic format/repartition
Repartition = No
UseWholeDisk = No


ComputerName = *
ProductID=XXXXX-XXXXX-XXXXX-XXXXX-XXXXX

Naturally, we indicate our data (path, server and serial number).

After that, go to the i386 folder and unpack the drivers.cab archive

cabextract drivers.cab

Setting up the BINL service

I hope you have already downloaded the archive ris-linux via the link above. If not, then download it, after which you can continue setting up.

Service BINL created in order to Windows installer transfer network card drivers. Yes. This is a paradoxical situation - the bootloader has loaded over the network, but cannot communicate with the network itself, without this service and the subsequently loaded driver.

Unpack the archive into a folder /opt(It is recommended to install any unnecessary software there). Let's go to the folder. There are quite a lot of files there, but we won't need all of them. So, we need to provide network card drivers. To do this, you first need to create a list of them. This is done like this:

infparser.py /tftpboot/install/win/i386

Now you can start the service:

./binlsrv.py &

By the way. If the bootloader will not load, then there is a file to bring it into working hours fixloader.py.

fixloader.py /tftpboot/ntldr

Setting up hpa-tftpd

Because When writing the path to a file, Windows and Linux use different slashes, you need to make sure that tftp-the server understood what they wanted from him. To do this, create a file /etc/tftpd.rules the following content:

After that this file, you need to indicate to the server. To do this, edit it configuration file and use the -m flag to specify the path to the file. In Gentoo this file is called /etc/conf.d/in.tftpd. We find and reduce the launch options line to the following form:

INTFTPD_OPTS="-c -R 4096:32767 -s $(INTFTPD_PATH) -v -m /etc/conf.d/tftpd.rules"

The -v flag is also specified here. It is needed for debugging. So that when something goes wrong, you can see what files were requested and whether they were given.

Setting up Samba

The first stage of installation pulls files via tftp, and the second (which after a reboot) can retrieve files via a share, with hard drive or from a CD. Naturally, in our case we need to create a ball with installation files.

Add to smb.conf approximately the following lines:


comment = install files
path = /tftpboot/install
public = yes
writable = yes
guest only = yes

Important point. The global option must be set: null passwords = true

And one more important point— please note that inside the shares there must be at least one directory in which the installation files are already located. If you immediately share the folder with the installation files, you will get an error at the very beginning of the installation.

Setting up pxelinux

This operation is the simplest. You need to add the following lines to your pxelinux.cfg/default:

label WinXP Home Install from Network
kernel install/win/startrom.0

All. You can now download and install.

In server rooms, servers without CD/DVD drives are increasingly being found. From time to time they need to install an operating system, and installing over a network can greatly help with this. You simply turn on the server and begin the installation. LAN card must support PXE technology. PXE - Pre-Boot Execution Environment - allows you to boot over the network.

But PXE is not enough for complete happiness; a technology that will completely automate the installation is kickstart (developed by Red Hat). Its essence is simple - we compile a file in advance containing the values ​​of all options that may be needed during installation. Moreover, we can execute our scripts before and after installation, thereby setting the settings for the future OS.

Installing a typical Linux kit using kickstart takes 5-7 minutes.

The Install server requires 3 services and 1 package.


  • DHCP provides clients with network credentials

  • TFTP is an easy way to share files over the network

  • Syslinux contains the pxelinux.0 bootloader and some other files

  • NFS allows file system access over the network
The installation process can be divided into stages:

  1. pxe - pxe firmware starts working when we set the installation over the network in the BIOS, or when the MBR is not found on the HDD.

  2. DHCP phase 1 - the client receives network details and the address of the tftp server, as well as the name of the loader file (pxelinux.0). By default, the TFTP server is a DHCP server.

  3. TFTP - the pxelinux.0 loader contacts the TFTP server and requests from it initrd.img (Initial RAM disk, temporary file system), Linux kernel.

  4. Kernel - transfer of control to the Linux kernel.

  5. DHCP phase 2 - the Linux kernel makes a request to the DHCP server to obtain network details and subsequently the NFS server address.

  6. NFS - the stage when the NFS partition is mounted

  7. init - /sbin/init is launched and control is transferred to it. Init is the main process in the system, other processes are child processes of init.
Freely stated:

The DHCP server listens for bootp requests on its network; after it receives a request, it looks at the source MAC address, and if it has a corresponding entry for that MAC address, it starts working with it. The DHCP server provides the client with network details (IP address, gateway, DNS server,...) and, using the TFTP protocol, sends boot image pxelinux.0. This image is enough to display the OS selection menu.

Having selected the OS, we begin loading the kernel and begin the installation, in the process selecting the installation source - the NFS server. You need to upload the prepared content of the future to the NFS server operating system and ensure that the appropriate directories are exported.

DHCP

Install DHCPD and add it to startup:
# yum -y install dhcp
# chkconfig dhcpd on

Make the /etc/dhcpd.conf file like this:

Ddns-update-style interim;
ignore client-updates;
subnet 192.168.146.0 netmask 255.255.255.0 (
option routers 192.168.146.1;
option subnet-mask 255.255.255.0;
option domain-name "domain.local";
option domain-name-servers 192.168.146.1;
default-lease-time 21600;
max-lease-time 43200;
Allow boot;
Allow booting;
host unixbox (
hardware ethernet 00:0c:29:77:9c:9c;
fixed-address 192.168.146.128;
filename "pxelinux.0";
option host-name "unixbox";
next-server 192.168.146.1;
}
}

Launch DHCPD or reboot if it was running:
# service dhcpd restart

Disable the firewall, which is enabled by default (otherwise the target computer will receive the error “ICMP Destination unreachable (Host administratively prohibited)” upon boot):
# service iptables stop
# chkconfig iptables off

TFTP

Install the tftp-server package from the repository:
# yum -y install tftp-server

Now you need to enable tftp in the xinetd configuration; to do this, in the /etc/xinetd.d/tftp file, change “disable = yes” to “disable = no” and enable xinetd:
# service xinetd start

We check that the tftp server port is listening (tftp runs on port 69):
# netstat -nlp | grep:69
udp 0 0 0.0.0.0:69 0.0.0.0:* 3105/xinetd

Syslinux

The package contains a set of files for downloading over the network. We need pxelinux.0, which we will serve as a boot image via DHCP, and menu.c32, with which a more attractive user menu will be drawn. (For CentOS 4, the updated syslinux with dependencies must be downloaded from rpmfind.net.)

# cp $(rpm -ql syslinux | grep menu.c32) /tftpboot/
# cp $(rpm -ql syslinux | grep pxelinux.0) /tftpboot/

NFS

By default, the system most likely has NFS, if not, install it using yum.
# chkconfig nfs on

Add an entry to the /etc/exports file:
echo “/var/install-server/ *(ro,no_root_squash)” >> /etc/exports

Launch the nfs server:
# service nfs start

We check that the directory has been exported:
#exportfs
/var/install-server

We create the structure of the tftp server, add content to the server:
# mkdir -p /tftpboot/(pxelinux.cfg,centos5_x86)
# mkdir -p /var/install-server/centos5_x86

We mount our DVD with CentOS 5 and upload the contents to /var/install-server/centos5_x86:
# mount /dev/cdrom /mnt/
# cp -r /mnt/* /var/install-server/centos5_x86/
# cp /var/install-server/centos5_x86/images/p xeboot/* /tftpboot/centos5_x86/

In the /tftpboot/pxelinux.cfg directory, create a default file and fill it in as shown below:
default menu.c32

prompt 0
timeout 100

kernel /centos5_x86/vmlinuz
append initrd=/centos52_x86/initrd.img
label Quit
localboot 0

Installing the OS over the network

After all the manipulations described above, we can begin installing the OS. We start our machine with the MAC address 00:0c:29:77:9c:9c, turning on BIOS loading over the network. When the installation begins, we do everything in the standard way, except that in the list of where to install the OS, you need to select NFS, and then, when asked, indicate:
NFS server name: 192.168.146.1
CentOS directory: /var/install-server/centos5_x86

Automate installation with Kickstart

To automate, you need to create a file containing all the necessary information that may be required during the installation process. Such a file is created by the system-config-kickstart program (GUI tool) in any CentOS with X Window:
# yum -y install system-config-kickstart
# system-config-kickstart

After we have created the file using system-config-kickstart, it needs to be transferred to the Install server and made available via one of the HTTP, NFS or FTP protocols. Since the Install server actively uses NFS, we will use it.

In my case, the kickstart file is located in /var/install-server/centos5_x86/centos5_ x86_ks.cfg .

To the file /tftpboot/pxelinux.cfg/default you just need to add the ks directive indicating the location of the kickstart file. Example with kickstart file:
default menu.c32
menu title Linux Install Server. Please choose OS to install.
prompt 0
timeout 100
label CentOS 5 x86 Custom install
kernel /centos5_x86/vmlinuz
append initrd=/centos5_x86/initrd.img
label CentOS 5 x86 Kickstart Install
kernel /centos52_x86/vmlinuz
append initrd=/centos5_x86/initrd.img ks=nfs:192.168.146.1:/var/install-server/c entos5_x86/centos5_x86_ks.cfg
label Quit
localboot 0

Now, having selected “CentOS 5 x86 Kickstart Install” in the OS selection menu, we will only have to wait for the server with the OS installed on it.

Below is an example of my Kickstart file. I wanted the installed OS to have the “PermitRootLogin yes” option in the sshd settings. The Kickstart file allows you not only to set OS installation parameters, but also to execute scripts before installation (%pre) and after (%post). This way you can write a lot of tuning scripts and get a completely finished OS in 5-10 minutes of installation.

#platform =x86, AMD64, or Intel EM64T
# System authorization information
auth --useshadow --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
#Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --disabled
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# Installation logging level
logging --level=info
# Use NFS installation media
nfs --server=192.168.146.1 --dir=/var/install-server/centos5_x86
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
#Root password
rootpw --iscrypted $1$Bz09jb2I$hfzh2vApqMjG0sEPsAwNr/
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone Europe/Moscow
# Install OS instead of upgrade
install
# Disk partitioning information
part swap --bytes-per-inode=4096 --fstype=”swap” --size=512
part / --bytes-per-inode=4096 --fstype=”ext3” --grow --size=1

%post --interp /bin/bash
PATH=/somework
/bin/mkdir$PATH
/bin/sed -e ‘s/#PermitRootLogin yes/PermitRootLogin yes/g’ /etc/ssh/sshd_config > $PATH/sshd_config_edited
/bin/cp $PATH/sshd_config_edited /etc/ssh/sshd_config
/bin/rm -rf $PATH