• Installing Ubuntu from the network. PXE - loading everything! Mastering multi-booting over a local network. Setting up dynamically obtaining an IP address

    In the article he mentioned the possibility of installing “via network boot (PXE boot)”, thanks to which I decided to finally write material on creating a pxe boot server.

    The story will be based on the example of the same OS - Debian (so your paths and commands may differ).
    To begin with, let's install a tftp server. Let's look at the available options ( apt-cache search tftp | fgrep server):

    • atftpd
    • dnsmasq
    • tftpd
    • tftpd-hpa
    First I installed tftpd-hpa, because... it was described in the manual with which I started creating the server. Then I switched to atftpd because... I needed logging. Let's consider both options:
    • tftpd-hpa:
      Install the package, edit the file /etc/default/tftpd-hpa, so that the demon knows that he is worth living:

      #Defaults for tftpd-hpa
      RUN_DAEMON="yes"
      OPTIONS="-l -s /var/lib/tftpboot"

      Create the required directory: mkdir /var/lib/tftpboot, and we start the service invoke-rc.d tftpd-hpa start

    • atftpd:
      After installation, we discover that by default this service runs through inetd. For some reason, I’m not a fan of this method, so the first thing I did was comment out the corresponding line in /etc/inetd.conf. Then we edit /etc/default/atftpd:

      USE_INETD=false
      OPTIONS="--daemon --tftpd-timeout 1500 --no-multicast --retry-timeout 20 --logfile /var/log/atftpd.log --maxthread 100 --verbose=5 /var/lib/tftpboot"

      --tftpd-timeout- thread lifetime, in the absence of requests
      --retry-timeout- file upload timeout
      I have large timeouts set, because... the service is broadcast to the city local network, which periodically sag from the abundance of subscribers and cannot cope with the flow of requests.
      Well, as in the previous paragraph, we create the necessary directory: mkdir /var/lib/tftpboot, and we start the service invoke-rc.d atftpd start

    Now we have a tftp server. We've taken one step :)
    Next is the dhcp setup:
    • dhcp3:
      To the configuration file /etc/dhcp3/dhcpd.conf add download information:

      Filename "pxelinux.0";
      next-server ;

      If tftpd is installed on the same server as dhcpd, the next-server directive can be omitted. And restart dhcp3-server: invoke-rc.d dhcp3-server restart

    • dnsmasq:
      In config /etc/dnsmasq.conf add:

      Dhcp-boot=pxelinux.0, ,

      Again, if the tftp and dhcp servers match, the last 2 attributes do not need to be filled in. Restart: invoke-rc.d dnsmasq restart

    Step two completed. Next is the actual configuration of pxe-boot.
    Go to ftp.debian.org, select the directory installer-*, corresponding to the required architecture. Then go to the directory current/images/netboot inside we will find files netboot.tar.gz And gtk/netboot.tar.gz- these are text and graphical installation files, respectively. Choose the one you like, download and unpack it into /var/lib/tftpboot.
    All that remains is to make sure that access to UDP port 69 is allowed, and you can enjoy the delights of a network installation.

    As a bonus, I am attaching the menu that I came up with after several days of bullying:
    In the current configuration, it is possible to install several OS (Debian installation is possible in both text and graphical mode), boot xUbuntu (via nfs), SystemRescueCD (via http-boot), memtest86 (via tftp). Installation of all OS is possible for 2 architectures - x86 and x64. Because I have an intranet mirror of the Ubuntu 8.10 and Debian 5.0 repositories, but the installers do not offer a choice of repository, but automatically merge everything from it.
    Screenshots.

    This article will cover installing Ubuntu Linux from a network boot repository.

    So, we will install Ubuntu 10.04 on client computers from server 192.168.0.3, which hosts the network boot server and dhcpd. To install, the repository must have a directory dists/lucid/main/debian-installer. If you add similar directories for other repositories (multiverse, universe, restricted), then at the “Selecting and installing software” stage the list of software will be larger. In this guide I will consider this option. If you made a debmirror mirror, then most likely you don’t have these directories at all. You can download them, for example, from ftp://mirror.yandex.ru. Also, during installation, the installer, regardless of the selected repository, often accesses security.ubuntu.com.

    Step 1: Server Installation

    Installation of necessary applications:

    apt-get install tftpd-hpa openbsd-inetd

    Download and unpack the image for network installation:

    tar -xvzf netboot.tar.gz -C /var/lib/tftpboot/

    chown -R nobody:nogroup /var/lib/tftpboot

    For network boot, you need to pass 2 parameters to the client: the name of the boot file and the boot file server (in dhcpd these are the filename and next-server parameters):

    next-server 192.168.0.3;
    filename "pxelinux.0";

    The server is installed, you can install the system.

    Step 2: System Installation

    To install the system from a server on the network, you must enable network boot (PXE) in the BIOS. If your bios supports the boot menu, then it is better to use it to select the boot device - so that there are no problems if you forget to change the boot order.

    If everything is fine, then you will see the installer welcome screen:

    • Basic Ubuntu Server
    • Name server (DNS)
    • Edubuntu server
    • LAMP server
    • Mail server
    • OpenSSH server
    • PostgreSQL database
    • Print server
    • Samba file server
    • Ubuntu Enterprise Cloud
    • Virtual Machine host
    • 2D/3D creation and editing suite
    • Audio creation and editing suite
    • Edubuntu KDE desktop
    • Edubuntu desktop
    • Kubuntu desktop
    • Kubuntu netbook
    • LADSPA and DSSI audio plugins
    • Large selection of font packages
    • Mythbuntu additional roles
    • Mythbuntu frontend
    • Mythbuntu master backend
    • Mythbuntu slave backend
    • Ubuntu Netbook
    • Ubuntu Desktop
    • Video creation and editing suite
    • Xubuntu desktop
    • Manual package selection

    In the article he mentioned the possibility of installing “via network boot (PXE boot)”, thanks to which I decided to finally write material on creating a pxe boot server.

    The story will be based on the example of the same OS - Debian (so your paths and commands may differ).
    To begin with, let's install a tftp server. Let's look at the available options ( apt-cache search tftp | fgrep server):

    • atftpd
    • dnsmasq
    • tftpd
    • tftpd-hpa
    First I installed tftpd-hpa, because... it was described in the manual with which I started creating the server. Then I switched to atftpd because... I needed logging. Let's consider both options:
    • tftpd-hpa:
      Install the package, edit the file /etc/default/tftpd-hpa, so that the demon knows that he is worth living:

      #Defaults for tftpd-hpa
      RUN_DAEMON="yes"
      OPTIONS="-l -s /var/lib/tftpboot"

      Create the required directory: mkdir /var/lib/tftpboot, and we start the service invoke-rc.d tftpd-hpa start

    • atftpd:
      After installation, we discover that by default this service runs through inetd. For some reason, I’m not a fan of this method, so the first thing I did was comment out the corresponding line in /etc/inetd.conf. Then we edit /etc/default/atftpd:

      USE_INETD=false
      OPTIONS="--daemon --tftpd-timeout 1500 --no-multicast --retry-timeout 20 --logfile /var/log/atftpd.log --maxthread 100 --verbose=5 /var/lib/tftpboot"

      --tftpd-timeout- thread lifetime, in the absence of requests
      --retry-timeout- file upload timeout
      I have large timeouts set, because... the service is broadcast to the city local network, which periodically sag from the abundance of subscribers and cannot cope with the flow of requests.
      Well, as in the previous paragraph, we create the necessary directory: mkdir /var/lib/tftpboot, and we start the service invoke-rc.d atftpd start

    Now we have a tftp server. We've taken one step :)
    Next is the dhcp setup:
    • dhcp3:
      To the configuration file /etc/dhcp3/dhcpd.conf add download information:

      Filename "pxelinux.0";
      next-server ;

      If tftpd is installed on the same server as dhcpd, the next-server directive can be omitted. And restart dhcp3-server: invoke-rc.d dhcp3-server restart

    • dnsmasq:
      In config /etc/dnsmasq.conf add:

      Dhcp-boot=pxelinux.0, ,

      Again, if the tftp and dhcp servers match, the last 2 attributes do not need to be filled in. Restart: invoke-rc.d dnsmasq restart

    Step two completed. Next is the actual configuration of pxe-boot.
    Go to ftp.debian.org, select the directory installer-*, corresponding to the required architecture. Then go to the directory current/images/netboot inside we will find files netboot.tar.gz And gtk/netboot.tar.gz- these are text and graphical installation files, respectively. Choose the one you like, download and unpack it into /var/lib/tftpboot.
    All that remains is to make sure that access to UDP port 69 is allowed, and you can enjoy the delights of a network installation.

    As a bonus, I am attaching the menu that I came up with after several days of bullying:
    In the current configuration, it is possible to install several OS (Debian installation is possible in both text and graphical mode), boot xUbuntu (via nfs), SystemRescueCD (via http-boot), memtest86 (via tftp). Installation of all OS is possible for 2 architectures - x86 and x64. Because I have an intranet mirror of the Ubuntu 8.10 and Debian 5.0 repositories, but the installers do not offer a choice of repository, but automatically merge everything from it.
    Screenshots.

    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. The network 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), the 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 sends the boot image pxelinux.0 using the TFTP protocol. 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 operating system to the NFS server and make sure that the corresponding directories are exported.

    DHCP

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

    Make the file /etc/dhcpd.conf 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, enabling network boot in the BIOS. 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