Instructions how to make a diskless VM with iPXE and NFS using IPv6 only.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

pirms 5 gadiem
pirms 5 gadiem
pirms 5 gadiem
pirms 5 gadiem
pirms 5 gadiem
pirms 5 gadiem
pirms 5 gadiem
pirms 5 gadiem
pirms 5 gadiem
pirms 5 gadiem
pirms 5 gadiem
pirms 5 gadiem
pirms 5 gadiem
pirms 5 gadiem
pirms 5 gadiem
pirms 5 gadiem
pirms 5 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. # How to boot a diskless VM with iPXE over NFS using only IPv6
  2. I have encountered many issues and countless hours trying to figure this out, but I finally succeeded. Reading source code, strace'ing binaries trying to figure out what was wrong with them.
  3. # iPXE
  4. iPXE will do IPv4 DHCP first and then IPv6 SLAAC/DHCP. This is not a problem, it's just annoying. IPv4 DHCP has a default timeout in iPXE of 10 seconds.
  5. What you need to do in iPXE:
  6. * enable serial console -> `src/config/console.h` -> `#define CONSOLE_SERIAL`
  7. * enable IPv6 -> `src/config/general.h` -> `#define NET_PROTO_IPV6`
  8. * mangle IPv4 DHCP timeout -> `src/config/dhcp.h` -> `#define DHCP_DISC_END_TIMEOUT_SEC 1`
  9. Debian/Ubuntu ipxe-qemu patching
  10. ```
  11. apt-get update
  12. apt-get source ipxe-qemu
  13. apt-get build-dep ipxe-qemu
  14. cd ipxe-1.0.0+git-20180124.fbe8c52d # or whatever your version is
  15. dch -n "add support for serial console / IPv6"
  16. # apply the modifications above
  17. debuild -b -uc -us
  18. cd ..
  19. dpkg -i ipxe-qemu_*.deb
  20. ```
  21. # Kernel options
  22. Make sure you pass the right kernel options for initramfs/initrd to know exactly what you want to do. (replace eth0 with the name of your PXE interface)
  23. * `ip=:::::eth0:off` (disable IPv4 on the PXE interface)
  24. * `ip6=eth0` (enable IPv6 on the PXE interface)
  25. * `nfsroot=<hostname>:<path>` (mounting IPv6 NFS shares using a literal IPv6 **WILL FAIL**, you **MUST** use a hostname)
  26. Those options will tell the initrd script which interface and protocol is desired.
  27. # Hooks in initramfs
  28. NOTE: Be aware that this will increase the size of initrd. In my case it went to ~16MB which is still way less than on a physical host (~60MB).
  29. A few files must be copied to the initramfs in order to make this work. First we need DNS to work and secondly we need to replace the busybox nfsmount with mount.nfs.
  30. In `/etc/initramfs-tools/hooks/` create an executable script with the name of your choice. Here's the content:
  31. ```
  32. #!/bin/bash
  33. . /usr/share/initramfs-tools/hook-functions
  34. # copy all the name libraries (for DNS to work)
  35. cp -fpL /lib/x86_64-linux-gnu/libns* ${DESTDIR}/lib/x86_64-linux-gnu/
  36. # copy helper files needed by mount.nfs
  37. for file in /etc/protocols /etc/netconfig
  38. do cp $file ${DESTDIR}${file}; done
  39. # uncomment to embed in your setup, can be useful for debugging
  40. # copy_exec /sbin/dhclient /sbin
  41. # copy_exec /bin/ping /bin
  42. # copy_exec /usr/bin/strace /bin
  43. # replace the busybox nfsmount with mount.nfs (this way we don't need to modify the included nfs script which calls nfsmount)
  44. cp /sbin/mount.nfs ${DESTDIR}/bin/nfsmount
  45. # this little hack will find all libraries needed by mount.nfs, locate them and copy them.
  46. for lib in `ldd /sbin/mount.nfs | awk '{print $1}'`
  47. do
  48. found=0
  49. for path in /lib /lib/x86_64-linux-gnu /usr/lib /usr/lib/x86_64-linux-gnu
  50. do
  51. if [ -r "${path}/${lib}" ]
  52. then
  53. cp -L ${path}/${lib} ${DESTDIR}/${path}/${lib}
  54. found=1
  55. fi
  56. done
  57. if [ ! $found ]
  58. then
  59. echo "ERROR: Cannot find ${lib}"
  60. exit 1;
  61. fi
  62. done
  63. ```
  64. After that you'll need to `update-initramfs -u`
  65. # Boot
  66. **Boot and it should just work! Happy IPv6!**
  67. # Final notes
  68. ## iPXE & NFS
  69. Due to incompatible limiting requirements of iPXE and initramfs, both must be run on separate subnets. You will need one interface for iPXE and one for NFS.
  70. ### radvd.conf
  71. ```
  72. # iPXE needs SLAAC and DHCPv6 options
  73. interface bridge0 {
  74. IgnoreIfMissing on;
  75. AdvSendAdvert on;
  76. AdvOtherConfigFlag on;
  77. AdvDefaultLifetime 0;
  78. AdvLinkMTU 9000;
  79. AdvCurHopLimit 64;
  80. AdvReachableTime 0;
  81. MaxRtrAdvInterval 600;
  82. MinRtrAdvInterval 198;
  83. AdvDefaultPreference low;
  84. AdvRetransTimer 0;
  85. AdvManagedFlag off;
  86. prefix <your PXE /64>::/64 { };
  87. RDNSS <your dnsmasq server (yourself) IP, must be in the same subnet>:: { };
  88. };
  89. # busybox/initramfs needs DHCPv6
  90. interface bridge2 {
  91. IgnoreIfMissing on;
  92. AdvSendAdvert on;
  93. AdvOtherConfigFlag off;
  94. AdvDefaultLifetime 0;
  95. AdvLinkMTU 9000;
  96. AdvCurHopLimit 64;
  97. AdvReachableTime 0;
  98. MaxRtrAdvInterval 600;
  99. MinRtrAdvInterval 198;
  100. AdvDefaultPreference low;
  101. AdvRetransTimer 0;
  102. AdvManagedFlag off;
  103. prefix <your NFS /64>::/64 {
  104. AdvAutonomous off;
  105. };
  106. };
  107. ```
  108. ### isc-dhcp-server6 dhcpd6.conf
  109. ```
  110. # PXE
  111. subnet6 <your PXE /64>::/64 {
  112. option dhcp6.bootfile-url "http://<pxe server hostname>?uuid=${uuid}&op=ipxe";
  113. }
  114. # NFS
  115. subnet6 <your NFS /64>::/64 {
  116. range6 <your NFS /64>::1 <your NFS /64>::ffff;
  117. option dhcp6.name-servers <your NFS server>::;
  118. }
  119. ```
  120. ### dnsmasq
  121. ```
  122. # leave everything to defaults except
  123. interface=bridge1
  124. interface=bridge2
  125. no-dhcp-interface=bridge1
  126. no-dhcp-interface=bridge2
  127. ```
  128. ### /etc/hosts
  129. DO NOT MAKE YOUR VMs depend on VMs to boot !!!
  130. If your DNS server is a VM, make sure that the hostnames used to boot (pxe server hostname, nfs server hostname) can be resolved by dnsmasq, the easiest way to ensure this is to add them to /etc/hosts which dnsmasq will use by default.