2 #----------------------------------------------------
3 #shell used to create the root file system for the
4 #container, incoming file is a tar file to
5 #insert within the vzgot directory structure
7 #----------------------------------------------------
9 #vzgot.create VE_name tpl_tar_filename dist arch base_dir
10 # VE_name is the container dir name
11 # tpl_tar_filename is the template file name to be used
12 # dist is the distribution name (fc12, rh7.3, el5.4, etc...)
13 # arch is the architecture base (i386, x86_64)
14 # base_dir is this application root directory
15 # used for devel only.
16 #----------------------------------------------------
23 #-------------------------------------------------------------------
31 #----------------------------------------------------
32 #default GETAR value, during the container create
33 #CAN BE overriden within /etc/vzgot/vzgot_config
34 #if your template are somewhere else
35 GETAR="cat /var/lib/vzgot/vztemplate/$TARFILE"
36 #----------------------------------------------------
37 if ! [ -f $BASE/etc/vzgot/vzgot_config ] ; then
38 abort "Missing vzgot config file"
40 . $BASE/etc/vzgot/vzgot_config
42 #specific container configuration override (if needed)
43 if [ -f $BASE/$VZLIB/vzdir/$CONTNAME/vzgot_config ] ; then
44 $BASE/$VZLIB/vzdir/$CONTNAME/vzgot_config
46 #----------------------------------------------------
47 if [ -d $BASE/$VZLIB/vzdir/$CONTNAME ] ; then
48 echo "Container $CONTNAME already existing, must be destroyed first"
49 abort "Use command \"vzgot destroy $CONTNAME\" to do it"
52 #----------------------------------------------------
53 #creating Container directory
54 mkdir -p $BASE/$VZLIB/vzdir/$CONTNAME
55 if [ ! -z "$LVM" ] ; then
56 if [ -z "$LVM_SIZE" ] ; then
59 VZCONTNAME=`echo $CONTNAME | sed 's/\.//g' | sed 's/-//g'`
60 lvcreate -L$LVM_SIZE -n$VZCONTNAME $LVM > /dev/null 2>&1
62 if [ $ret -ne 0 ]; then
63 abort "vzgot.create, unable to create LVM $VZCONTNAME on volume $LVM"
65 mke2fs -q -t ext4 -j -L$VZCONTNAME /dev/$LVM/$VZCONTNAME
67 if [ $ret -ne 0 ]; then
68 abort "vzgot.create, unable to format LVM $VZCONTNAME with mke2fs"
70 mount /dev/$LVM/$VZCONTNAME $BASE/$VZLIB/vzdir/$CONTNAME
72 if [ $ret -ne 0 ]; then
73 abort "vzgot.create, unable to mount LVM $VZCONTNAME on BASE/$VZLIB/vzdir/$CONTNAME"
75 echo -e "/dev/$LVM/$VZCONTNAME\t$BASE/$VZLIB/vzdir/$CONTNAME\text4\tdefaults\t0 0" >> /etc/fstab
77 mkdir -p $BASE/$VZLIB/vzdir/$CONTNAME/rootfs
80 $GETAR | tar zxCf $BASE/$VZLIB/vzdir/$CONTNAME/rootfs -
82 if [ $ret -ne 0 ]; then
83 abort "vzgot.create, Unable to install template file $TPL!"
85 #----------------------------------------------------
86 #duplicating cgroup HOST setting (the limits you
87 #want to be set to all created container)
88 cp -ap $BASE/$VZLIB/cgroup.d $BASE/$VZLIB/vzdir/$CONTNAME
89 #----------------------------------------------------
90 #setting the container architecture
91 echo $ARCH > $BASE/$VZLIB/vzdir/$CONTNAME/arch
92 #setting the container distribution
93 echo $DIST > $BASE/$VZLIB/vzdir/$CONTNAME/dist
94 #----------------------------------------------------
96 rm -fr $BASE/$VZLIB/vzdir/$CONTNAME/rootfs/etc/mtab*
97 #----------------------------------------------------
98 #specific configuration according distribution
101 #setting variable LD_ASSUME_KERNEL to help RPM utility
102 export ENVRPM="LD_ASSUME_KERNEL=2.4.1"
103 echo "export $ENVRPM" >> $BASE/$VZLIB/vzdir/$CONTNAME/rootfs/etc/bashrc
108 #----------------------------------------------------
109 #installing needed RPM
110 if [ -d $BASE/$VZLIB/RPM/RPMS/$ARCH/$DIST ] ; then
112 #do we have specific rpm to add to template
113 cd $BASE/$VZLIB/RPM/RPMS/$ARCH/$DIST
114 num=`ls -1 *.rpm | wc -l`
115 if [ $num -ge 1 ] ; then
117 VZROOT=$BASE/$VZLIB/vzdir/$CONTNAME/rootfs
118 CHROOT="/usr/bin/setarch $ARCH /usr/sbin/chroot"
120 mkdir $VZROOT/tmp/rpm
121 cp *.rpm $VZROOT/tmp/rpm
122 $CHROOT $VZROOT mount -t proc proc /proc
123 $CHROOT $VZROOT mount -t sysfs sysfs /sys
124 $CHROOT $VZROOT /bin/bash -c "$ENVRPM rpm -U --quiet tmp/rpm/*.rpm"
125 $CHROOT $VZROOT umount /sys
126 $CHROOT $VZROOT umount /proc
130 #----------------------------------------------------