Difference between revisions of "OpenVZ VM First Boot Setup Tips"

From Proxmox VE
Jump to navigation Jump to search
(Put to Category Proxmox VE 3.x)
Line 34: Line 34:
  echo ...... and is \"`cat /root/.my.cnf | grep password | cut -d'"' -f 2`\"
  echo ...... and is \"`cat /root/.my.cnf | grep password | cut -d'"' -f 2`\"
[[Category: HOWTO]]
[[Category:Proxmox VE 3.x]]

Latest revision as of 17:18, 13 October 2016

Yellowpin.svg Note: Article about the old stable Proxmox VE 3.x releases

If we copy over a setup script into a VM Template during it's build, we can execute it on first boot up of it's newly created VM and on script completion we can remove the script and hence prevent it from running on subsequent boot ups.


This article lists some useful oneliners especially for building OpenVZ templates using the Debian Appliance Builder.

Here are some bash shell script statements that perform some common tasks that may be used in such a script (the value will be placed in a variable for example VAR and it can be used with ${VAR} in the scripts):

Advanced Bash Scripting Guide

Get the 2.50 MB Free eBook at:


Current IP of the container

MYIP=`ifconfig venet0:0 | grep "inet" | cut -d":" -f 2 | cut -d " " -f 1`

Fully Qualified Domain Name of the container


Generate Random Password

The following will generate a 12 character random password with special characters:

UPASSWD=`openssl rand -base64 12`

The following will generate a 12 character random password without special characters:

UPASSWD=`dd if=/dev/urandom count=200 bs=1 2>/dev/null|tr "\n" " "|sed 's/[^a-zA-Z0-9]//g'|cut -c-12`

Do not use reserved keywords like PASSWD, HOSTNAME, etc., as userland variables, since squeeze does not like bashisms and Debian is progressing to strict dash from lenient bash....

Generate an MD5 hash (lowercase) of a random number

SKEY3=`dd if=/dev/urandom count=2000 bs=1 2>/dev/null|tr "\n" " "|sed 's/[^0-9]//g'|cut -c-32`
UNIQAPPKEY=`echo -n ${SKEY3} | md5sum |cut -d ' ' -f 1`

MySQL Random root Password

echo Current \"root\" password for MySQL is stored in \"/root/.my.cnf\" file
echo ...... and is \"`cat /root/.my.cnf | grep password | cut -d'"' -f 2`\"