lx_init_zone.ksh revision 9acbbeaf2a1ffe5c14b244867d427714fab43c5c
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# ident "%Z%%M% %I% %E% SMI"
#
#
# This script contains various routines used to post-process a zone for use
# with BrandZ after it has been installed from RPM media or a tar image.
#
# Briefly, there are three main jobs we need to do:
#
# 1) Create any needed directories and symlinks BrandZ needs but that the
# Linux install may not create
#
# 2) Modify rc scripts to shut off services that don't apply to a zone
# or that wish to access hardware directly
#
# 3) Modify various Linux system files for use within a zone environment
#
#
#
export PATH
#
# Sends output to log file if "$logfile" is set
#
log()
{
}
#
# Setup i18n output
#
TEXTDOMAIN="SUNW_OST_OSCMD"
export TEXTDOMAIN
#
# Output an internationalized string followed by a carriage return
#
{
typeset fmt="$1"
shift
}
#
# Routine to make a full path out of a supplied path
#
fullpath()
{
typeset path="$1"
echo $path
}
#
# Routine to create directories and handle errors
#
makedir()
{
typeset mode=""
exit 1
fi
}
#
# Routine to create initial symlinks and handle errors
#
symlink()
{
typeset src="$1"
exit 1
fi
}
#
# Install a file using "ln -s"
#
# Returns 0 on success, 1 on failure.
#
{
typeset source="$1"
log ""
return 1
fi
return 0
}
#
# Enable NFS servers and the NFS lock daemon for a particular zone.
#
{
log "Non-miniroot install; enabing NFS servers and NFS lock daemon"
#
# Setup files required for NFS:
#
#
# These two files are treated as read-only in lx branded zones.
# To enfore this restriction we will read-only lofs mount them
# into the zone from the global zone. For these lofs mounts to
# work we'll need to create empty directories now that will serve
# as mount points later.
#
#
# These files are symlinks to scripts supplied by the lx brand
# that will start up the solaris nfs daemons.
#
log "Aborting NFS setup..."
log ""
return
fi
log "Aborting NFS setup..."
log ""
return
fi
#
#
log ""
log "Adding lockd entry to \"$install_root/etc/services\"..."
#
# Brackets in the sed script below contain a space followed by a tab
#
cat >> $install_root/etc/services <<-EOF
lockd 4045/udp # NFS lock daemon/manager
lockd 4045/tcp # NFS lock daemon/manager
EOF
#
# find some commands in alternate locations.
#
log ""
log "Modifying \"$install_root/etc/init.d/nfslock\"..."
sed '
s/USERLAND_LOCKD=$/USERLAND_LOCKD="yes"/
' |
}
#
# The main script starts here.
#
# The syntax is:
#
# lx_init_zone <rootdir> <logfile> [mini]
#
# Where:
# <rootdir> is the root of the zone directory to be modified
#
# <logfile> is the name of the log file to which error messages should
# be appended
#
# [mini] is an optional third argument that signifies whether this is
# to be a miniroot install; if it is, NFS services are not enabled
# in the processed zone
#
unset is_miniroot
unset install_root
unset logfile
install_root="$1"
logfile="$2"
if (($# < 2 || $# > 3)); then
exit 1
fi
exec 2>>"$logfile"
if [[ ! -d "$install_root" ]]; then
exit 1
fi
cd "$install_root"
log ""
log "Making needed directories in \"$install_root\"."
#
# Make various directories in /native that are needed to boot an lx branded
# zone.
#
#
# Make various other directories needed for the lx brand
#
#
# zlogin requires that these utilities live in places other than their
# Linux defaults, so create appropriate links for them here.
#
# XX - The need for these links may go away in the future if zlogin is
# appropriately modified
#
log ""
log "Modifying system configuration in \"$install_root\""
#
# libraries.
#
log "Creating \"$install_root/var/ld/ld.config\"..."
log "\tCreation of \"$install_root/var/ld/ld.config\" failed!"
i18n_echo "$cmd_failed" "crle"
exit 1
fi
log ""
log "Modifying \"$install_root/etc/fstab\"..."
none / ufs defaults 1 1
none /proc proc defaults 0 0
EOF
if [[ $? -ne 0 ]]; then
log "Could not create new \"$install_root/etc/fstab\"!"
exit 1
fi
#
# as well as xdm on the X console. Since we don't have virtual consoles nor
#
# Don't bother changing the file if it looks like we already did.
#
log "Modifying: \"$install_root/etc/inittab\"..."
sed -e 's/^[1-6x]:/# Disabled by lx brand: &/
s/^id:5:initdefault:/id:3:initdefault: # Modified by lx brand: &/' \
#
# Don't bother with further alterations if the sed above failed...
#
if [[ $? -eq 0 ]]; then
if [[ $? -ne 0 ]]; then
#
# console login for lx brand
#
1:2345:respawn:/sbin/mingetty console
EOF
#
# Only install the new inittab if the append
# above succeeded.
#
if [[ $? -eq 0 ]]; then
#
# Attempt to save off the original inittab
# before moving over the modified version.
#
if [[ $? -ne 0 ]]; then
"\"$installroot/etc/inittab\"" \
"failed!"
i18n_echo "$cmd2_failed" "mv" \
"$tmpfile" \
exit 1
else
fi
fi
fi
else
log "Attempt to disable entries in" \
"\"$install_root/etc/inittab\" failed!"
exit 1
fi
fi
if [[ ! -e "$install_root/etc/hosts" ]]; then
log ""
log "Creating: \"$install_root/etc/hosts\"..."
cat > "$install_root/etc/hosts" <<-_EOF_
127.0.0.1 localhost
_EOF_
fi
#
# User must configure various brand-specific items to enable networking, so
# boot the system non-networked.
#
log ""
log "Modifying: \"$install_root/etc/sysconfig/network\"..."
NETWORKING="no"
#
# To enable networking, change the "no" above to "yes" and
# uncomment and fill in the following parameters.
#
# If you are specifying a hostname by name rather than by IP address,
# be sure the system can resolve the name properly via the use of a
# name service and/or the proper name files, as specified by
# nsswitch.conf. See nsswitch.conf(5) for further details.
#
# HOSTNAME=your_hostname_here
#
EOF
if [[ $? -ne 0 ]]; then
log "Could not create new \"$install_root/etc/sysconfig/network\"!"
exit 1
fi
#
#
log ""
log "Modifying: \"$install_root/etc/sysconfig/syslog\"..."
#
#
if [[ $? -eq 0 ]]; then
#
# Attempt to save off the original syslog before moving over
# the modified version.
#
"\"$installroot/etc/sysconfig/syslog\" failed!"
i18n_echo "$cmd2_failed" "mv" "$tmpfile" \
exit 1
else
fi
else
log "Attempt to modify entries in" \
"\"$install_root/sysconfig/syslog\" failed!"
exit 1
fi
fi
if [[ $? -ne 0 ]]; then
log "Could not create new \"$install_root/etc/sysconfig/syslog\"!"
exit 1
fi
#
#
#
# text operations, which we don't support. Removing this file disables the
# mouse configuration.
#
#
# The following scripts attempt to start services or otherwise configure
# the system in ways incompatible with zones, so don't execute them at boot
# time.
#
log ""
log "Modifying \"$install_root/etc/rc.d/init.d\" to disable any"
log " services not supported by BrandZ:"
kudzu
microcode_ctl
network
random
pcmcia
isdn
iptables
ip6tables
iscsi
saslauthd
psacct
xfs
gpm
irda
smartd
rawdevices
netdump
snmpd
snmptrapd
hpoj
netfs
mdmonitor
mdmpd
irqbalance
"
fi
fi
if [[ -h "$file" ]]; then
else
fi
done
fi
done
#
# There is a lot of stuff in the standard halt and reboot scripts that we
# have no business running in a zone. Fortunately, the stuff we want to
# skip is all in one contiguous chunk.
#
# Don't bother to modify the file if it looks like we already did.
#
log ""
log " within a zone..."
awk 'BEGIN {skip = ""}
/^# Save mixer/ {skip = "# Disabled by lx brand: "}
/halt.local/ {skip = ""}
if [[ $? -eq 0 ]]; then
else
"FAILED"
log "Continuing with balance of zone setup..."
fi
fi
#
# Fix up /etc/rc.d/rc.sysinit:
#
# Since the hardware clock cannot be set from within a zone, we comment out
# the line.
#
# 2) Disable dmesg commands, since we don't implement klogctl
#
#
# work from within a zone.
#
# 5) Don't try to check the root filesystem (/) as there is no associated
# physical device, and any attempt to run fsck will fail.
#
# Don't modify the rc.sysinit file if it looks like we already did.
#
log ""
log "Modifying: \"$install_root/etc/rc.d/rc.sysinit\"..."
log ""
s@^HOSTTYPE=@HOSTTYPE=\"s390\" # Spoofed for lx brand: &@
s@^dmesg -s@# Disabled by lx brand: &@
s@initlog -c \"fsck@: # Disabled by lx brand: &@
#
# Only install the new rc.sysinit if the edit above succeeded.
#
if [[ $? -eq 0 ]]; then
#
# Attempt to save off the original rc.sysinit
# before moving over the modified version.
#
"\"$installroot/etc/rc.d/rc.sysinit\" failed!"
i18n_echo "$cmd2_failed" "mv" "$tmpfile" \
exit 1
else
fi
else
log "Attempt to modify entries in" \
"\"$install_root/rc.d/rc.sysinit\" failed!"
exit 1
fi
fi
if [[ -z $is_miniroot ]]; then
fi
log ""
log ""
i18n_echo "System configuration modifications complete!"
exit 0