Netboot Alpine Linux using iPXE: Difference between revisions

From Alpine Linux
m (Fix typo in ipxeboot network name)
(nowiki hypothetical link)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
<h2>Copy the files needed by iPXE to a web server</h2>
== Copy the files needed by iPXE to a web server ==
<ul>
<li><p>For this guide we will provide the files at http://ipxe-boot.example.com/ from the directory <code>/var/www/ixpe-boot.example.com/</code> on the web server, which is writable by your non-root admin user. We also assume the web server follows symlinks within <code>/var/www/ipxe-boot.example.com</code> (but not outside that directory tree).</p>
</li>
<li><p>Copy the netboot tarball (for example the [https://dl-cdn.alpinelinux.org/alpine/v3.16/releases/x86_64/alpine-netboot-3.16.0-x86_64.tar.gz 3.16.0 stable release of Alpine's netboot image for x86_64]) to your non-root admin user on your web server.</p>
</li>
<li><p>Extract the netboot tarball to your webserver directory. For example:</p>


<pre>tar -C /var/www/ipxe-boot.example.com -xzf alpine-netboot-3.16.0-x86_64.tar.gz</pre>
* For this guide we will provide the files at <nowiki>http://ipxe-boot.example.com/</nowiki> from the directory <code>/var/www/ixpe-boot.example.com/</code> on the web server, which is writable by your non-root admin user. We also assume the web server follows symlinks within <code>/var/www/ipxe-boot.example.com</code> (but not outside that directory tree).
 
* Copy the netboot tarball (for example the [https://dl-cdn.alpinelinux.org/alpine/v3.16/releases/x86_64/alpine-netboot-3.16.0-x86_64.tar.gz 3.16.0 stable release of Alpine's netboot image for x86_64]) to your non-root admin user on your web server.
</li>
* Extract the netboot tarball to your webserver directory. For example:
<li><p>This will create a directory structure such as:</p>
{{Cmd|tar -C /var/www/ipxe-boot.example.com -xzf alpine-netboot-3.16.0-x86_64.tar.gz}}
* This will create a directory structure such as:


<pre>boot/
<pre>boot/
Line 26: Line 21:
boot/vmlinuz-lts</pre>
boot/vmlinuz-lts</pre>


</li>
== Create an iPXE boot script ==
</ul>
For example, create a script called {{Path|boot.ipxe}} with contents:
<h2 class="atx" id="create-an-ipxe-boot-script">Create an iPXE boot script</h2>
<p>For example, create a script called <code>boot.ipxe</code> with contents:</p>


<pre>#!ipxe
{{Cat|boot.ipxe|#!ipxe


set base-url http://ipxe-boot.example.com
set base-url http://ipxe-boot.example.com


kernel ${base-url}/boot/vmlinuz-virt console=tty0 modules=loop,squashfs quiet nomodeset alpine_repo=https://dl-cdn.alpinelinux.org/alpine/v3.16/main modloop=http://ipxe-boot.example.com/boot/modloop-virt
kernel ${base-url}/boot/vmlinuz-virt console{{=}}tty0 modules{{=}}loop,squashfs quiet nomodeset alpine_repo{{=}}https://dl-cdn.alpinelinux.org/alpine/v3.16/main modloop{{=}}http://ipxe-boot.example.com/boot/modloop-virt
initrd ${base-url}/boot/initramfs-virt
initrd ${base-url}/boot/initramfs-virt
boot</pre>
boot
}}


<h2 class="atx" id="boot-using-the-ipxe-boot-script">Boot using the iPXE boot script</h2>
== Boot using the iPXE boot script ==
<h3 class="atx" id="using-qemu-for-testing">Using QEMU (for testing)</h3>
=== Using QEMU (for testing) ===
<p>Assuming you have the binary <code>qemu-system-x86_64</code> on your system:</p>
Assuming you have the binary <code>qemu-system-x86_64</code> on your system:


<pre>qemu-system-x86_64 -boot n -m 512M -enable-kvm -device virtio-net,netdev=n1 -netdev user,id=n1,tftp=$(pwd),bootfile=/boot.ipxe</pre>
{{Cmd|<nowiki>qemu-system-x86_64 -boot n -m 512M -enable-kvm -device virtio-net,netdev=n1 -netdev user,id=n1,tftp=$(pwd),bootfile=/boot.ipxe</nowiki>}}


<h3 class="atx" id="using-libvirt">Using Libvirt</h3>
=== Using Libvirt ===
<ul>
* Copy the {{Path|boot.ipxe}} script to your webserver at {{Path|/var/www/ipxe-boot.example.com/boot.ipxe}} (substituting for your actual directory, of course).
<li><p>Copy the <code>boot.ipxe</code> script to your webserver at <code>/var/www/ipxe-boot.example.com/boot.ipxe</code> (substituting for your actual directory, of course).</p>
* Create a new NAT network with XML such:
</li>
<li><p>Create a new NAT network with XML such:</p>
<pre>&lt;network&gt;
<pre>&lt;network&gt;
   &lt;name&gt;ipxeboot&lt;/name&gt;
   &lt;name&gt;ipxeboot&lt;/name&gt;
Line 68: Line 60:
&lt;/network&gt;</pre>
&lt;/network&gt;</pre>


</li>
* Use <code>virt-install</code> such as:
<li><p>Use <code>virt-install</code> such as:</p>
 
{{Cmd|<nowiki>virt-install -n vm-name --memory 512 --vcpus 1 --pxe --disk size=5,bus=virtio --network network=ipxeboot,model=virtio --input tablet --video virtio --os-variant id=http://alpinelinux.org/alpinelinux/3.13</nowiki>}}


<pre>virt-install -n vm-name --memory 512 --vcpus 1 --pxe --disk size=5,bus=virtio --network network=ipxeboot,model=virtio --input tablet --video virtio --os-variant id=http://alpinelinux.org/alpinelinux/3.13</pre>
=== On Vultr.com ===
<em>NOTE</em>: Other cloud providers have similar features, but I haven't used them.
[https://www.vultr.com/docs/ipxe-boot-feature/ iPXE Boot Feature - Vultr.com]


</li>
== See Also ==
</ul>
* [https://boot.alpinelinux.org/ Alpine linux netboot server]
<h3 class="atx" id="on-vultrcom">On Vultr.com</h3>
* [https://wiki.archlinux.org/title/Netboot Netboot - Archwiki]
<p><em>NOTE</em>: Other cloud providers have similar features, but I haven't used them.</p>
<p>[https://www.vultr.com/docs/ipxe-boot-feature/ iPXE Boot Feature - Vultr.com]</p>
<h2 class="atx" id="see-also">See Also</h2>
<p>[https://boot.alpinelinux.org/ Alpine linux netboot server]</p>

Latest revision as of 21:53, 25 August 2023

Copy the files needed by iPXE to a web server

  • For this guide we will provide the files at http://ipxe-boot.example.com/ from the directory /var/www/ixpe-boot.example.com/ on the web server, which is writable by your non-root admin user. We also assume the web server follows symlinks within /var/www/ipxe-boot.example.com (but not outside that directory tree).
  • Copy the netboot tarball (for example the 3.16.0 stable release of Alpine's netboot image for x86_64) to your non-root admin user on your web server.
  • Extract the netboot tarball to your webserver directory. For example:

tar -C /var/www/ipxe-boot.example.com -xzf alpine-netboot-3.16.0-x86_64.tar.gz

  • This will create a directory structure such as:
boot/
boot/initramfs-lts
boot/config-virt
boot/dtbs-virt/
boot/System.map-lts
boot/vmlinuz-virt
boot/System.map-virt
boot/config-lts
boot/initramfs-virt
boot/modloop-lts
boot/modloop-virt
boot/dtbs-lts/
boot/vmlinuz-lts

Create an iPXE boot script

For example, create a script called boot.ipxe with contents:

Contents of boot.ipxe

#!ipxe set base-url http://ipxe-boot.example.com kernel ${base-url}/boot/vmlinuz-virt console=tty0 modules=loop,squashfs quiet nomodeset alpine_repo=https://dl-cdn.alpinelinux.org/alpine/v3.16/main modloop=http://ipxe-boot.example.com/boot/modloop-virt initrd ${base-url}/boot/initramfs-virt boot

Boot using the iPXE boot script

Using QEMU (for testing)

Assuming you have the binary qemu-system-x86_64 on your system:

qemu-system-x86_64 -boot n -m 512M -enable-kvm -device virtio-net,netdev=n1 -netdev user,id=n1,tftp=$(pwd),bootfile=/boot.ipxe

Using Libvirt

  • Copy the boot.ipxe script to your webserver at /var/www/ipxe-boot.example.com/boot.ipxe (substituting for your actual directory, of course).
  • Create a new NAT network with XML such:
<network>
  <name>ipxeboot</name>
  <forward mode="nat">
    <nat>
      <port start="1024" end="65535"/>
    </nat>
  </forward>
  <bridge name="virbr1" stp="on" delay="0"/>
  <mac address="52:54:00:a4:10:b3"/>
  <domain name="ipxeboot"/>
  <ip address="192.168.129.1" netmask="255.255.255.0">
    <dhcp>
      <range start="192.168.129.128" end="192.168.129.254"/>
      <bootp file="http://ipxe-boot.example.com/boot.ipxe"/>
    </dhcp>
  </ip>
</network>
  • Use virt-install such as:

virt-install -n vm-name --memory 512 --vcpus 1 --pxe --disk size=5,bus=virtio --network network=ipxeboot,model=virtio --input tablet --video virtio --os-variant id=http://alpinelinux.org/alpinelinux/3.13

On Vultr.com

NOTE: Other cloud providers have similar features, but I haven't used them. iPXE Boot Feature - Vultr.com

See Also