]> www.opopop.net Git - reminder/blob - booting_linux_through_the_network.mdwn
attachment upload
[reminder] / booting_linux_through_the_network.mdwn
1 The internet is not short of tutorials about how to boot your Linux
2 computer through the network, you will find links to some of these in
3 the following. This is my own howto about that, with a focus on
4 lightweight tools; the case for a diskless workstation will not be
5 covered.
6
7 You will be interested in this
8 method for installing on a set of servers, as it doesn't involve
9 moving a CD reader or USB stick around. The network method is useful
10 also for a laptop or notebook, which may not have a CD reader.
11
12 The network boot method is also fine for recovery, in case your boot
13 sector is messed up and you can't use a CD reader.
14
15 What about booting with USB, which is today present everywhere? See
16 next section.
17
18 # Booting using USB: maybe not so universal
19
20 Probably the easiest for an individual installation... when it works!
21 Three different ways to organize a USB key for booting seem to exist,
22 and not all are always recognized by your BIOS. See for instance these
23 references:
24
25 1. [General information about bootable USB sticks](http://www.rm.com/Support/TechnicalArticle.asp?cref=TEC818956)
26 1. ["Universal" USB key builder](http://advancemame.sourceforge.net/boot-readme.html)
27 1. [About USB-ZIP](http://lime-technology.com/forum/index.php?topic=2407.0)
28 1. [Debian USB install from hybrid iso](http://kitenet.net/~joey/blog/entry/Debian_USB_install_from_hybrid_iso/)
29 1. [Boot Debian from an USB device](http://www.debian-administration.org/article/Boot_Debian_from_an_USB_device)
30
31 Despite the above information, I was never able to boot using USB with
32 one of my motherboard. This was actually one of the reason I wrote this: it's
33 expensive to change a motherboard which doesn't cooperate, but cheap
34 to get an ethernet card accepting network boot.
35
36 # Network booting in a few simple steps
37
38 ## Configuring your BIOS
39
40 You have to setup your BIOS to boot first through the network. The
41 option label for this can be quite different between BIOSes, your
42 motherboard manual can be handy here. 
43
44 If your motherboard doesn't have the option, you are screwed, but it's
45 unlikely if it is from the [present millenium](http://www.kegel.com/linux/pxe.html). 
46
47 It can happen that even if the motherboard has the option, your
48 network card doesn't have the ROM for network boot in the right
49 specification (which is
50 [PXE](http://en.wikipedia.org/wiki/Preboot_Execution_Environment)). Trying
51 a more recent network card will help here.
52
53 Reboot after BIOS change. You will get a message like "Intel UNDI,
54 PXE...", and a few lines below the MAC address of your network
55 card. Write it down somewhere, it will be useful later. These messages
56 are sent by a program running on the network card ROM, which the BIOS
57 has called because you selected "network boot".
58
59 After a few seconds, an error message will appear, as no host on your
60 LAN has replied to the bootp protocol requests that the ROM program
61 has sent. Next step is then to setup such a host.
62
63 ## Setting up a bootp and tftp server
64
65 The bootp server will be configured to send back after receiving a
66 bootp request from a booting host:
67
68 1. an IP address for the booting host
69 1. the IP address of a tftp server 
70 1. pathname on that tftp server of a first stage bootloader
71
72 After the bootp transaction finishes, the booting host will start
73 downloading the first stage bootloader from the tfpt server, and pass
74 control to it. In the simplest scenario, the first stage bootloader
75 will in turn load kernel image and initrd from the tftp server. In a
76 more complex scenario, an OS installer will be downloaded from the
77 tftp server; it is how Debian does network installations. More details
78 about all that later.
79
80 For simplicity, I will give the configuration where bootp and tftp
81 servers are the same. In the case you want separate servers, notice
82 that the bootp server must be on the same ethernet link as the booting
83 machine; the tftp server can be any IP reachable host.
84
85 You have several options for a bootp and tftp servers, I use udhcpd
86 (from [BusyBox](http://busybox.net/)) and
87 [tftpd-hpa](ftp://ftp.kernel.org/pub/software/network/tftp/), which
88 are lightweight compared to the competition. On Debian, this is a
89 minimal /etc/udhcpd.conf configuration file:
90
91     start           192.168.0.22
92     end             192.168.0.22
93     interface   eth0
94     max_leases  1
95     siaddr          192.168.0.99
96     boot_file   pxelinux.0
97     option          subnet      255.255.255.0
98     option          lease       600
99     option      router  192.168.0.254
100     option      dns       8.8.8.8
101
102 start and end bound the
103 range of the addresses allocated by the server. Here there is only one
104 possible address, as this example is for a recovery setup. Notice that
105 the range must not be already allocated on your LAN, and the address
106 allocated to the booting host can be limited to the time of the kernel
107 download; after that you can change it. This allows for that
108 configuration to be universal for network booting on your LAN.
109
110 siaddr is the address of the tftp server. In case the tftp server is
111 outside your subnet, you have to give a router option and a dns option.
112
113 boot_file is the pathname of the first stage bootloader. The pathname
114 is relative to the root directory of the tftp server, see below.
115
116 For Debian, the tftpd-hpa configuration file is called
117 /etc/default/tftpd-hpa and contains arguments to the daemon called
118 in.tfpd:
119
120     RUN_DAEMON="yes"
121     OPTIONS="-v -l -a 192.168.0.99 -s /var/lib/tftpboot"
122
123 Option -a must be consistent with siaddr above. Argument -s is the
124 root directory of the files to be downloaded. So file pxelinux.0 is
125 located at /var/lib/tftpboot/pxelinux.0
126
127 ## Putting in place files to be downloaded by tftp: OS installation
128
129 I will be a bit Debian specific here, as I don't use regularly other distros.
130
131 Have a look at [the Debian network installation manual](http://www.debian.org/releases/stable/i386/ch04s05.html.en),
132 which gives the project blessed method for network
133 installation. You will find reference to a file netboot/netboot.tar.gz
134 at the end of that page, it's what you have to untar in
135 /var/lib/tftpboot/. That's all!
136
137 Notice: when the Debian installer asks for a network address through
138 DHCP, and you let it go ahead with udhcpd, you will need a router
139 and a dns option in /etc/udhcpd.conf, so as to be able to reach the internet and
140 download packages.
141
142 ## Putting in place files to be downloaded by tftp: recovery
143
144 For recovery, you can use the pxelibux.0 from Debian package syslinux-common, part of the
145 [syslinux project software](http://www.syslinux.org/wiki/index.php/The_Syslinux_Project). 
146 Here is how the /var/lib/tftpboot looks like:
147
148     /var/lib/tftpboot/:
149     total 7545
150     drwxr-xr-x 63 root root    2048 Jun 10 22:06 ..
151     drwxr-xr-x  2 root root    1024 Oct  4  2010 pxelinux.cfg
152     -rw-r--r--  1 root root 6165406 Oct  4  2010 initrd.img-2.6.26-1-686
153     drwxr-xr-x  3 root root    1024 Oct  4  2010 .
154     -rw-r--r--  1 root root 1505936 Oct  4  2010 vmlinuz-2.6.26-1-686
155     -rwxr-xr-x  1 root root   15820 Oct  4  2010 pxelinux.0
156
157     /var/lib/tftpboot/pxelinux.cfg:
158     total 3
159     drwxr-xr-x 2 root root 1024 Oct  4  2010 .
160     -rw-r--r-- 1 root root  230 Oct  4  2010 01-aa-bb-cc-dd-ee-ff
161     drwxr-xr-x 3 root root 1024 Oct  4  2010 ..
162
163 Notice the 01-aa-bb-cc-dd-ee-ff file: it's a syslinux configuration
164 file, whose name is a network MAC address, prefixed with 01-. 
165
166 This a simple authorization mechanism: pxelinux.0 will look for a
167 syslinux configuration file in pxelinux.cfg/ whose name
168 matches the MAC address of the host doing the tftp request: if none is
169 found, booting stops. So you can use a specific kernel and initrd for
170 every host you want to boot through the network.
171
172 Now the content of a syslinux config file fit for the above listing:
173
174     totaltimeout 50
175     timeout 50
176     ontimeout /vmlinuz-2.6.26-1-686
177     append root=/dev/sda1 ro quiet initrd=/initrd.img-2.6.26-1-686
178     label single
179           kernel /vmlinuz-2.6.26-1-686
180           append root=/dev/sda1 ro single initrd=/initrd.img-2.6.26-1-686
181
182 More info about the MAC authorization mechanism and other configuration options can be found at the 
183 [syslinux project](http://www.syslinux.org/wiki/index.php/The_Syslinux_Project).
184
185 ## Final remarks
186
187 You will experience that downloading the kernel and especially the
188 initrd is quite slow, due to tftp using UDP packets of 512 bytes
189 only. So it is a method to recommend only in case of problems, or for
190 a first installation.
191
192 It can be noticed that a tftp download is sent in clear and so is not
193 secure.
194
195 Information in this page should remain valid for
196 [EFI](http://en.wikipedia.org/wiki/Extensible_Firmware_Interface)
197 motherboards and architecture derived IA-32, but I have no direct
198 experience of these. However, mobile computers like smartphones and
199 tablets are mostly not covered.