Riz Khan on March 14th, 2011


Virtouzzo provides a shell utility named ‘vzmlocal‘ , it can be used to clone a vps and comes handy in many situations.

There are multiple reasons for which you may want o clone a vps, like :

  • clone a vps before doing any major installation or changes within vps, so it can be reverted back in case something goes wrong
  • clone a vps or vps template to create a new vps with same OS and applications, e.g. a clone for cPanel vps template to create a new cPanel vps
  • to create a exact replica of a vps to be used as redundant copy of the vps

Lets see how we can use this command to create a vps clone :


above is general syntax , a real time example would be :

vzmlocal -C 145:245
Moving/copying Container#145 -> Container#245, [], [] ...
Syncing private area '/vz/private/145'->'/vz/private/245'
Successfully completed

The above command will create the exact replica of VPS with id 145 into a new VPS who’s id will be 245.

Additional parameters can be used as per requirement , some of the command parameters are below :

  • -s, –fast-sid     :     allows to speed up cloning process
  • -d, –destroy-source   :   destroys the source container after making a clone
  • -l, –skiplock    :   allows to clone the locked containers

You can check the command help for complete options.


Tags: , , , ,

Riz Khan on March 10th, 2011

fsck stands for File System Check and it is a disk repair utility used in Unix and Linux  based operating systems.

Normally fsck is started automatically at boot time if some file system inconsistency is identified. However System Administrators can issue a manual fsck as well if they notice any issues on the running system. It is always performed after unmounting the related server partition and in most cases in single user mode, unless it a partition which can be unmounted on a running system.

This article cover the ways we can set fsck to start automatically at reboot, irrespective of the server detecting a file system inconstancy or not.

First method you can use to achieve this is by creating a file under root file system / , you can do this by using following command :

touch /forcefsck

Then reboot the system :

or you can use the shutdown command with -r flag , which is what ‘reboot‘ command calls as well in background.

The second method is more simple and just requires the use of an additional argument -F to force fsck , you can do this by using below command :
shutdown -rF now

shutdown -r now is the normal command used for server reboot and adding -F ensures that a forced file system check ( fsck ) will be performed on the server.

Tags: , , ,

Riz Khan on February 28th, 2011

As part of their work, system administrators and technicians come across many instances where they have to replace some specific text in scripts or files on server.

sed , which stands for stream editor is an excellent utility/language for string editing. Its very powerful and can be used to do many complex string replacements that might not be possible with other simpler utilities like ‘replace‘ command in linux, however sed has some steep learning curve as well which is worth the benefits it provide.

In this post I will mention the simple text replacement sed command.

The basic syntax for the command is below :

sed -i 's/stringtomatch/stringtoreplace/g' targetfile

This command will replace ‘stringtomatch’ with ‘stringtoreplace’ in this case.  The -i or –in-place argument do the inplace editing to the original file and if you mention an extension it will create a backup file before doing the change. It would look like below :

sed -i".bak" 's/stringtomatch/stringtoreplace/g' targetfile

In this case a backup files named targetfile.bak will be created , before the string replacement is done to the original files named ‘targetfile’ in this case.

If we do not use the -i argument then no changes are made to the original file, but you can redirect the output to a second file, that would take the below form :

sed 's/stringtomatch/stringtoreplace/g' targetfile > newfilewithchages.txt

In this case the original targetfile will not get modified, rather they will be replacement in the other file where output is redirected, ‘newfilewithchanges.txt’ in this case.

If you have to do more than one string replacement in one command then -e or –expression argument can be used and multiple string replacement arguments can be supplied to make changes to the same file.

The command can take multiple expression and multiple input files, for complete synax check help for sed command.

Tags: , , , ,

Riz Khan on February 27th, 2011

3ware raid controller along with Adaptec and LSI are among the more      popular Raid controllers.  If you do have have right configurations you  will not get the performance you are looking for, even after spending  reasonable amount of money on these expensive controllers.

If you have write cache disabled on a 3ware raid controller , you may see very degraded performance for the raid array and enabling the cache can improve the performance reasonably. Though it is recommended that if you enable the write cache you must have battery backup for your Raid controller, else there could be chance for some data loss from the cache in case of an unexpected server outage. However battery backups add some more costs to the controller and many small operations may not able to afford them, so many admins still enable the write cache to gain the major performance benefits compared to small risk of possible data loss.

And practically for Raid10, I have not seen any major issues with write cache enabled for 3ware raid controllers without battery backups, so the trade-off is not that bad idea in this case, though it also depends on kind of operation you are running and how critical data you are hosting on the server.

You can check the current cache status and then enable or disable it using the 3ware command line utility tw_cli. First lets see how we can check the current status :

root@centos [~]# tw_cli info c0

Unit UnitType Status %RCmpl %V/I/M Stripe Size(GB) Cache AVrfy
u0 RAID-10 OK - - 64K 465.641 OFF OFF
Port Status Unit Size Blocks Serial
p0 OK u0 466.76 GB 490234752 WD-WCANKXXXXX34
p1 OK u0 466.76 GB 490234752 WD-WCANKXXXXX57
p2 OK u0 466.76 GB 490234752 WD-WCANKXXXXX82
p3 OK u0 466.76 GB 490234752 WD-WCANKXXXXX18

