2 #----------------------------------------------------
3 #shell used to prepare container structure, this script
4 #is called by the vzgot before any root pivot action.
5 #It is used on the firstboot to prepare all needed file.
7 #----------------------------------------------------
9 #vzgot.fistboot VE_name node domain ip_list [Base]
10 # VE_name is the container dir name
11 # Node is the container hostname
12 # Domain is the container domainname
13 # IP_LIST is an ip list (ip,ip1,ip2,..) used
14 # to prepare container network
15 # base_dir is this application root directory
16 # (used for devel only).
17 #----------------------------------------------------
23 #----------------------------------------------------
24 if ! [ -f $BASE/etc/vzgot/vzgot_config ] ; then
25 echo "Missing vzgot config file"
26 exit 1 #trouble trouble
28 . $BASE/etc/vzgot/vzgot_config
30 #specific container configuration override (if needed)
31 if [ -f $BASE/$VZLIB/vzdir/$CONTNAME/vzgot_config ] ; then
32 $BASE/$VZLIB/vzdir/$CONTNAME/vzgot_config
34 #----------------------------------------------------
35 VZROOT=$BASE/$VZLIB/vzdir/$CONTNAME/rootfs
36 #====================================================
37 #procedure to implement redhat distribution file
38 #----------------------------------------------------
39 #Prepare /etc/hosts file
40 #----------------------------------------------------
42 HOSTS="$BASE/$VZLIB/vzdir/$CONTNAME/rootfs/etc/hosts"
44 echo "#----------------------------------------------------"
45 echo "#done by vzgot.fboot"
46 echo "#----------------------------------------------------"
47 echo -e "127.0.0.1\tlocalhost.localdomain\tlocalhost"
50 if [ -n $LSTIP ] ; then
52 echo -n `echo $LSTIP | tr ',' ' ' | cut -d' ' -f1`
53 echo -e "\t$NODE.$DOMAIN\t\t$NODE"
54 echo "#----------------------------------------------------"
58 #----------------------------------------------------
59 #Prepare /etc/hostname
60 #----------------------------------------------------
61 HST="$BASE/$VZLIB/vzdir/$CONTNAME/rootfs/etc/hostname"
66 #----------------------------------------------------
67 #Prepare /etc/network/interface
68 #----------------------------------------------------
69 #need directory to have /etc/init.d/networking to work
70 mkdir -p $BASE/$VZLIB/vzdir/$CONTNAME/rootfs/var/run/network
73 INT="$BASE/$VZLIB/vzdir/$CONTNAME/rootfs/etc/network/interfaces"
75 echo "# Used by ifup(8) and ifdown(8). See the interfaces(5) manpage or"
76 echo "# /usr/share/doc/ifupdown/examples for more information."
79 echo "iface lo inet loopback"
81 if [ -n $LSTIP ] ; then
82 ETH0=`echo $LSTIP | tr ',' ' ' | cut -d' ' -f1`
86 echo "iface eth0 inet static"
88 echo "netmask 255.255.255.255"
89 echo "up route add default dev eth0"
91 ETHX=`echo $LSTIP | tr ',' ' ' | cut -s -d' ' -f2-`
96 echo "auto eth0:$aliasnum"
98 echo "netmask 255.255.255.255"
100 let aliasnum=aliasnum+1
103 #----------------------------------------------------
104 #Prepare /dev directoy contents
105 #----------------------------------------------------
110 mknod -m 666 $DEV/null c 1 3
111 mknod -m 666 $DEV/zero c 1 5
112 mknod -m 666 $DEV/random c 1 8
113 mknod -m 666 $DEV/urandom c 1 9
114 mkdir -m 755 $DEV/pts
115 mkdir -m 1777 $DEV/shm
116 mknod -m 666 $DEV/tty c 5 0
117 mknod -m 600 $DEV/console p
118 mknod -m 666 $DEV/tty0 c 4 0
119 mknod -m 666 $DEV/full c 1 7
120 mknod -m 600 $DEV/initctl p
121 mknod -m 666 $DEV/ptmx c 5 2
123 #----------------------------------------------------
124 #Prepare /dev directoy fstab
125 #----------------------------------------------------
126 FSTAB="$VZROOT/etc/fstab"
128 echo -e "/vzgot\t\t/\t\text3\tdefaults\t0 0"
129 echo -e "proc\t\t/proc\t\tproc\tdefaults\t0 0"
130 echo -e "sysfs\t\t/sys\t\tsysfs\tdefaults\t0 0"
131 echo -e "devpts\t\t/dev/pts\t\tdevpts\tdefaults\t0 0"
132 echo -e "tmpfs\t\t/dev/shm\t\ttmpfs\tdefaults\t0 0"
135 #====================================================
136 #starting common container configuration process
140 #----------------------------------------------------
141 #insert a common root password within the vz
143 if [ -f etc/shadow ] ; then
144 SHAD="$VZROOT/etc/shadow"
145 sed 's/#.*//g' etc/shadow | grep -v '^[[:space:]]*$' | \
148 NAME=`echo $LINE | cut -d':' -f1`
149 (echo $LINE ; grep -v "^$NAME:" $SHAD) > $SHAD.new
150 mv -f $SHAD.new $SHAD
155 #setting the DNS resolver
156 if [ -f etc/resolv.conf ] ; then
157 cp -a etc/resolv.conf $VZROOT/etc
160 #duplicating ssh Key if we want to have all container even.
161 if [ -d etc/ssh ] ; then
162 #removing the hack to make original KEY
163 rm -fr $VZROOT/etc/rc2.d/S11sshhack
164 rm -fr $VZROOT/etc/init.d/ssh_key_hack.sh
165 for k in `ls etc/ssh/*key* 2> /dev/null`
167 cp -a $k $VZROOT/etc/ssh
171 #insert iptables script
172 if [ -f etc/sysconfig/iptables ] ; then
173 cp -a etc/sysconfig/iptables $VZROOT/etc/sysconfig
176 #adding sudoer informations
177 if [ -f etc/sudoers ] ; then
178 cat etc/sudoers >> $VZROOT/etc/sudoers
181 #adding snmpd.conf specific to ALL container
182 if [ -d $VZROOT/etc/snmp/ ] && [ -f etc/snmp/snmpd.conf ] ; then
183 cat etc/snmp/snmpd.conf>> $VZROOT/etc/snmp/snmpd.conf
187 #end common container configuration process
188 #====================================================
189 #lets create common users and groups
190 ARCH=`cat $VZLIB/vzdir/$CONTNAME/arch`
191 CHROOT="/usr/bin/setarch $ARCH /usr/sbin/chroot"
193 $CHROOT $VZROOT mount -t proc proc /proc
194 $CHROOT $VZROOT mount -t sysfs sysfs /sys
196 #creating common group
197 if [ -f $VZLIB/etc/groups ] ; then
198 sed 's/#.*//g' $VZLIB/etc/groups | grep -v '^[[:space:]]*$' | \
199 while read -r GRPNAME
201 $CHROOT $VZROOT groupadd $GRPNAME
205 #creating common users
206 if [ -f $VZLIB/etc/users ] ; then
207 sed 's/#.*//g' $VZLIB/etc/users | grep -v '^[[:space:]]*$' | \
208 while read -r NAME CRYPTED GRPNAME
210 if [ -d $VZLIB/home/$NAME ] ; then
211 cp -a $VZLIB/home/$NAME $VZROOT/tmp
214 $CHROOT $VZROOT useradd -m $SKEL -p "$CRYPTED" -g $GRPNAME $NAME
215 rm -fr $VZROOT/tmp/$NAME
219 #removing udev family auto start
220 $CHROOT $VZROOT update-rc.d -f udev remove > /dev/null 2>&1
221 $CHROOT $VZROOT update-rc.d -f udev-finish remove > /dev/null 2>&1
223 $CHROOT $VZROOT umount /sys
224 $CHROOT $VZROOT umount /proc
225 #====================================================