]>
git.saurik.com Git - apple/launchd.git/blob - launchd/src/rc.netboot
d3397b426645edf1c634fbe05123b2c851c34641
3 # Copyright 2002 Apple Computer, Inc.
5 # This script configures NetBoot
11 # Define: NETBOOT_SHADOW
13 # To change the behavior of the system when choosing a netboot shadow
16 # -NETWORK- Try to use the network for the shadow file, if
17 # that fails, use the local drive
18 # -NETWORK_ONLY- Only use the network, fail if not available
19 # -LOCAL- Use the local drive for the shadow file, if that
20 # fails, use the network
21 # -LOCAL_ONLY- Only use the local drive for the shadow, fail if
24 NETBOOT_MOUNT
=/var
/netboot
25 NETBOOT_SHADOW
=${NETBOOT_SHADOW:-NETWORK-}
30 echo rc.netboot
: $1 > /dev
/console
39 if [ "${netboot_dir}" = "" ] ; then
40 Failed
"netboot_dir is empty"
42 if [ "${netboot_shadow}" = "" ] ; then
43 Failed
"netboot_shadow is empty"
45 netboot_shadow
="${netboot_dir}/${netboot_shadow}"
46 if ! mkdir -p "${netboot_dir}" ; then
47 Failed
"create ${netboot_dir} failed"
49 chmod 700 "${netboot_dir}"
51 root_device
=$(mount | sed -n 's:/dev/\(.*\) on
/ .
*:\
1:p
')
52 case "${root_device}" in
54 if ! touch "${netboot_shadow}" ; then
55 Failed "create ${netboot_shadow} failed"
57 chmod 600 "${netboot_shadow}"
58 if ! /usr/libexec/vndevice shadow "/dev/r${root_device}" "${netboot_shadow}" ; then
59 Failed "vndevice shadow failed"
63 Failed "root device unknown"
66 if ! touch "${netboot_shadow}" ; then
67 Failed "failed to create shadow ${netboot_shadow}"
69 chmod 600 "${netboot_shadow}"
70 if ! /usr/bin/nbdst -recycle "${root_device}" "${netboot_shadow}" ; then
81 while [ $tries -lt $limit ]; do
82 tries=$(( tries + 1 ))
83 volinfo=`autodiskmount -F 2>/dev/null`
85 if [ $tries -lt $limit ]; then
86 echo "Waiting for local drives..."
87 echo "Waiting for local drives (retry ${tries}/$(( limit - 1 )))..." > /dev/console
90 echo "autodiskmount -F found no local drives"
101 mount -t "${fstype}" -o nosuid,nodev "/dev/${devname}" "${NETBOOT_MOUNT}" 2>&1
102 if [ $? -ne 0 ]; then
103 echo "mount of ${devname} failed"
106 common_start "${NETBOOT_MOUNT}/.com.apple.NetBootX" shadowfile
112 mount_from=$(ipconfig netbootoption shadow_mount_path 2>&1)
113 if [ $? -ne 0 ]; then
114 echo "no network shadow mount path available"
117 shadow_path=$(ipconfig netbootoption shadow_file_path 2>&1)
118 if [ $? -ne 0 ]; then
119 echo "no network shadow file path available"
122 case "${mount_from}" in
125 *) echo "unknown network filesystem mount from ${mount_from}"
129 mount -t "${fstype}" "${mount_from}" "${NETBOOT_MOUNT}"
130 if [ $? -ne 0 ]; then
131 echo "mount -t ${fstype} ${mount_from} ${NETBOOT_MOUNT} failed"
134 common_start "${NETBOOT_MOUNT}" "${shadow_path}"
140 case "${NETBOOT_SHADOW}" in
143 if [ $? -ne 0 ]; then
149 if [ $? -ne 0 ]; then
151 if [ $? -ne 0 ]; then
152 Failed "Could not find a local or network drive"
158 if [ $? -ne 0 ]; then
165 if [ $? -ne 0 ]; then
167 if [ $? -ne 0 ]; then
168 Failed "Could not find a network or local drive"
178 # attach the shadow file to the root disk image
181 # make sure the root filesystem is clean
182 fsck -p || fsck -fy || Failed "Could not clean root filesystem"
187 # adjust /private/var/vm to point to the writable area (if not diskless)
188 swapdir=/private/var/vm
189 mounted_from=$(mount | sed -n 's:\(.*\) on .*/var/netboot.*:\1:p')
190 case "${mounted_from}" in
192 netboot_dir
="${NETBOOT_MOUNT}/.com.apple.NetBootX"
193 if [ -d "${netboot_dir}" ]; then
195 ln -s "${netboot_dir}" "${swapdir}"
202 # set the ComputerName based on what the NetBoot server told us it was
203 machine_name
=$(ipconfig netbootoption machine_name 2>&1)
204 if [ $?
-ne 0 ]; then
205 echo "no machine name option available"
207 echo "Setting ComputerName to ${machine_name}"
208 scutil
--set ComputerName
"${machine_name}"
213 if [ $# -lt 1 ] ; then