- Сетевая установка Linux
- Установка через PXE
- Установка Linux через iPXE
- PXEInstallServer
- Installing needed packages
- Configure tftpd-hpa
- Configure dhcpd
- Configure tftpd-hpa
- Install apache
- Copying Ubuntu files
- Customising the install
- Use your ks.cfg
- Boot and install
- Using the CD (or .iso) directly
- Boot Ubuntu via http/ftp server with pxe(diskless boot)
- Pxe short info
- How i do it
- Customize initramfs
- Creating squashfs
- Setup bootloader, squashfs, and pxe server
- Conclusion
Сетевая установка Linux
Недавно столкнулся с установкой Centos 7 в необычных условиях.
Во-первых, дома. То есть имел дело с локальными компьютером, а не с сервером с IPMI.
Во-вторых, за неимением дискового привода обычно использую загрузочную флешку, которая в данном случае оказалась бесполезной, так как новый компьютер загружается только с флешек с инсталятором Windows. Проблема не новая, судя по отзывам о материнской плате.
В моем распоряжении осталась сеть. Приведу пример установки Centos 7 по PXE и iPXE
Итак, начнем.
Как установить Linux через ipxe?
Как установить Linux через pxe?
Установка через PXE
Соединим ethernet кабелем компьютер1 — на котором будут DHCP, TFTP и компьютер2 — на который должна быть установлена ОС.
Добавим статичные настройки сетевого адаптера на компьютер1. Мой адрес 192.168.1.50.
Скачаем и установим TFTP. В этой программе настроим DHCP и TFTP сервер с которого отдадим IP адрес и установочные файлы компьютеру2.
Отключим брандмауэр и запустим tftpd с правами администратора. Выставим аналогичные установки, как на картинках. Возможно потребуется перезапуск tftpd.
На компьютере2 в boot меню выберем сетевой адаптер. В окне tftpd на компьютере1 будет отображаться шкала прогресса.
После этого, на компьютере2 загрузится окно инсталлятора ОС.
Установка Linux через iPXE
Скачаем образ ipxe.iso. Rufus-ом создадим загрузочную флешку на основе этого образа.
Выложим скрипт install.ipxe на любой веб сервер. О том, как поднять веб сервер на локальном компьютере можно узнать тут. Адрес моего скрипта будет таким sitename.ru/install.ipxe
Содержимое скрипта install.ipxe для установки Centos 7
#!ipxe set base http://mirror.centos.org/centos/7/os/x86_64 prompt -k 0x197e -t 2000 Press F12 to install CentOS. || exit kernel $/images/pxeboot/vmlinuz initrd=initrd.img repo=$ initrd $/images/pxeboot/initrd.img boot
По аналогии с этим скриптом для установки Centos 7, можете подготовить свой скрипт для установки другой ОС.
Соединим компьютер, на который необходимо установить Linux, и роутер ethernet кабелем. Вставим флешку и загрузимся с нее. После нажатия F12 появится ipxe консоль. Используем следующие команды для получения IP адреса и скачивания скрипта
iPXE> dhcp DHCP (net0 52:54:00:12:34:56). ok iPXE> chain http://sitename.ru/install.ipxe
PXEInstallServer
This will guide you through running an Ubuntu server as PXE install server. You’ll need to run a DHCP server on your network, not necessarily this server but you do need one.
Installing needed packages
- For Ubuntu 10.04, there is a bug with inetutils-inetd. It only listens on IPv6, and not on IPv4. As a quick workaround, you can use openbsd-inetd instead.
If this is also going to be your DHCP server, install dhcp server contained in the follwing package: dhcp3-server (see InstallingSoftware)
Configure tftpd-hpa
You’ll need to tell tftpd-hpa to start its daemon (which it doesn’t by default). To do this, edit the /etc/default/tftpd-hpa file, and make sure that it looks something like this:
#Defaults for tftpd-hpa RUN_DAEMON="yes" OPTIONS="-l -s /var/lib/tftpboot"
Then, run the startup script to actually start the daemon
Configure dhcpd
If your pxe server is also your dhcp server, you’ll need something like this in /etc/dhcp3/dhcpd.conf
subnet 192.168.0.0 netmask 255.255.255.0 range 192.168.0.100 192.168.0.200; filename "pxelinux.0"; >
If you have an existing dhcp server, you should point it to your pxe server by doing something like the following
subnet 192.168.0.0 netmask 255.255.255.0 filename "pxelinux.0"; next-server ; >
Be sure to restart your dhcp server so that the changes take effect
sudo /etc/init.d/dhcp3-server restart
Configure tftpd-hpa
tftpd-hpa is called from inetd. The options passed to tftpd-hpa when it starts are thus found in /etc/inetd.conf
The defaults are fine for us, your /etc/inetd.conf should have an entry like this
tftp dgram udp wait root /usr/sbin/in.tftpd /usr/sbin/in.tftpd -s /var/lib/tftpboot
(although you may need to edit this file and replace udp with ‘udp4’, as tftpd-hpa seems to expect an IPv6 address now)
Now we’ll copy the needed files from the Ubuntu CD
sudo cp -r /media/cdrom/install/netboot/* /var/lib/tftpboot/
If your dhcp server issues correct network info and your pxe clients will have network access, then at this point you will be able to do an Ubuntu install using internet repositories.
I want to go a little further however and install everything from the install server as well as customise some of the packages to install.
Install apache
Currently nfs installs aren’t well supported (Please correct me if I’m wrong) so we’ll install over http. For that we need a webserver on our install server too: install the following package apache (see InstallingSoftware).
Copying Ubuntu files
Create an ubuntu directory under your freshly installed apache’s document root and copy all of the contents of the Ubuntu Alternate CD to that directory
mkdir /var/www/ubuntu cp -r /media/cdrom/* /var/www/ubuntu/
Customising the install
There is a package called system-config-kickstart which is a GUI frontend to creating kickstart files. The kickstart file tells the installer where to get its packages from, what to install and a number of other useful settings. See KickstartCompatibility for more info.
This package does not have to be installed on your install server, it can be on a convenient Ubuntu desktop somewhere.
Create a custom ks.cfg with system-config-kickstart, be sure to specify HTTP under «Installation Method». Provide the IP of you install server and make the HTTP Directory /ubuntu/ Save the file and copy it to your install server under /var/www/html/
A very minimalist ks.cfg file which only uses the installation files on the install server and asks for all other questions might look like this
install url --url http://192.168.0.1/ubuntu/
Use your ks.cfg
In order for your network Ubuntu install to use your kickstart file, you have to tell it where to find it. Edit /var/lib/tftpboot/pxelinux.cfg/default and add ks=http:///ks.cfg to the append line. It should then look something like this (note that the append line is one line)
label linux kernel ubuntu-installer/i386/linux append ks=http://192.168.0.1/ks.cfg vga=normal initrd=ubuntu-installer/i386/initrd.gz ramdisk_size=16432 root=/dev/rd/0 rw --
In Jaunty the default file has been broken up into includes. The append line can be found in /ubuntu-installer/i386/boot-screens/text.cfg
label install menu label ^Install (from my http server) menu default kernel ubuntu-installer/i386/linux append ks=http://192.168.0.1/ks.cfg vga=normal initrd=ubuntu-installer/i386/initrd.gz -- quiet
Boot and install
You should now be able to boot another pc on the lan over the network and have it install Ubuntu automagically You can vary the tftp and http install points to have multiple versions of Ubuntu available to install on your network.
Using the CD (or .iso) directly
You can also achieve the above without actually copying any files anywhere. You can mount the CD (or the .iso) and then do additional mounts with the —bind option. The advantage is that you can upgrade the CD (or the .iso) without needing to update the install server files.
For example, after mounting the CD (or the .iso) to /media/cdrom/, you can mount the ubuntu files to the web directory
mount --bind /media/cdrom/ /var/www/ubuntu/
Similarly, you can do the same with the tftproot:
mount --bind /media/cdrom/install/netboot/ /var/lib/tftpboot/
If you were to create a pxelinux.cfg directory with an appropriate default file, you can mount that over the top of the mounted CD, so that the tftp server gives out your pxelinux.cfg/default file. For example, a pxelinux.cfg directory in ~/pxelinux.cfg could be mounted like this
mount --bind ~/pxelinux.cfg /var/lib/tftpboot/pxelinux.cfg
(Note that in the above example, the actual mount point of the directory would end up as /var/lib/tftpboot/ubuntu-installer/i386/pxelinux.cfg because the pxelinux.cfg is a symlink on the CD (or .iso))
PXEInstallServer (последним исправлял пользователь 71-223-168-121 2010-07-24 17:53:54)
The material on this wiki is available under a free license, see Copyright / License for details
You can contribute to this wiki, see Wiki Guide for details
Boot Ubuntu via http/ftp server with pxe(diskless boot)
PXE is a great solution for booting a diskless computer (or a computer without an OS installed). This method is often used for terminal stations and OS mass installation.
Stock ubuntu (16.04) in pxe-mode can mount rootfs only from NFS. But this is not a great idea: any difficulties with the network/NFS server and the user gets problems.
In my opinion, it’s best to use other protocols, such as http/ftp. Once booting, you will have an independent system
You should add information about the limits of applicability of the proposed solution and what are the dependencies and restrictions.
Pxe short info
PXE (Preboot Execution Environment) is a special method for booting a computer from the bios / EFI.
How it works (simplified scheme):
- The computer bios/uefi sends ordinary dhcp request (DHCPDISCOVER)
- The dhcp server sends a response with the next-server option
- The computer sends DHCPREQUEST/DHCPINFORM request
- The dhcp server sends TFTP server address and the filename to upload
- The computer downloads this file from the tftp server. Its size is limited so, often, it’s a bootloader like pxeinux
- pxelinux reads its own config and downloads Linux kernel using initramfs
- Linux kernel downloads squashfs with main rootfs
- switch_root to its squashfs
Keep in mind that TFTP is a slow protocol. It works around UDP with a small block size (512K). Of course, you can increase this value, but this is a way of unstable operation.
- get bootloader via tftp
- get kernel (+ initramfs) via tftp
- get main rootfs squash via http/tftp
How i do it
- Add modules to initramfs
- Write my own boot script and add it to initramfs
- Make new initramfs
- Create squashfs with future rootfs
- Setup pxe server
- Run it
I used squashfs for rootfs (the simplest way is to create squashfs from installed ubuntu). Overlayfs is necessary to make rootfs writable.
Supported protocols are http/ftp, but you can try to add others via curl/other software.
Customize initramfs
There are 2 places where you can customize initramfs in ubuntu:
I’ll use /usr/share/initramfs-tools. First, I added needed support modules in initramfs:
boozlachu@comp:~$ cat /usr/share/initramfs-tools/modules.d/pxe overlayfs squashfs
Next, I wrote a boot script that does all the work:
boozlachu@comp:~$ cat /usr/share/initramfs-tools/scripts/pxe #!/bin/bash mountroot() < maxTryCount=5 squashfsFile="/tmp/rootfs.squashfs" squashfsMountPoint="/mnt/ro" tmpfsMountPoint="/mnt/rw" overlayfsUppderDir="$tmpfsMountPoint/upper" overlayfsWorkDir="$tmpfsMountPoint/work" overlayfsDir="/mnt/overlayfs" tryCount="1" # run udevadm wait_for_udev 10 # parce kernel cmdline args. rooturl needed for x in $(cat /proc/cmdline); do case $x in rooturl=*) export rooturl=$;; maxTryCount=*) export maxTryCount=$ ;; esac done log_begin_msg "Loading modules" modprobe squashfs || panic "can't modprobe squashfs" modprobe af_packet || panic "can't modprobe af_packet" modprobe overlay || panic "can't modprobe overlayfs" log_success_msg "modules loaded" log_begin_msg "Configure network" configure_networking || panic "Can't configure network" log_success_msg "Network configured" log_begin_msg "Download rootfs" while [ ! -f $ ] && [ $ -le $ ]; do wget $ -O $ || log_failure_msg "Can't download rootfs, count $" tryCount=$(( $ + 1 )) sleep 0.5 done if [ -f $ ] then log_success_msg "Rootfs downloaded" else panic "Can't download rootfs" fi log_begin_msg "Mount rootfs" mkdir -p $squashfsMountPoint mount -t squashfs -o loop $squashfsFile $squashfsMountPoint || panic "Can't mount rootfs" log_success_msg "Rootfs mounted" log_begin_msg "Mount tmpfs" mkdir -p $tmpfsMountPoint mount -t tmpfs none $tmpfsMountPoint || panic "Tmpfs mount failed " log_success_msg "Tmpfs mounted" log_begin_msg "Mount overlayfs" mkdir -p $overlayfsUppderDir $overlayfsWorkDir $overlayfsDir mount -t overlay overlay -o lowerdir=$squashfsMountPoint,upperdir=$overlayfsUppderDir,workdir=$overlayfsWorkDir $overlayfsDir \ || panic "Overlayfs mount failed" log_success_msg "Overlayfs mounted" log_begin_msg "Move tmpfs and squashfs to new root" mkdir -p $overlayfsDir/$tmpfsMountPoint $overlayfsDir/$squashfsMountPoint mount --move $squashfsMountPoint $overlayfsDir/$squashfsMountPoint || panic "squashfs move failed" mount --move $tmpfsMountPoint $overlayfsDir/$tmpfsMountPoint || panic "tmpfs move failed" log_success_msg "Tmpfs and squashfs moved" log_begin_msg "Move overlayfs to new root" mount --move $overlayfsDir $ || panic "" >
The script has a lot of messages for understanding how it works.
After the modules and script, add your need to generate new initramfs:
boozlachu@comp:~$ sudo update-initramfs -c -k all
Creating squashfs
- install ubuntu on drive
- boot from LiveCD
- create squashfs from the installed system
I don’t recommend this way for production since you’ll have a very large squashfs (not the best idea for pxe)!
Setup bootloader, squashfs, and pxe server
I use pxelinux as a pxe bootloader. It’s an easy way. My pxe servers are Debian 10, tftp-hpa,dhcpd, and lighttpd.
I’ll omit the installation details, but I’ll show the important info.
TFRP server file struct (/srv/tftp is root dir fot tftp-hpa):
root@debian:/srv/tftp/ubuntu# tree /srv/tftp/ /srv/tftp/ └── ubuntu ├── firmware.sq ├── initrd ├── ldlinux.c32 ├── libcom32.c32 ├── libutil.c32 ├── menu.c32 ├── pxelinux.bin ├── pxelinux.cfg │ └── default ├── vesamenu.c32 └── vmlinuz
- firmware.sq is squashfs with rootfs
- *c32 are files for pxelinux
- vmlinuz is kernel
- initrd is initramfs(which i rebuild earler)
- pxelinux.bin — main pxelinux file
- default is config for pxelinux
root@debian:/srv/tftp/ubuntu# cat /srv/tftp/ubuntu/pxelinux.cfg/default ui menu.c32 timeout 30 default ubuntu_pxe font UniCyr_8x16.psf menu title PXE Special Boot Menu menu color tabmsg 37;40 #80ffffff #00000000 menu color hotsel 30;47 #40000000 #20ffffff menu color sel 30;47 #40000000 #20ffffff menu color scrollbar 30;47 #40000000 #20ffffff LABEL ubuntu_pxe menu label Run ubuntu pxe kernel vmlinuz append initrd=initrd rooturl=http://192.168.56.2/ubuntu/firmware.sq boot=pxe maxTryCount=10
It’s impotant to set the correct kernel parameters:
- rooturl=http://192.168.56.2/ubuntu/firmware.sq, url for rootfs
- boot=pxe, use my script for boot
- maxTryCount=10, number of tries for rootfs download (optional, default value 5)
And the last one is the dhcp config:
root@debian:/srv/tftp/ubuntu# cat /etc/dhcp/dhcpd.conf subnet 192.168.56.0 netmask 255.255.255.0 < range 192.168.56.10 192.168.56.45; option routers 192.168.56.2; option domain-name-servers 192.168.2.1 ; option broadcast-address 192.168.56.255; default-lease-time 3600; max-lease-time 7200; # Important! Set bootloader file filename "ubuntu/pxelinux.bin"; >
The extended variant (if the dhcp and tftp servers placed on different machines) requires the next-server option for dhcp.
Conclusion
This article shows you how to change the boot mode of ubuntu without any difficulties. Use it as information and write your solutions. This can be a system in the form of firmware (with squashfs), pxe, or another solution.