root@centos [~]#

As you can see in this case , its a Raid10 array and the write cache is set to OFF i.e. disabled.

Now to enable it, you need to note the controller and unit number so then it can enabled accordingly, in above case our command to enable write cache would be :

tw_cli set cache c0 u0 on

And below is a real time example on how it should look like for a successful operation :

root@centos [~]# tw_cli set cache c0 u0 on
Setting Write Cache Policy on /c0/u0 to [on] ... Done.

root@centos [~]#

Now lets check the status of the raid array again.

root@centos [~]# tw_cli info c0
Unit UnitType Status %RCmpl %V/I/M Stripe Size(GB) Cache AVrfy
u0 RAID-10 OK - - 64K 465.641 ON OFF
Port Status Unit Size Blocks Serial
p0 OK u0 466.76 GB 490234752 WD-WCANKXXXXX34
p1 OK u0 466.76 GB 490234752 WD-WCANKXXXXX57
p2 OK u0 466.76 GB 490234752 WD-WCANKXXXXX82
p3 OK u0 466.76 GB 490234752 WD-WCANKXXXXX18

root@centos [~]#

As you can see the write cache is enabled now, similarly you can disable the write cache using below command :

tw_cli set cache c0 u0 off

Now you know how to check and enable the write cache for 3ware raid controller, so go a head and try it on your server if you are not already using it, and you will see a good performance improvement.

Tags: , ,

Riz Khan on February 27th, 2011

MySQL database server has tbe capability to use different database storage engines. The database storage engine is what actually do the work of storing and retrieving data from the underlying database tables.

The storage engines work like a modular code which can be plugged into MySQL. Among the stroage enginers MyISAM is the one, used most widely and also the default storage engine for MySQL. However it do lack some high level functionalities which are requirement for any enterprise level database server e.g. it do not have proper support for transaction or foreign key.

This is where InnoDB storage engine comes into play, InnDB is a trasanction safe storage engine with support for foreign keys along with commit, rollbak and crash recovery capabilties.

InnoDB is a product of Innobase Oy, which a Finnish company now owned by Oracle. MySQL has a licensing agreement with Innobase Oy which allows it to provide the InnoDB.

As we have covered some InnoDb background lets take a look at main ‘how to’ topic , i.e. how we can check if the MySQL server we are running has InnDB support enabled or not.

There is a MySQL system variable have_inndb and its value can be checked to see if the support enabled or not. You can do this by using following command :

mysqladmin variables | grep have_innodb

If this returns YES then it means that the InnoDB support is enabled. If you have ‘–skip-innodb’ in your /etc/my.cnf MySQL configuration file then InnoDB engine would be disabled. And in that case you can comment out this option to enable InnoDB. It is enabled by default and unless there is some related disable configuration added to my.cnf configuration, there should be no issues.

Also if you would like to use InnoDB as the default storage engine, you can do that by using below cofiguration in /etc/my.cnf :


But make sure to do your homework before setting the storage engine, it do have performance benefits over MyISAM once its configured properly, but do have higher administrative cost. InnoDB can be configured to have per table innodb file, which do help in isolating any individual database corruptions. I will cover that in some other post soon.


Tags: , , , , ,

MySQL is one of most known and popular open source database engine. It helps application owners to run their applications or sites on a reliable platform in a cost affective way.

I have been thinking from some time to do some write up on Mysql Optimization as I have found that many people keep running the stock form of Mysql service and they are missing the great benefits they can achieve by doing some extra effort and Optimizing Mysql according to their server/vps or application behavior and usage.

The first main area for optimization is good usage of Mysql Variables and adjusting their values to gain performance. Secondly slow query logging is another major area for Mysql Optimization and thus achieving lower loads on your servers. I wrote about enabling slow query logging in one of my earlier post here , you can check it to see the steps for enabling slow query logging. Thirdly the use of some tuning application/scripts that help tune settings for your Mysql instance by findings the highest resource consuming users and queries.

I came across a video by Dani Wallace from cPanel few weeks back which was specifically prepared on Mysql Optimization and it covered most of the areas I was looking to explain, in such a good and comprehensive way, that I changed my mind to write a lengthy write up myself and instead to link the video here, a video presentation helps getting a good grasp on the topic.

The video discusses following areas :

  • Introduction :  i.e what exactly is Mysql Optimization and why one should do it
  • Default Settings :  default setup of /etc/my.cnf configuration file and desc of those variables
  • Mysql Variables : commands to check the variables and introduction to common variables
  • Logging : Type of logging and its role in Optimization
  • Monitoring : Commands and tools ideal for monitoring Mysql activity
  • Templates : Introduction and opinion about templates provided by Mysql
  • Diagnostic Tools : Tools to diagnose users/queries taking highest resources to help tune and optimize Mysql accordingly
  • Test Results : Some test results of performing Optimization based on different tools and improving server performance by reducing server loads

I will do another write up for installation and usage of all Diagnostic tools soon.

Tags: , , ,