Guest User

Untitled

a guest
Jan 5th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.87 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # This implementation is incomplete: Discovery mode is not implemented and
  4. # the argument handling doesn't follow currently agreed formats. This is mainly
  5. # because rfc4173 does not say anything about iscsi_initiator but open-iscsi's
  6. # iscsistart needs this.
  7. #
  8.  
  9. . /lib/dracut-lib.sh
  10.  
  11. PATH=$PATH:/sbin:/usr/sbin
  12.  
  13. # Huh? Empty $1?
  14. [ -z "$1" ] && exit 1
  15.  
  16. # Huh? Empty $2?
  17. [ -z "$2" ] && exit 1
  18.  
  19. # Huh? Empty $3? This isn't really necessary, since NEWROOT isn't
  20. # used here. But let's be consistent
  21. [ -z "$3" ] && exit 1
  22.  
  23. # root is in the form root=iscsi:[<servername>]:[<protocol>]:[<port>]:[<LUN>]:<targetname>
  24. netif="$1"
  25. iroot="$2"
  26.  
  27. source_all /etc/conf.d
  28.  
  29. # If it's not iscsi we don't continue
  30. [ "${iroot%%:*}" = "iscsi" ] || exit 1
  31.  
  32. iroot=${iroot#iscsi:}
  33.  
  34. # XXX modprobe crc32c should go in the cmdline parser, but I haven't yet
  35. # figured out a way how to check whether this is built-in or not
  36. modprobe crc32c 2>/dev/null
  37.  
  38.  
  39. [ -e /tmp/root.info ] && . /tmp/root.info
  40.  
  41. if getarg iscsi_firmware ; then
  42. if [ -n "${root%%block:*}" ]; then
  43. # if root is not specified try to mount the whole iSCSI LUN
  44. printf 'ENV{DEVTYPE}!="partition", SYMLINK=="disk/by-path/*-iscsi-*-*", SYMLINK+="root"\n' >> /etc/udev/rules.d/99-iscsi-root.rules
  45. fi
  46. iscsistart -b
  47. exit 0
  48. fi
  49.  
  50. # override conf settings by command line options
  51. arg=$(getarg iscsi_initiator)
  52. [ -n "$arg" ] && iscsi_initiator=$arg
  53. arg=$(getarg iscsi_target_name)
  54. [ -n "$arg" ] && iscsi_target_name=$arg
  55. arg=$(getarg iscsi_target_ip)
  56. [ -n "$arg" ] && iscsi_target_ip=$arg
  57. arg=$(getarg iscsi_target_port)
  58. [ -n "$arg" ] && iscsi_target_port=$arg
  59. arg=$(getarg iscsi_target_group)
  60. [ -n "$arg" ] && iscsi_target_group=$arg
  61. arg=$(getarg iscsi_username)
  62. [ -n "$arg" ] && iscsi_username=$arg
  63. arg=$(getarg iscsi_password)
  64. [ -n "$arg" ] && iscsi_password=$arg
  65. arg=$(getarg iscsi_in_username)
  66. [ -n "$arg" ] && iscsi_in_username=$arg
  67. arg=$(getarg iscsi_in_password)
  68. [ -n "$arg" ] && iscsi_in_password=$arg
  69.  
  70. handle_netroot()
  71. {
  72. iroot=$1
  73. # override conf/commandline options by dhcp root_path
  74. # FIXME this assumes that all values have been provided
  75. OLDIFS="$IFS"
  76. IFS=@
  77. set $iroot
  78. if [ $# -gt 1 ]; then
  79. authinfo=$1; shift
  80. iroot=$*
  81. # allow empty authinfo to allow having an @ in iscsi_target_name like this:
  82. # netroot=iscsi:@192.168.1.100::3260::iqn.2009-01.com.example:testdi@sk
  83. if [ -n "$authinfo" ]; then
  84. IFS=:
  85. set $authinfo
  86. iscsi_username=$1
  87.  
  88. iscsi_password=$2
  89. if [ $# -gt 2 ]; then
  90. iscsi_in_username=$3
  91. iscsi_in_password=$4
  92. fi
  93. fi
  94. fi
  95.  
  96. IFS="$OLDIFS"
  97.  
  98. local v=${iroot}:
  99. local i
  100. set --
  101. while [ -n "$v" ]; do
  102. if [ "${v#\[*:*:*\]:}" != "$v" ]; then
  103. # handle IPv6 address
  104. i="${v%%\]:*}"
  105. i="${i##\[}"
  106. set -- "$@" "$i"
  107. v=${v#\[$i\]:}
  108. else
  109. set -- "$@" "${v%%:*}"
  110. v=${v#*:}
  111. fi
  112. done
  113. iscsi_target_ip=$1; shift
  114. iscsi_protocol=$1; shift # ignored
  115. iscsi_target_port=$1; shift
  116. iscsi_lun=$1; shift
  117. IFS=:
  118. iscsi_target_name=$*
  119. IFS="$OLDIFS"
  120. # XXX is this needed?
  121. getarg ro && iscsirw=ro
  122. getarg rw && iscsirw=rw
  123. fsopts=${fsopts+$fsopts,}${iscsirw}
  124. if [ -z $iscsi_initiator ]; then
  125. # XXX Where are these from?
  126. [ -f /etc/initiatorname.iscsi ] && . /etc/initiatorname.iscsi
  127. [ -f /etc/iscsi/initiatorname.iscsi ] && . /etc/iscsi/initiatorname.iscsi
  128. iscsi_initiator=$InitiatorName
  129.  
  130. # XXX rfc3720 says 'SCSI Initiator Name: The iSCSI Initiator Name specifies
  131. # the worldwide unique name of the initiator.' Could we use hostname/ip
  132. # if missing?
  133. fi
  134.  
  135. if [ -z $iscsi_initiator ]; then
  136. if [ -f /sys/firmware/ibft/initiator/initiator-name ]; then
  137. iscsi_initiator=$(while read line; do echo $line;done < /sys/firmware/ibft/initiator-name)
  138. else
  139. fi
  140.  
  141. if [ -z $iscsi_target_port ]; then
  142. iscsi_target_port=3260
  143. fi
  144.  
  145. if [ -z $iscsi_target_group ]; then
  146. iscsi_target_group=1
  147. fi
  148.  
  149. if [ -z $iscsi_initiator ]; then
  150. # XXX is this correct?
  151. iscsi_initiator=$(iscsi-iname)
  152. fi
  153.  
  154. if [ -z $iscsi_lun ]; then
  155. iscsi_lun=0
  156. fi
  157.  
  158. echo "InitiatorName='$iscsi_initiator'" > /dev/.initiatorname.iscsi
  159.  
  160. # FIXME $iscsi_protocol??
  161.  
  162. if [ -n "${root%%block:*}" ]; then
  163. # if root is not specified try to mount the whole iSCSI LUN
  164. printf 'SYMLINK=="disk/by-path/*-iscsi-*-%s", SYMLINK+="root"\n' $iscsi_lun >> /etc/udev/rules.d/99-iscsi-root.rules
  165. fi
  166.  
  167. # inject new exit_if_exists
  168. echo 'settle_exit_if_exists="--exit-if-exists=/dev/root"; rm "$job"' > /initqueue/iscsi-settle.sh
  169.  
  170. # force udevsettle to break
  171. > /initqueue/work
  172.  
  173. iscsistart -i $iscsi_initiator -t $iscsi_target_name \
  174. -g $iscsi_target_group -a $iscsi_target_ip \
  175. -p $iscsi_target_port \
  176. ${iscsi_username+-u $iscsi_username} \
  177. ${iscsi_password+-w $iscsi_password} \
  178. ${iscsi_in_username+-U $iscsi_in_username} \
  179. ${iscsi_in_password+-W $iscsi_in_password} || :
  180.  
  181. # install mount script
  182. if [ -n "${root%%block:*}" ]; then
  183. # if root is not specified try to mount the whole iSCSI LUN
  184. echo "iscsi_lun=$iscsi_lun . /bin/mount-lun.sh " > /mount/01-$$-iscsi.sh
  185. fi
  186. }
  187.  
  188. # loop over all netroot parameter
  189. if getarg netroot; then
  190. for nroot in $(getargs netroot); do
  191. [ "${netroot%%:*}" = "iscsi" ] || continue
  192. handle_netroot ${nroot##iscsi:}
  193. done
  194.  
  195. else
  196. handle_netroot $iroot
  197. fi
  198.  
  199. # now we have a root filesystem somewhere in /dev/sda*
  200. # let the normal block handler handle root=
  201. exit 0
Add Comment
Please, Sign In to add comment