1<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="sec-booting-from-usb">
2 <title>Booting from a USB flash drive</title>
3 <para>
4 The image has to be written verbatim to the USB flash drive for it
5 to be bootable on UEFI and BIOS systems. Here are the recommended
6 tools to do that.
7 </para>
8 <section xml:id="sec-booting-from-usb-graphical">
9 <title>Creating bootable USB flash drive with a graphical
10 tool</title>
11 <para>
12 Etcher is a popular and user-friendly tool. It works on Linux,
13 Windows and macOS.
14 </para>
15 <para>
16 Download it from
17 <link xlink:href="https://www.balena.io/etcher/">balena.io</link>,
18 start the program, select the downloaded NixOS ISO, then select
19 the USB flash drive and flash it.
20 </para>
21 <warning>
22 <para>
23 Etcher reports errors and usage statistics by default, which can
24 be disabled in the settings.
25 </para>
26 </warning>
27 <para>
28 An alternative is
29 <link xlink:href="https://bztsrc.gitlab.io/usbimager">USBImager</link>,
30 which is very simple and does not connect to the internet.
31 Download the version with write-only (wo) interface for your
32 system. Start the program, select the image, select the USB flash
33 drive and click <quote>Write</quote>.
34 </para>
35 </section>
36 <section xml:id="sec-booting-from-usb-linux">
37 <title>Creating bootable USB flash drive from a Terminal on
38 Linux</title>
39 <orderedlist numeration="arabic" spacing="compact">
40 <listitem>
41 <para>
42 Plug in the USB flash drive.
43 </para>
44 </listitem>
45 <listitem>
46 <para>
47 Find the corresponding device with <literal>lsblk</literal>.
48 You can distinguish them by their size.
49 </para>
50 </listitem>
51 <listitem>
52 <para>
53 Make sure all partitions on the device are properly unmounted.
54 Replace <literal>sdX</literal> with your device (e.g.
55 <literal>sdb</literal>).
56 </para>
57 </listitem>
58 </orderedlist>
59 <programlisting>
60sudo umount /dev/sdX*
61</programlisting>
62 <orderedlist numeration="arabic" spacing="compact">
63 <listitem override="4">
64 <para>
65 Then use the <literal>dd</literal> utility to write the image
66 to the USB flash drive.
67 </para>
68 </listitem>
69 </orderedlist>
70 <programlisting>
71sudo dd if=<path-to-image> of=/dev/sdX bs=4M conv=fsync
72</programlisting>
73 </section>
74 <section xml:id="sec-booting-from-usb-macos">
75 <title>Creating bootable USB flash drive from a Terminal on
76 macOS</title>
77 <orderedlist numeration="arabic" spacing="compact">
78 <listitem>
79 <para>
80 Plug in the USB flash drive.
81 </para>
82 </listitem>
83 <listitem>
84 <para>
85 Find the corresponding device with
86 <literal>diskutil list</literal>. You can distinguish them by
87 their size.
88 </para>
89 </listitem>
90 <listitem>
91 <para>
92 Make sure all partitions on the device are properly unmounted.
93 Replace <literal>diskX</literal> with your device (e.g.
94 <literal>disk1</literal>).
95 </para>
96 </listitem>
97 </orderedlist>
98 <programlisting>
99diskutil unmountDisk diskX
100</programlisting>
101 <orderedlist numeration="arabic" spacing="compact">
102 <listitem override="4">
103 <para>
104 Then use the <literal>dd</literal> utility to write the image
105 to the USB flash drive.
106 </para>
107 </listitem>
108 </orderedlist>
109 <programlisting>
110sudo dd if=<path-to-image> of=/dev/rdiskX bs=4m
111</programlisting>
112 <para>
113 After <literal>dd</literal> completes, a GUI dialog "The disk
114 you inserted was not readable by this computer" will pop up,
115 which can be ignored.
116 </para>
117 <note>
118 <para>
119 Using the 'raw' <literal>rdiskX</literal> device instead of
120 <literal>diskX</literal> with dd completes in minutes instead of
121 hours.
122 </para>
123 </note>
124 <orderedlist numeration="arabic" spacing="compact">
125 <listitem override="5">
126 <para>
127 Eject the disk when it is finished.
128 </para>
129 </listitem>
130 </orderedlist>
131 <programlisting>
132diskutil eject /dev/diskX
133</programlisting>
134 </section>
135</section>