Build a Minimal Solaris Image

Build a Minimal Solaris Image
Here is a simple script to build a minimal Solaris x86 image from packages. The output file, sol_image, boots to multiuser login prompt with the following GRUB commands:
    kernel /path/multiboot kernel/unix
    module /path/sol_image
where multiboot is from /boot in the Solaris media. Note that the image contains minimal hardware support and many SMF services are not available.

Before running the script, PROD should be set to the Product directory of the Solaris distribution media. The package list is determined empirically and is known to work from Solaris 10 1/06 to the latest OpenSolaris (build 48). A more flexible treatment of packages can be found here. For OpenSolaris kernel hackers, you can test your kernel changes by setting the PROD_OVERRIDE variable to the package area of your workspace.


#!/bin/ksh

PKGADD=/usr/sbin/pkgadd
PKGLOG=/tmp/packages.log
PKGADMIN=/tmp/pkgadmin
ROOTDIR=/tmp/miniroot
PROD=/cdrom/Solaris_11/Product
PROD_OVERRIDE=/myworkspace/packages/i386/nightly

#
# Minimum list of packages that boots to login prompt on text console.
# Add additional packages to get more functionality (e.g. add SUNWmdbr
# for kernel debugging via kmdb).
#
PKGLIST="
        SUNWcar.i
        SUNWcakr.i
        SUNWkvm.i
        SUNWcsr
        SUNWcsd
        SUNWos86r
        SUNWrmodr
        SUNWpsdcr
        SUNWpsdir
        SUNWckr
        SUNWcnetr
        SUNWcsl
        SUNWcsu
        SUNWcslr
        SUNWesu
        SUNWkey
        SUNWlibms
        SUNWlibmsr
        SUNWusb
        SUNWpr
        SUNWtls
        SUNWlibsasl
        SUNWlxml
        SUNWopenssl-libraries
        SUNWusbs
        SUNWmdr
        SUNWmdu
        SUNWtecla
        SUNWzlib
        SUNWuprl
        SUNWsmapi
        SUNWkrbr
        SUNWkrbu
        SUNWtnetr
        SUNWtnetd
        SUNWgss
        SUNWbipr
        SUNWbip
"

#
# Create a pkg admin file - see man admin(4)
#
sed 's/ask/nocheck/' /var/sadm/install/admin/default > $PKGADMIN

echo "adding packages to $ROOTDIR"

[ -d $ROOTDIR ] && rm -fr $ROOTDIR
mkdir -p $ROOTDIR

for pkg in $PKGLIST; do
        if [ -d "$PROD_OVERRIDE/$pkg" ]; then
                echo "  $pkg added from $PROD_OVERRIDE"
                $PKGADD -a $PKGADMIN -d $PROD_OVERRIDE -R $ROOTDIR $pkg \\
                        > PKGLOG 2>&1
        elif [ -d "$PROD/$pkg" ]; then
                echo "  $pkg added from $PROD"
                $PKGADD -a $PKGADMIN -d $PROD -R $ROOTDIR $pkg \\
                        > PKGLOG 2>&1
        else
                echo "  $pkg not found: skipped"
        fi
done

#
# Strip amd64 binaries
#
echo "strip amd64 binaries"
(cd $ROOTDIR; find . -name amd64 | xargs rm -r 2> /dev/null)

#
# remove packaging, xpg4, sfw
#
echo "strip packaging, xpg4, and freeware"
(cd $ROOTDIR; rm -r var/sadm/\* usr/xpg4 usr/sfw)

#
# Fix up the image so it boot to login prompt
#
echo "fix /etc/vfstab, /etc/nodename, and /etc/hosts"
echo "/devices/ramdisk:a - / ufs - no nologging" >> $ROOTDIR/etc/vfstab
echo "embedded" > $ROOTDIR/etc/nodename
echo "127.0.0.1 localhost loghost" > $ROOTDIR/etc/hosts

#
# Set the environment variables for svccfg.
#
echo "customize SMF services"
SVCCFG_DTD=$ROOTDIR/usr/share/lib/xml/dtd/service_bundle.dtd.1
SVCCFG_REPOSITORY=$ROOTDIR/etc/svc/repository.db
SVCCFG=/usr/sbin/svccfg

export SVCCFG_DTD SVCCFG_REPOSITORY SVCCFG

echo "add sysconfig milestone and system-log service"
$SVCCFG import $ROOTDIR/var/svc/manifest/milestone/sysconfig.xml
$SVCCFG import $ROOTDIR/var/svc/manifest/system/system-log.xml
$SVCCFG -s system/system-log:default setprop general/enabled=true

echo "turnoff boot-archive, rpc bind, ipfilter, manifest-import, metainit"
$SVCCFG -s system/boot-archive setprop start/exec=:true
$SVCCFG -s system/manifest-import setprop start/exec=:true
$SVCCFG -s network/rpc/bind delpg sysidtool
$SVCCFG -s network/rpc/bind:default setprop general/enabled=false
$SVCCFG -s network/pfil:default setprop general/enabled=false
$SVCCFG -s system/metainit:default setprop general/enabled=false

#
# pack the image in a form loadable by grub
#
echo "create boot archive sol_image"
/boot/solaris/bin/root_archive pack sol_image $ROOTDIR

Comments:

Post a Comment:
Comments are closed for this entry.
About

szhou

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today