Howto Recover a Linux Partition after a Superblock corruption?

March 31, 2012    |   Posted by admin   |    Category: Linux Administration

A SuperBlock in Linux saves information about the File System like, the File System type, size, status etc. A File system cannot be mounted if a Superblock is corrupted.  Corruption of superblock can occur due to various reasons like, abnormal shutdown due to power failure, virus infection, file system corruption etc.

When a Superblock is corrupted, you receive a ” can’t read superblock” error message while accessing the File System. For example, if you try to access a Linux ext3 partition say, /dev/sda3, you will receive the following message:

/dev/sda3: Input/output error
mount: /dev/sda3: can’t read superblock

Linux ext3 file system automatically maintains a backup of superblock at various locations. In cases such as these, you have to restore a superblock from an alternate  backup location to retrieve the data.

Note: You should unmount the partition before performing this task.

First, find / list the superblock locations of the file system /dev/sda3 (we are using sda3 as an example, your partition may be different)

# dumpe2fs /dev/sda3 | grep superblock
 dumpe2fs 1.39 (29-May-2006)
 Primary superblock at 1, Group descriptors at 2-2
 Backup superblock at 8193, Group descriptors at 8194-8194
 Backup superblock at 24577, Group descriptors at 24578-24578
 Backup superblock at 40961, Group descriptors at 40962-40962
 Backup superblock at 57345, Group descriptors at 57346-57346
 Backup superblock at 73729, Group descriptors at 73730-73730

Now, check and repair (fsck) the file system with an alternate superblock #24577. BTW, try superblock from another location if one doesn’t work.

# fsck -b 24577 /dev/sda3
 fsck 1.39 (29-May-2006)
 e2fsck 1.39 (29-May-2006)
 /dev/sda3 was not cleanly unmounted, check forced.
 Pass 1: Checking inodes, blocks, and sizes
 Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
 Free blocks count wrong for group #0 (3553, counted=513).
 Fix<y>? yes
Free blocks count wrong for group #1 (7681, counted=5059).
 Fix<y>? yes
Free blocks count wrong for group #19 (7939, counted=7697).
 Fix<y>? yes
/boot: ***** FILE SYSTEM WAS MODIFIED *****
 /boot: 35/50200 files (8.6% non-contiguous), 17906/200780 blocks

Now, mount the partition once the file system check is over:

# mount /dev/sda3 /mnt

Once the partition is mounted, you can retrieve the files from /mnt:

# mkdir backup
# cd /mnt
# cp filename /backup/

BTW, it is always good to keep a backup of your data instead of finding yourself in such situations.

Comments Off on Howto Recover a Linux Partition after a Superblock corruption?

Mysql failed after upgrade: Table ‘mysql.plugin’ doesn’t exist

March 24, 2012    |   Posted by admin   |    Category: Mysql & PostGres SQL

After performing a mysql upgrade, you may run into a problem where Mysql won’t start successfully and will result in a “Table ‘mysql.plugin’ doesn’t exist” error message. The mysql error logs will state something like follows:

/usr/libexec/mysqld: Table 'mysql.plugin' doesn't exist
110620  01:01:01 [ERROR] Can't open the mysql.plugin table.
Please run mysql_upgrade to create it.

The solution is to run mysql_upgrade to create the mysql.plugin table but the problem is you can execute the command only when Mysql is online. Tricky situation, isn’t it?

This mostly likely happens when mysql is still using the old my.cnf file after the upgrade. The my.cnf of the new Mysql version is saved as /etc/my.cnf.rpmnew and this is the file you should be using

# cp /etc/my.cnf /etc/my.cnf.old
# cp /etc/my.cnf.rpmnew /etc/my.cnf
# /etc/init.d/mysqld start

Once Mysql is started, you can now execute mysql_upgrade:

# mysql_upgrade -uroot -p <mysqlpass>

This will create the ‘mysql.plugin’ table and will make sure the mysql database is uptodate as per the newer version.

Comments Off on Mysql failed after upgrade: Table ‘mysql.plugin’ doesn’t exist

