[OmniOS-discuss] LX for OmniOS update

Michael Rasmussen mir at miras.org
Tue Aug 9 22:11:39 UTC 2016


Hi Dan,

On Tue, 9 Aug 2016 16:08:11 -0400
Dan McDonald <danmcd at omniti.com> wrote:

> Look in the script /usr/lib/brand/lx/lx_install to see what I mean.
> 
Nice.

I have taken the liberty to extend your script to handle gzipped
tarballs of a root filesystem using the argument -t. With the stuff I
have added I was able to use the script to install a lxc prepared
tarball of Debian stable with your install script;-)

root at localhost:~# uname -a
Linux localhost 3.16.0 BrandZ virtual linux x86_64 GNU/Linux

root at localhost:~# ls -l /
total 33
drwxr-xr-x  2 root root  108 Jun 30  2015 bin
drwxr-xr-x  2 root root    2 May  4  2015 boot
drwxr-xr-x 62 root sys    12 Aug  9 21:58 dev
drwxr-xr-x 69 root root  151 Aug  9 21:58 etc
drwxr-xr-x  2 root root    2 May  4  2015 home
drwxr-xr-x 12 root root   23 Jun 30  2015 lib
drwxr-xr-x  2 root root    3 Jun 30  2015 lib64
drwxr-xr-x  2 root root    2 Jun 30  2015 media
drwxr-xr-x  2 root root    2 Jun 30  2015 mnt
drwxr-xr-x  9 root root    9 Aug  9 21:58 native
drwxr-xr-x  2 root root    2 Jun 30  2015 opt
dr-xr-xr-x 95 root root 1520 Aug  9 21:58 proc
drwx------  2 root root    4 Jun 30  2015 root
drwxr-xr-x  9 root root 1355 Aug  9 21:58 run
drwxr-xr-x  2 root root  109 Jun 30  2015 sbin
drwxr-xr-x  2 root root    2 Jun 30  2015 srv
dr-xr-xr-x  1 root root    0 Aug  9 21:58 sys
drwxr-xr-x  4 root root    4 Aug  9 21:58 system
drwxrwxrwt  4 root root    4 Aug  9 21:58 tmp
drwxr-xr-x 10 root root   10 Jun 30  2015 usr
drwxr-xr-x 12 root root   14 Aug  9 21:58 var

I have simply added in the installed script so no diff (Sorry, bad move
but I got exited ;-)

# cat /usr/lib/brand/lx/lx_install #!/bin/ksh -p
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
# Copyright 2016 Joyent, Inc.  All rights reserved.
# Copyright 2016 OmniTI Computer Consulting, Inc.  All rights reserved.
#

PATH=/bin:/usr/bin:/usr/sbin
export PATH

. /usr/lib/brand/shared/common.ksh

ZFS_SEED=""
TAR_SEED=""

bad_usage() {
	echo "LX zone install bad option"
	echo "Available options are:"
	echo "	-s <absolute-pathname>	Path to ZFS send stream or gzip thereof"
	echo "  -t <absolute-pathname>  Path to gzipped tarball of root" 
	exit $ZONE_SUBPROC_USAGE
}

while getopts "R:s:t:z:" opt
do
	case "$opt" in
		R)	ZONEPATH="$OPTARG";;
		z)	ZONENAME="$OPTARG";;
		s)	ZFS_SEED="$OPTARG";;
		t)	TAR_SEED="$OPTARG";;
		*)	bad_usage ;;
	esac
done
shift OPTIND-1

if [[ $ZFS_SEED == "" && $TAR_SEED == "" ]]; then
    echo "The -s <absolute-pathname> or -t <absolute-pathname>"
    echo "argument is required for LX installation."
    bad_usage
fi

# Set the ZONEPATH_DS variable so we know the zone's dataset.
get_zonepath_ds $ZONEPATH

# Do something based on whatever ZFS_SEED is.

if [[ -n $ZFS_SEED ]]; then
    if [[! -f $ZFS_SEED ]]; then
        echo "Seed file $ZFS_SEED not found."
        # XXX KEBE SAYS maybe we can eat a snapshot name here, or even a
        # Joyent-style UUID for direct snagging from Joyent's image
        # servers.
        bad_usage
    fi
    type=`file -b $ZFS_SEED | awk '{print $1}'`
elif [[ -n $TAR_SEED ]]; then
    if [[ ! -f $TAR_SEED ]]; then
        echo "Seed file $TAR_SEED not found."
        bad_usage
    fi
    type=tgz
fi

# For now, we are dependent on the output of file(1).
# I'm being cheesy in checking the first word of file(1)'s output.
if [[ $type == "ZFS" ]]; then
    zfs recv -F $ZONEPATH_DS < $ZFS_SEED
    RESULT=$? 
    MSG="ZFS receive command failed"
elif [[ $type == "gzip" ]]; then
    gunzip -c $ZFS_SEED | zfs recv -F $ZONEPATH_DS
    RESULT=$?
    MSG="ZFS receive command failed"
elif [[ $type == "tgz" ]]; then
    mkdir $ZONEPATH_DS/root
    chmod 755 $ZONEPATH_DS/root
    tar -xzf $TAR_SEED -C $ZONEPATH_DS/root
    RESULT=$?
    MSG="TAR command failed"
else
    echo "Seed file $ZFS_SEED not a ZFS receive (or compressed) one."
    bad_usage
fi

if [[ $RESULT != 0 ]]; then
   echo "$MSG ($RESULT)."
   exit $ZONE_SUBPROC_FATAL
fi

# One Joyent-ism we need to clean up.
if [[ -d $ZONEPATH/cores ]]; then
    rmdir $ZONEPATH/cores
fi

exit 0

-- 
Hilsen/Regards
Michael Rasmussen

Get my public GnuPG keys:
michael <at> rasmussen <dot> cc
http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xD3C9A00E
mir <at> datanom <dot> net
http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xE501F51C
mir <at> miras <dot> org
http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xE3E80917
--------------------------------------------------------------
/usr/games/fortune -es says:
What does it mean if there is no fortune for you?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: OpenPGP digital signature
URL: <https://omniosce.org/ml-archive/attachments/20160810/ae827e1e/attachment.bin>


More information about the OmniOS-discuss mailing list