PageRenderTime 26ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/usr/src/lib/brand/solaris10/zone/s10_boot.ksh

https://github.com/richlowe/illumos-gate
Korn Shell | 338 lines | 147 code | 35 blank | 156 comment | 20 complexity | 224c775b18eb1c0c020f38b4604368a0 MD5 | raw file
  1. #!/bin/ksh -p
  2. #
  3. # CDDL HEADER START
  4. #
  5. # The contents of this file are subject to the terms of the
  6. # Common Development and Distribution License (the "License").
  7. # You may not use this file except in compliance with the License.
  8. #
  9. # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10. # or http://www.opensolaris.org/os/licensing.
  11. # See the License for the specific language governing permissions
  12. # and limitations under the License.
  13. #
  14. # When distributing Covered Code, include this CDDL HEADER in each
  15. # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16. # If applicable, add the following below this CDDL HEADER, with the
  17. # fields enclosed by brackets "[]" replaced with your own identifying
  18. # information: Portions Copyright [yyyy] [name of copyright owner]
  19. #
  20. # CDDL HEADER END
  21. #
  22. #
  23. # Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  24. #
  25. # s10 boot script.
  26. #
  27. # The arguments to this script are the zone name and the zonepath.
  28. #
  29. . /usr/lib/brand/solaris10/common.ksh
  30. ZONENAME=$1
  31. ZONEPATH=$2
  32. ZONEROOT=$ZONEPATH/root
  33. w_missing=$(gettext "Warning: \"%s\" is not installed in the global zone")
  34. arch=`uname -p`
  35. if [ "$arch" = "i386" ]; then
  36. ARCH32=i86
  37. ARCH64=amd64
  38. elif [ "$arch" = "sparc" ]; then
  39. # 32-bit SPARC not supported!
  40. ARCH32=
  41. ARCH64=sparcv9
  42. else
  43. echo "Unsupported architecture: $arch"
  44. exit 2
  45. fi
  46. #
  47. # Run the s10_support boot hook.
  48. #
  49. /usr/lib/brand/solaris10/s10_support boot $ZONENAME
  50. if (( $? != 0 )) ; then
  51. exit 1
  52. fi
  53. BRANDDIR=/.SUNWnative/usr/lib/brand/solaris10;
  54. FILEDIR=$BRANDDIR/files;
  55. EXIT_CODE=1
  56. #
  57. # Replace the specified file in the booting zone with a wrapper script that
  58. # invokes s10_isaexec_wrapper. This is a convenience function that reduces
  59. # clutter and code duplication.
  60. #
  61. # Parameters:
  62. # $1 The full path of the file to replace (e.g., /sbin/ifconfig)
  63. # $2 The access mode of the replacement file in hex (e.g., 0555)
  64. # $3 The name of the replacement file's owner (e.g., root:bin)
  65. #
  66. # NOTE: The checks performed in the 'if' statement below are not generic: they
  67. # depend on the success of the zone filesystem structure validation performed
  68. # above to ensure that intermediate directories exist and aren't symlinks.
  69. #
  70. replace_with_native() {
  71. path_dname=$ZONEROOT/`dirname $1`
  72. [ ! -f $1 ] && printf "$w_missing" "$1"
  73. if [ ! -h $path_dname -a -d $path_dname ]; then
  74. safe_replace $ZONEROOT/$1 $BRANDDIR/s10_isaexec_wrapper $2 $3 \
  75. remove
  76. fi
  77. }
  78. replace_with_native_py() {
  79. path_dname=$ZONEROOT/`dirname $1`
  80. [ ! -f $1 ] && printf "$w_missing" "$1"
  81. if [ ! -h $path_dname -a -d $path_dname ]; then
  82. safe_replace $ZONEROOT/$1 $BRANDDIR/s10_python_wrapper $2 $3 \
  83. remove
  84. fi
  85. }
  86. #
  87. # Create a new wrapper script that invokes s10_isaexec_wrapper in the
  88. # brand (for a non-existing s10c file) pointing to the native brand file.
  89. #
  90. # Parameters:
  91. # $1 The full path of the wrapper file to create
  92. # $2 The access mode of the replacement file in hex (e.g., 0555)
  93. # $3 The name of the replacement file's owner (e.g., root:bin)
  94. #
  95. wrap_with_native() {
  96. [ ! -f $1 ] && printf "$w_missing" "$1"
  97. path_dname=$ZONEROOT/`dirname $1`
  98. if [ ! -h $path_dname -a -d $path_dname -a ! -f $ZONEROOT/$1 ]; then
  99. safe_wrap $ZONEROOT/$1 $BRANDDIR/s10_isaexec_wrapper $2 $3
  100. fi
  101. }
  102. #
  103. # Before we boot we validate and fix, if necessary, the required files within
  104. # the zone. These modifications can be lost if a patch is applied within the
  105. # zone, so we validate and fix the zone every time it boots.
  106. #
  107. #
  108. # BINARY REPLACEMENT
  109. #
  110. # This section of the boot script is responsible for replacing Solaris 10
  111. # binaries within the booting zone with Nevada binaries. This is a two-step
  112. # process: First, the directory structure of the zone is validated to ensure
  113. # that binary replacement will proceed safely. Second, Solaris 10 binaries
  114. # are replaced with Nevada binaries.
  115. #
  116. # Here's an example. Suppose that you want to replace /usr/bin/zcat with the
  117. # Nevada /usr/bin/zcat binary. Then you should do the following:
  118. #
  119. # 1. Go to the section below labeled "STEP ONE" and add the following
  120. # two lines:
  121. #
  122. # safe_dir /usr
  123. # safe_dir /usr/bin
  124. #
  125. # These lines ensure that both /usr and /usr/bin are directories
  126. # within the booting zone that can be safely accessed by the global
  127. # zone.
  128. # 2. Go to the section below labeled "STEP TWO" and add the following
  129. # line:
  130. #
  131. # replace_with_native /usr/bin/zcat 0555 root:bin
  132. #
  133. # Details about the binary replacement procedure can be found in the Solaris 10
  134. # Containers Developer Guide.
  135. #
  136. #
  137. # STEP ONE
  138. #
  139. # Validate that the zone filesystem looks like we expect it to.
  140. #
  141. safe_dir /lib
  142. safe_dir /lib/svc
  143. safe_dir /lib/svc/method
  144. safe_dir /lib/svc/share
  145. safe_dir /usr
  146. safe_dir /usr/bin
  147. safe_dir /usr/lib
  148. safe_dir /usr/lib/autofs
  149. safe_dir /usr/lib/fs
  150. safe_dir /usr/lib/fs/autofs
  151. safe_dir /usr/lib/fs/ufs
  152. safe_dir /usr/lib/fs/zfs
  153. safe_dir /usr/lib/inet
  154. safe_dir /usr/lib/zfs
  155. safe_dir /usr/sbin
  156. if [ -n "$ARCH32" ]; then
  157. safe_dir /usr/lib/ipf/$ARCH32
  158. safe_dir /usr/sbin/$ARCH32
  159. fi
  160. if [ -n "$ARCH64" ]; then
  161. safe_dir /usr/lib/ipf/$ARCH64
  162. safe_dir /usr/sbin/$ARCH64
  163. fi
  164. safe_dir /sbin
  165. safe_dir /var
  166. safe_dir /var/svc
  167. safe_dir /var/svc/manifest
  168. safe_dir /var/svc/manifest/network
  169. #
  170. # Some of the native networking daemons such as in.mpathd are
  171. # expected under /lib/inet
  172. #
  173. mkdir -m 0755 -p $ZONEROOT/lib/inet
  174. chown root:bin $ZONEROOT/lib/inet
  175. safe_dir /lib/inet
  176. #
  177. # STEP TWO
  178. #
  179. # Replace Solaris 10 binaries with Nevada binaries.
  180. #
  181. #
  182. # Replace various network-related programs with native wrappers.
  183. #
  184. replace_with_native /sbin/dhcpagent 0555 root:bin
  185. replace_with_native /sbin/dhcpinfo 0555 root:bin
  186. replace_with_native /sbin/ifconfig 0555 root:bin
  187. replace_with_native /usr/bin/netstat 0555 root:bin
  188. replace_with_native /usr/lib/inet/in.ndpd 0555 root:bin
  189. replace_with_native /usr/sbin/in.routed 0555 root:bin
  190. replace_with_native /usr/sbin/ndd 0555 root:bin
  191. replace_with_native /usr/sbin/snoop 0555 root:bin
  192. replace_with_native /usr/sbin/if_mpadm 0555 root:bin
  193. #
  194. # Replace IPFilter commands with native wrappers
  195. #
  196. if [ -n "$ARCH32" ]; then
  197. replace_with_native /usr/lib/ipf/$ARCH32/ipftest 0555 root:bin
  198. replace_with_native /usr/sbin/$ARCH32/ipf 0555 root:bin
  199. replace_with_native /usr/sbin/$ARCH32/ipfs 0555 root:bin
  200. replace_with_native /usr/sbin/$ARCH32/ipfstat 0555 root:bin
  201. replace_with_native /usr/sbin/$ARCH32/ipmon 0555 root:bin
  202. replace_with_native /usr/sbin/$ARCH32/ipnat 0555 root:bin
  203. replace_with_native /usr/sbin/$ARCH32/ippool 0555 root:bin
  204. fi
  205. if [ -n "$ARCH64" ]; then
  206. replace_with_native /usr/lib/ipf/$ARCH64/ipftest 0555 root:bin
  207. replace_with_native /usr/sbin/$ARCH64/ipf 0555 root:bin
  208. replace_with_native /usr/sbin/$ARCH64/ipfs 0555 root:bin
  209. replace_with_native /usr/sbin/$ARCH64/ipfstat 0555 root:bin
  210. replace_with_native /usr/sbin/$ARCH64/ipmon 0555 root:bin
  211. replace_with_native /usr/sbin/$ARCH64/ipnat 0555 root:bin
  212. replace_with_native /usr/sbin/$ARCH64/ippool 0555 root:bin
  213. fi
  214. #
  215. # Replace in.mpathd daemon at /usr/lib/inet by native wrapper
  216. #
  217. if [ ! -h $ZONEROOT/usr/lib/inet -a -d $ZONEROOT/usr/lib/inet ]; then
  218. safe_replace $ZONEROOT/usr/lib/inet/in.mpathd \
  219. /lib/inet/in.mpathd 0555 root:bin remove
  220. fi
  221. #
  222. # Create wrapper at /lib/inet/in.mpathd as well because native ifconfig
  223. # looks up in.mpathd under /lib/inet.
  224. #
  225. wrap_with_native /lib/inet/in.mpathd 0555 root:bin
  226. # Create native wrapper for /sbin/ipmpstat
  227. wrap_with_native /sbin/ipmpstat 0555 root:bin
  228. #
  229. # Create ipmgmtd wrapper to native binary in s10 container
  230. # and copy ipmgmt service manifest and method.
  231. #
  232. wrap_with_native /lib/inet/ipmgmtd 0555 root:bin
  233. safe_copy /lib/svc/manifest/network/network-ipmgmt.xml \
  234. $ZONEROOT/var/svc/manifest/network/network-ipmgmt.xml
  235. safe_copy /lib/svc/method/net-ipmgmt \
  236. $ZONEROOT/lib/svc/method/net-ipmgmt
  237. #
  238. # To handle certain IPMP configurations, we need updated
  239. # net-physical method script and native net_include.sh
  240. #
  241. filename=$ZONEROOT/lib/svc/method/net-physical
  242. safe_backup $filename $filename.pre_p2v
  243. safe_copy /usr/lib/brand/solaris10/s10_net_physical $filename
  244. filename=$ZONEROOT/lib/svc/share/net_include.sh
  245. safe_backup $filename $filename.pre_p2v
  246. safe_copy /lib/svc/share/net_include.sh $filename
  247. #
  248. # PSARC 2009/306 removed the ND_SET/ND_GET ioctl's for modifying
  249. # IP/TCP/UDP/SCTP/ICMP tunables. If S10 ndd(1M) is used within an
  250. # S10 container, the kernel will return EINVAL. So we need this.
  251. #
  252. replace_with_native /usr/sbin/ndd 0555 root:bin
  253. #
  254. # Replace various ZFS-related programs with native wrappers. These commands
  255. # either link with libzfs, dlopen libzfs or link with libraries that link
  256. # or dlopen libzfs. Commands which fall into these categories but which can
  257. # only be used in the global zone are not wrapped. The libdiskmgt dm_in_use
  258. # code uses libfs, but only the zpool_in_use() -> zpool_read_label() code path.
  259. # That code does not issue ioctls on /dev/zfs and does not need wrapping.
  260. #
  261. replace_with_native /sbin/zfs 0555 root:bin
  262. replace_with_native /sbin/zpool 0555 root:bin
  263. replace_with_native /usr/lib/fs/ufs/quota 0555 root:bin
  264. replace_with_native /usr/lib/fs/zfs/fstyp 0555 root:bin
  265. replace_with_native /usr/lib/zfs/availdevs 0555 root:bin
  266. replace_with_native /usr/sbin/df 0555 root:bin
  267. replace_with_native /usr/sbin/zstreamdump 0555 root:bin
  268. replace_with_native_py /usr/lib/zfs/pyzfs.py 0555 root:bin
  269. #
  270. # Replace automount and automountd with native wrappers.
  271. #
  272. replace_with_native /usr/lib/fs/autofs/automount 0555 root:bin
  273. replace_with_native /usr/lib/autofs/automountd 0555 root:bin
  274. #
  275. # The class-specific dispadmin(1M) and priocntl(1) binaries must be native
  276. # wrappers, and we must have all of the ones the native zone does. This
  277. # allows new scheduling classes to appear without causing dispadmin and
  278. # priocntl to be unhappy.
  279. #
  280. rm -rf $ZONEROOT/usr/lib/class
  281. mkdir $ZONEROOT/usr/lib/class || exit 1
  282. find /usr/lib/class -type d -o -type f | while read x; do
  283. [ -d $x ] && mkdir -p -m 755 $ZONEROOT$x
  284. [ -f $x ] && wrap_with_native $x 0555 root:bin
  285. done
  286. #
  287. # END OF STEP TWO
  288. #
  289. #
  290. # Replace add_drv and rem_drv with /usr/bin/true so that pkgs/patches which
  291. # install or remove drivers will work. NOTE: add_drv and rem_drv are hard
  292. # linked to isaexec so we want to remove the current executable and
  293. # then copy true so that we don't clobber isaexec.
  294. #
  295. filename=$ZONEROOT/usr/sbin/add_drv
  296. [ ! -f $filename.pre_p2v ] && safe_backup $filename $filename.pre_p2v
  297. rm -f $filename
  298. safe_copy $ZONEROOT/usr/bin/true $filename
  299. filename=$ZONEROOT/usr/sbin/rem_drv
  300. [ ! -f $filename.pre_p2v ] && safe_backup $filename $filename.pre_p2v
  301. rm -f $filename
  302. safe_copy $ZONEROOT/usr/bin/true $filename
  303. exit 0