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 "#----------------------------------------------------"
57 #----------------------------------------------------
58 #Prepare /etc/sysconfig/network file
59 #----------------------------------------------------
60 NET="$BASE/$VZLIB/vzdir/$CONTNAME/rootfs/etc/sysconfig/network"
63 echo "HOSTNAME=$NODE.$DOMAIN"
64 echo "GATEWAYDEV=$ETHNAME"
67 #----------------------------------------------------
68 #Prepare /etc/sysconfig/network-scripts/sysconfig-eth* file
69 #----------------------------------------------------
71 ETH="$BASE/$VZLIB/vzdir/$CONTNAME/rootfs/etc/sysconfig/network-scripts/ifcfg"
72 if [ -n $LSTIP ] ; then
73 ETH0=`echo $LSTIP | tr ',' ' ' | cut -d' ' -f1`
79 echo "NETMASK=255.255.255.255"
81 ETHX=`echo $LSTIP | tr ',' ' ' | cut -s -d' ' -f2-`
86 echo "DEVICE=eth0:$aliasnum"
90 echo "NETMASK=255.255.255.255"
91 ) > $ETH-eth0:$aliasnum
92 let aliasnum=aliasnum+1
95 #----------------------------------------------------
96 #Prepare /dev directoy contents
97 #----------------------------------------------------
102 mknod -m 666 $DEV/null c 1 3
103 mknod -m 666 $DEV/zero c 1 5
104 mknod -m 666 $DEV/random c 1 8
105 mknod -m 666 $DEV/urandom c 1 9
106 mkdir -m 755 $DEV/pts
107 mkdir -m 1777 $DEV/shm
108 mknod -m 666 $DEV/tty c 5 0
109 mknod -m 600 $DEV/console p
110 mknod -m 666 $DEV/tty0 c 4 0
111 mknod -m 666 $DEV/full c 1 7
112 mknod -m 600 $DEV/initctl p
113 mknod -m 666 $DEV/ptmx c 5 2
115 #----------------------------------------------------
116 #Prepare /dev directoy fstab
117 #----------------------------------------------------
118 FSTAB="$VZROOT/etc/fstab"
120 echo -e "/vzgot\t\t/\t\text3\tdefaults\t0 0"
121 echo -e "proc\t\t/proc\t\tproc\tdefaults\t0 0"
122 echo -e "sysfs\t\t/sys\t\tsysfs\tdefaults\t0 0"
123 echo -e "devpts\t\t/dev/pts\t\tdevpts\tdefaults\t0 0"
124 echo -e "tmpfs\t\t/dev/shm\t\ttmpfs\tdefaults\t0 0"
127 #====================================================
128 #starting common container configuration process
132 #----------------------------------------------------
133 #insert a common root password within the vz
135 if [ -f etc/shadow ] ; then
136 SHAD="$VZROOT/etc/shadow"
137 sed 's/#.*//g' etc/shadow | grep -v '^[[:space:]]*$' | \
140 NAME=`echo $LINE | cut -d':' -f1`
141 (echo $LINE ; grep -v "^$NAME:" $SHAD) > $SHAD.new
142 mv -f $SHAD.new $SHAD
147 #setting the DNS resolver
148 if [ -f etc/resolv.conf ] ; then
149 cp -a etc/resolv.conf $VZROOT/etc
152 #duplicating ssh Key if we want to have all container even.
153 if [ -d etc/ssh ] ; then
154 for i in `ls etc/ssh/*key* 2> /dev/null`
156 cp -a $k $VZROOT/etc/ssh
160 #insert iptables script
161 if [ -f etc/sysconfig/iptables ] ; then
162 cp -a etc/sysconfig/iptables $VZROOT/etc/sysconfig
165 #adding sudoer informations
166 if [ -f etc/sudoers ] ; then
167 cat etc/sudoers >> $VZROOT/etc/sudoers
170 #adding snmpd.conf specific to ALL container
171 if [ -f etc/snmp/snmpd.conf ] ; then
172 cat etc/snmp/snmpd.conf>> $VZROOT/etc/snmp/snmpd.conf
176 #end common container configuration process
177 #====================================================
178 #lets create common users and groups
179 ARCH=`cat $VZLIB/vzdir/$CONTNAME/arch`
180 CHROOT="/usr/bin/setarch $ARCH /usr/sbin/chroot"
182 $CHROOT $VZROOT mount -t proc proc /proc
183 $CHROOT $VZROOT mount -t sysfs sysfs /sys
185 #creating common group
186 if [ -f $VZLIB/etc/groups ] ; then
187 sed 's/#.*//g' $VZLIB/etc/groups | grep -v '^[[:space:]]*$' | \
188 while read -r GRPNAME
190 $CHROOT $VZROOT groupadd $GRPNAME
194 #creating common users
195 if [ -f $VZLIB/etc/users ] ; then
196 sed 's/#.*//g' $VZLIB/etc/users | grep -v '^[[:space:]]*$' | \
197 while read -r NAME CRYPTED GRPNAME
199 if [ -d $VZLIB/home/$NAME ] ; then
200 cp -a $VZLIB/home/$NAME $VZROOT/tmp
203 $CHROOT $VZROOT useradd -m $SKEL -p "$CRYPTED" -g $GRPNAME $NAME
204 rm -fr $VZROOT/tmp/$NAME
208 #removing udev family auto start
209 UDEV="/sbin/start_udev"
210 $CHROOT $VZROOT /bin/mv $UDEV $UDEV.org > /dev/null 2>&1
211 $CHROOT $VZROOT /bin/ln /bin/true $UDEV > /dev/null 2>&1
213 $CHROOT $VZROOT umount /sys
214 $CHROOT $VZROOT umount /proc
215 #====================================================