CSF Installation failed: LWP perl module (libwww-perl) missing

March 19, 2012    |   Posted by admin   |    Category: Linux Administration

While installaing CSF firewall on a plain Linux server, you may notice the “LWP perl module” missing error message:

# sh install.sh
 Configuring for OS
 Checking for perl modules failed
 You need to install the LWP perl module (libwww-perl) and then
 install csf

The problem mostly occurs on a plain Linux server where all perl modules are not installed during the OS installation. On servers with control panels, this issue won’t arise.

The fix is to install the libwww-perl module either with YUM OR from cpan prompt.

# yum install perl-libwww-perl

OR goto the cpan prompt and install

# cpan
cpan> install Bundle::LWP [Installing LWP]

Once done, CSF firewall will be installed successfully.

Comments Off on CSF Installation failed: LWP perl module (libwww-perl) missing

How to Enable Remote Access to Mysql database server?

March 13, 2012    |   Posted by admin   |    Category: Mysql & PostGres SQL

By default, Mysql doesn’t allow remote connections for security reasons. However, sometimes you or your client may want to acess the database remotely i.e. from a different server Or from home Or a developer who is working on the website.

To grant remote access to a Mysql databas, the first thing is to make sure ‘skip-networking’ is not enabled in Mysql configuration i.e. in the my.cnf file.

On a CentOS/RHEL server, the file is located at /etc/my.cnf
On a Debian/Ubuntu server, the file is located at /etc/mysql/my.cnf

1) SSH to the server and comment/remove the line from my.cnf that says:

skip-networking

where,
        skip-networking means don’t listen on TCP/IP connections but only from Unix sockets. This is recommended on systems where only local connections are allowed. However, as you need to allow remote connections, skip-networking must be removed/commented in my.cnf as stated above.

2) Save the file and restart the mysql service

# /etc/init.d/mysqld restart

3) Connect to the Mysql server to grant access to a remote IP address.

# mysql -uroot -p

4) Now, for example, if you want to allow access to database ‘db_name’ for user ‘db_user’ and the remote IP is 1.1.1.1, the mysql command should be as follows:

mysql> use mysql
mysql> GRANT ALL ON db_name.* TO 'db_user'@'1.1.1.1' IDENTIFIED\
BY 'PASSWORD';

If your IP is NOT static and you want to grant access to the database from any IP, use % instead of IP, i.e.

mysql> GRANT ALL ON db_name.* TO 'db_user'@'%' IDENTIFIED\
BY 'PASSWORD';

5) Logout of Mysql and make sure port 3306 is open in your server firewall. Test the remote mysql connection from your local computer Or a different server:

# mysql -u db_user -h serverIP -D db_name -p

where,
        -u db-user: db_user is the database username.
        -h serverIP: ServerIP is the IP of your mysql server.
        -D db_name: db_name is the database name
        -p: password of the database user

Comments Off on How to Enable Remote Access to Mysql database server?

How to migrate a Mysql database/table from one server to another?

March 3, 2012    |   Posted by admin   |    Category: Mysql & PostGres SQL

The easiest way to transfer a Mysql database from one server to another is by creating a backup, copy the mysql database backup to another server and restore it on the remote server.

The first thing is to create a backup of the mysql database using mysqldump. It creates a backup in the .sql format. You have to use your SSH user/password while backup/restore of database.

To backup a specific database:

# mysqldump -u root -p db_name > db_name.sql

To backup a specific Mysql table:

# mysqldump -u root -p db_name tb_name > tb_name.sql

Copy the database/table backups to the remote server using SCP (ssh):

# scp db_name.sql root@remote_server_ip:/backup/
# scp tb_name.sql root@remote_server_ip:/backup/

Login to the remote server and restore the .sql file. You should be in the backup directory while restoring

# mysql -u root -p db_name < db_name.sql
# mysql -u root -p db_name < tb_name.sql

On a cPanel server, the mysql user is ‘root’ and the mysql password.
On a Plesk server the mysql user is ‘admin’ and the Plesk admin password.