iscsi.rst 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. .. SPDX-License-Identifier: GPL-2.0+
  2. .. Copyright (c) 2018 Heinrich Schuchardt
  3. iSCSI booting with U-Boot and iPXE
  4. ==================================
  5. Motivation
  6. ----------
  7. U-Boot has only a reduced set of supported network protocols. The focus for
  8. network booting has been on UDP based protocols. A TCP stack and HTTP support
  9. are expected to be integrated in 2018 together with a wget command.
  10. For booting a diskless computer this leaves us with BOOTP or DHCP to get the
  11. address of a boot script. TFTP or NFS can be used to load the boot script, the
  12. operating system kernel and the initial file system (initrd).
  13. These protocols are insecure. The client cannot validate the authenticity
  14. of the contacted servers. And the server cannot verify the identity of the
  15. client.
  16. Furthermore the services providing the operating system loader or kernel are
  17. not the ones that the operating system typically will use. Especially in a SAN
  18. environment this makes updating the operating system a hassle. After installing
  19. a new kernel version the boot files have to be copied to the TFTP server
  20. directory.
  21. The HTTPS protocol provides certificate based validation of servers. Sensitive
  22. data like passwords can be securely transmitted.
  23. The iSCSI protocol is used for connecting storage attached networks. It
  24. provides mutual authentication using the CHAP protocol. It typically runs on
  25. a TCP transport.
  26. Thus a better solution than DHCP/TFTP/NFS boot would be to load a boot script
  27. via HTTPS and to download any other files needed for booting via iSCSI from the
  28. same target where the operating system is installed.
  29. An alternative to implementing these protocols in U-Boot is to use an existing
  30. software that can run on top of U-Boot. iPXE[1] is the "swiss army knife" of
  31. network booting. It supports both HTTPS and iSCSI. It has a scripting engine for
  32. fine grained control of the boot process and can provide a command shell.
  33. iPXE can be built as an EFI application (named snp.efi) which can be loaded and
  34. run by U-Boot.
  35. Boot sequence
  36. -------------
  37. U-Boot loads the EFI application iPXE snp.efi using the bootefi command. This
  38. application has network access via the simple network protocol offered by
  39. U-Boot.
  40. iPXE executes its internal script. This script may optionally chain load a
  41. secondary boot script via HTTPS or open a shell.
  42. For the further boot process iPXE connects to the iSCSI server. This includes
  43. the mutual authentication using the CHAP protocol. After the authentication iPXE
  44. has access to the iSCSI targets.
  45. For a selected iSCSI target iPXE sets up a handle with the block IO protocol. It
  46. uses the ConnectController boot service of U-Boot to request U-Boot to connect a
  47. file system driver. U-Boot reads from the iSCSI drive via the block IO protocol
  48. offered by iPXE. It creates the partition handles and installs the simple file
  49. protocol. Now iPXE can call the simple file protocol to load GRUB[2]. U-Boot
  50. uses the block IO protocol offered by iPXE to fulfill the request.
  51. Once GRUB is started it uses the same block IO protocol to load Linux. Via
  52. the EFI stub Linux is called as an EFI application::
  53. +--------+ +--------+
  54. | | Runs | |
  55. | U-Boot |========>| iPXE |
  56. | EFI | | snp.efi|
  57. +--------+ | | DHCP | |
  58. | |<===|********|<========| |
  59. | DHCP | | | Get IP | |
  60. | Server | | | Address | |
  61. | |===>|********|========>| |
  62. +--------+ | | Response| |
  63. | | | |
  64. | | | |
  65. +--------+ | | HTTPS | |
  66. | |<===|********|<========| |
  67. | HTTPS | | | Load | |
  68. | Server | | | Script | |
  69. | |===>|********|========>| |
  70. +--------+ | | | |
  71. | | | |
  72. | | | |
  73. +--------+ | | iSCSI | |
  74. | |<===|********|<========| |
  75. | iSCSI | | | Auth | |
  76. | Server |===>|********|========>| |
  77. | | | | | |
  78. | | | | Loads | |
  79. | |<===|********|<========| | +--------+
  80. | | | | GRUB | | Runs | |
  81. | |===>|********|========>| |======>| GRUB |
  82. | | | | | | | |
  83. | | | | | | | |
  84. | | | | | | Loads | |
  85. | |<===|********|<========|********|<======| | +--------+
  86. | | | | | | Linux | | Runs | |
  87. | |===>|********|========>|********|======>| |=====>| Linux |
  88. | | | | | | | | | |
  89. +--------+ +--------+ +--------+ +--------+ | |
  90. | |
  91. | |
  92. | ~ ~ ~ ~|
  93. Security
  94. --------
  95. The iSCSI protocol is not encrypted. The traffic could be secured using IPsec
  96. but neither U-Boot nor iPXE does support this. So we should at least separate
  97. the iSCSI traffic from all other network traffic. This can be achieved using a
  98. virtual local area network (VLAN).
  99. Configuration
  100. -------------
  101. iPXE
  102. ~~~~
  103. For running iPXE on arm64 the bin-arm64-efi/snp.efi build target is needed::
  104. git clone http://git.ipxe.org/ipxe.git
  105. cd ipxe/src
  106. make bin-arm64-efi/snp.efi -j6 EMBED=myscript.ipxe
  107. The available commands for the boot script are documented at:
  108. http://ipxe.org/cmd
  109. Credentials are managed as environment variables. These are described here:
  110. http://ipxe.org/cfg
  111. iPXE by default will put the CPU to rest when waiting for input. U-Boot does
  112. not wake it up due to missing interrupt support. To avoid this behavior create
  113. file src/config/local/nap.h:
  114. .. code-block:: c
  115. /* nap.h */
  116. #undef NAP_EFIX86
  117. #undef NAP_EFIARM
  118. #define NAP_NULL
  119. The supported commands in iPXE are controlled by an include, too. Putting the
  120. following into src/config/local/general.h is sufficient for most use cases:
  121. .. code-block:: c
  122. /* general.h */
  123. #define NSLOOKUP_CMD /* Name resolution command */
  124. #define PING_CMD /* Ping command */
  125. #define NTP_CMD /* NTP commands */
  126. #define VLAN_CMD /* VLAN commands */
  127. #define IMAGE_EFI /* EFI image support */
  128. #define DOWNLOAD_PROTO_HTTPS /* Secure Hypertext Transfer Protocol */
  129. #define DOWNLOAD_PROTO_FTP /* File Transfer Protocol */
  130. #define DOWNLOAD_PROTO_NFS /* Network File System Protocol */
  131. #define DOWNLOAD_PROTO_FILE /* Local file system access */
  132. Open-iSCSI
  133. ~~~~~~~~~~
  134. When the root file system is on an iSCSI drive you should disable pings and set
  135. the replacement timer to a high value in the configuration file [3]::
  136. node.conn[0].timeo.noop_out_interval = 0
  137. node.conn[0].timeo.noop_out_timeout = 0
  138. node.session.timeo.replacement_timeout = 86400
  139. Links
  140. -----
  141. * [1] https://ipxe.org - iPXE open source boot firmware
  142. * [2] https://www.gnu.org/software/grub/ -
  143. GNU GRUB (Grand Unified Bootloader)
  144. * [3] https://github.com/open-iscsi/open-iscsi/blob/master/README -
  145. Open-iSCSI README