Initializing a new instance of Linux

After a fresh install of Linux, there are a number of tasks I like to do. I like having commands and aliases that I am used to installed.

Copy /opt/scripts

Create /opt/sw

/opt/scripts/stopUnusedServices.sh

set up MySQL

Install WebMin and VirtualMin for managing your domain names and their.

Starting a user’s VNC server automatically on Linux

On some Linux systems, it can be advantageous for users to have a way to login to a console. Unfortunately, if they do not have physical access to the machine, there needs to be a way to do it remotely. Fortunately on Linux, there is Virtual Network Computing (VNC). VNC can be set up as a server and I will outline the steps necessary to complete this task.

First, ensure that vncserver is installed on your system. For Red Hat systems type:

>yum list vnc-server

If you see the following message:

Loaded plugins: rhnplugin
Error: No matching Packages to list

You will  need to install vncserver. Using Yum again:

>yum -y install vnc-server

We can now begin configuring VNC. We are going to do this for two users, root and myuser. Each user will access their virtual desktop from separate Internet Protocol ports. Vtxinst will use port 5801 and root will use port 5802.

We first need to edit /etc/sysconfig/vncservers. On line that has

# VNCSERVERS=”2:myusername”

Change it to

VNCSERVERS=”1:myuser 2:root”

Save the file. Now we need to prime VNC to setup its supporting files correctly. Login first as root, then myuser and issue the following command:

>vncserver

You will be prompted for a password if this is the first time this user has started VNC. Then run the following command to stop vncserver:

>vncserver -kill :1

Next let’s edit the user’s ~/.vnc/xstartup so that we use the gnome desktop instead of X windows. In the user’s directory, edit the file ~/.vnc/xstartup and uncomment the following 2 lines by removing the # so that the two lines look like the following:

unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc

Finally, enable vncserver on startup with the following command:

>chkconfig –levels 35 vncserver on

Now, next time you reboot, VNC server will start automatically. If you don’t want to reboot, then run:

>service vncserver start

And VNC server will now be running!

Auto commit for MySQL databases

In corporate database systems, it is generally preferred to build transaction stacks. This allows for having multiple database statements run and be finally committed if everything is ok. In MySQL, auto commit is on by default; which means that every statement is instantly committed. To check the value of auto commit, run the following MySQL command:

mysql>select @@autocommit;

So in order to turn off auto commit, run the following command in MySQL:

mysql>SET autocommit=0

If you want auto commit turned off permanently, we need to edit your my.cnf file. In the [mysqld], add the following line:

init_connect='SET autocommit=0'

Restart MySQL and you are now ready to do full transaction processing.

Error in /etc/fstab stopping Linux boot

In Linux, there are times when you need to edit your /etc/fstab file to add a new disk. Sometimes, you may accidentally edit the wrong information which will cause Linux to not boot. Usually though, Linux plays nice and boots to a command prompt. Unfortunately, you are now booted into a read-only filesystem so you are unable to save your /etc/fstab.

What you need to do is first set the operating system to read/write (r/w). To do this run the following command:

>mount -o remount,rw /

If /etc is on a different volume, then run this command (replace /dev/sda1 with your /etc volume):

>mount -t ext3 /dev/sda1 / -o remount,rw

Some people have complained about kernels that are not compiled to support the reldiratime option. If you are still having trouble editing and saving /etc/fstab, try this:

>mount -o remount,defaults /

You should now be able to edit and save your /etc/fstab file and reboot and have Linux back again!