install gawk by default (required for gcc49 build)
[unleashed-kayak.git] / xen_help.sh
blob27a018c76a27d25e27d77e35c2d5e20ed121bb2d
2 # CDDL HEADER START
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License, Version 1.0 only
6 # (the "License"). You may not use this file except in compliance
7 # with the License.
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.
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]
20 # CDDL HEADER END
22 # Copyright 2013 by Andrzej Szeszo. All rights reserved.
24 # Copyright 2013 OmniTI Computer Consulting, Inc. All rights reserved.
25 # Use is subject to license terms.
28 log() {
29 echo "$*"
32 SetupPart() {
34 log "Setting up partition table on /dev/rdsk/${DISK}p0"
36 cat <<EOF | fdisk -F /dev/stdin /dev/rdsk/${DISK}p0
37 0 0 0 0 0 0 0 0 0 0
38 0 0 0 0 0 0 0 0 0 0
39 0 0 0 0 0 0 0 0 0 0
40 0 0 0 0 0 0 0 0 0 0
41 EOF
43 #NUMSECT=`fdisk -G /dev/rdsk/${DISK}p0|awk '!/^\*/ { print $1 * $5 * $6 - 34816 }'`
44 NUMSECT=`iostat -En $DISK|nawk '/^Size:/ { sub("<",""); print $3/512 - 34816 }'`
46 fdisk -A 6:0:0:0:0:0:0:0:2048:32768 /dev/rdsk/${DISK}p0
47 fdisk -A 191:0:0:0:0:0:0:0:34816:$NUMSECT /dev/rdsk/${DISK}p0
50 SetupPVGrub() {
52 log "Setting up 16MB FAT16 pv-grub filesystem"
54 echo y|mkfs -F pcfs -o b=pv-grub /dev/rdsk/${DISK}p0:c
55 mount -F pcfs /dev/dsk/${DISK}p1 $ALTROOT
56 cp $PVGRUB $ALTROOT/pv-grub.gz
57 mkdir -p $ALTROOT/boot/grub
59 cat <<EOF >$ALTROOT/boot/grub/menu.lst
60 timeout 0
61 default 0
62 title chainload pv-grub
63 root (hd0,0)
64 kernel /pv-grub.gz (hd0,1,a)/boot/grub/menu.lst
65 EOF
67 umount $ALTROOT
70 SetupZPool() {
72 log "Setting up '${RPOOL}' zpool"
74 # some of the commands below were borrowed from disk_help.sh
76 prtvtoc -h /dev/rdsk/${DISK}p0 | \
77 awk '/./{p=0;} {if($1=="2"){size=$5;p=1;} if($1=="8"){start=$5;p=1;} if(p==1){print $1" "$2" "$3" "$4" "$5;}} END{size=size-start; print "0 2 00 "start" "size;}' | \
78 sort -n | fmthard -s /dev/stdin /dev/rdsk/${DISK}s2 >/dev/null
80 zpool create -f ${RPOOL} /dev/dsk/${DISK}s0
82 zfs set compression=on ${RPOOL}
83 zfs create ${RPOOL}/ROOT
84 # zfs set canmount=off ${RPOOL}/ROOT
85 zfs set mountpoint=legacy ${RPOOL}/ROOT
88 ZFSRecvBE() {
89 log "Receiving ${RPOOL}/ROOT/${BENAME} filesystem"
90 cat $ZFSSEND | pv -B 128m | bzip2 -dc | zfs receive -u ${RPOOL}/ROOT/${BENAME}
91 zfs set canmount=noauto ${RPOOL}/ROOT/${BENAME}
92 zfs set mountpoint=legacy ${RPOOL}/ROOT/${BENAME}
93 zfs destroy ${RPOOL}/ROOT/${BENAME}@kayak || true
96 MountBE() {
97 log "Mounting BE"
98 mount -F zfs ${RPOOL}/ROOT/${BENAME} $ALTROOT
101 UmountBE() {
102 log "Unmounting BE"
103 umount $ALTROOT
106 PrepareBE() {
108 log "Preparing BE"
110 cp $ALTROOT/lib/svc/seed/global.db $ALTROOT/etc/svc/repository.db
111 chmod 0600 $ALTROOT/etc/svc/repository.db
112 chown root:sys $ALTROOT/etc/svc/repository.db
114 /usr/sbin/devfsadm -r $ALTROOT
116 [[ -L $ALTROOT/dev/msglog ]] || \
117 ln -s ../devices/pseudo/sysmsg@0:msglog $ALTROOT/dev/msglog
119 # GRUB stuff
120 log "...setting up GRUB and the BE"
121 mkdir -p /${RPOOL}/boot/grub/bootsign
122 touch /${RPOOL}/boot/grub/bootsign/pool_${RPOOL}
123 chown -R root:root /${RPOOL}/boot
124 chmod 444 /${RPOOL}/boot/grub/bootsign/pool_${RPOOL}
126 RELEASE=`head -1 $ALTROOT/etc/release | sed -e 's/ *//;'`
128 cat <<EOF >/${RPOOL}/boot/grub/menu.lst
129 default 0
130 timeout 3
132 title ${BENAME}
133 findroot (pool_${RPOOL},1,a)
134 bootfs ${RPOOL}/ROOT/${BENAME}
135 kernel$ /platform/i86pc/kernel/unix -B \$ZFS-BOOTFS
136 module$ /platform/i86pc/boot_archive
137 #============ End of LIBBE entry =============
140 sed -i '' -e "s/^title.*/title $RELEASE/;" /${RPOOL}/boot/grub/menu.lst
142 bootadm update-archive -R $ALTROOT
144 zpool set bootfs=${RPOOL}/ROOT/${BENAME} ${RPOOL}
146 # Allow root to ssh in
147 log "...setting PermitRootLogin=yes in sshd_config"
148 sed -i '' -e 's%^PermitRootLogin.*%PermitRootLogin yes%' $ALTROOT/etc/ssh/sshd_config
150 # Prevent direct root non-RSA logins (passwd -N equivalent)
151 log "...NP'ing root's password"
152 sed -i '' -e 's/^root:\$.*:/root:NP:6445::::::/;' $ALTROOT/etc/shadow
154 # Set up to use DNS (hello, this is the year 2013. I never really understood this)
155 log "...enabling DNS resolution"
156 cp $ALTROOT/etc/nsswitch.dns $ALTROOT/etc/nsswitch.conf
158 # Install ec2-credential and ec2-api-tools packages. rsync needed for vagrant
159 log "...installing EC2 and rsync packages"
160 pkg -R $ALTROOT install network/rsync ec2-credential ec2-api-tools