Jan 10

Compile error with ‘gcc’

Met with the following gcc error while I was compiling a package from its source.

=======
gcc: error trying to exec 'cc1plus': execvp: No such file or directory
=======

The fix is, you need to install gcc-c++

do

yum install gcc-c++

you are done 🙂

Nov 26

Lost dual boot option and need to reinstall grub

The steps in this post are applicable to be done in distributions like Redhat, Centos and Fedora.

Recently I met with an issue like my personal desktop has lost its Dual Boot option at the startup. The machine has been working by having both Windows XP and Centos present in it. The dual boot option has been lost ever since I reinstalled Windows XP. I was not able to choose Centos at the startup from then, and the machine was automatically booting to Windows XP once I power on the CPU. It was pretty sure that I would probably need to reinstall grub in Centos to bring back the Dual Boot option.

Here you go with the steps I tried to reinstall grub in Centos.

Put in the installation CD you used to install Centos in your machine.
(Before that log into BIOS and set CD/DVD Drive in first place of Boot Priority list)

– Press F10(Save your BIOS change and exit inorder to reboot) and on the reboot cycle, machine would load your Centos disk. That means your Centos disk should be present prior to the booting of machine, otherwise it would try to load the from Harddrive.
– Select “Rescue installed system”.
– Select “Local CDDVD” for the Rescue Method.
– On the “Rescue Screen”, select “Continue”.
– On the next menu screen, select “shell Start shell”.
– I got the shell as “bash-4.1#” successfully.
– Then I tried to run “chroot /mnt/sysimage” and hit the following error.

=====================
chroot: failed to run command `/bin/bash’: No such file or directory
=====================

The above error indicates that either you have put in a different architecture CD that doesn’t match the one installed in your machine. Mine is Centos 6.4 i686 and I was using the same disk used to installed it, so that wasn’t issue here.

Finally I found “chroot /mnt/sysimage” was not working and not shifting me into chroot environment, because “/” and “/boot” partitions were not mounting as well. I had to proceed with manual steps in the following way.

My fdisk -l result is

bash-4.1# fdisk -l
omitting empty partition (5)

Disk /dev/sda: 80.0GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x332cf22a

Device Boot Start End Blocks Id System
/dev/sda1 * 1 2550 20482843+ 7 HPFS/NTFS
/dev/sda2 2551 9728 57657285 f W95 Ext’d (LBA)
/dev/sda3 5738 9728 32057676 7 HPFS/NTFS
/dev/sda5 2551 2576 204800 83 Linux
/dev/sda6 2576 5476 23294976 83 Linux
/dev/sda7 5476 5737 2096128 82 Linux swap / Solaris

/dev/sda6 is my “/” partition and “/dev/sda5” is the “/boot” partition.

I mounted “/” and “/boot” partitions manually and chrooted it.

bash-4.1# mkdir /mnt/ROOT
bash-4.1# mount -t ext4 /dev/sda6 /mnt/ROOT
bash-4.1# mount -t ext4 /dev/sda5 /mnt/ROOT/boot

bash-4.1# chroot /mnt/ROOT
you will be switched to chroot environment >> sh-4.1#

sh-4.1#

I tried to run fdisk -l , but got the below error:

sh-4.1# fdisk -l
cannot open /proc/partitions
sh-4.1#

I exit from the chroot and mounted /proc and /dev using bind method.

sh-4.1# exit
bash-4.1# mount -o bind /proc /mnt/ROOT/proc
bash-4.1# mount -o bind /dev /mnt/ROOT/dev

chroot again

bash-4.1# chroot /mnt/ROOT
sh-4.1# fdisk -l
omitting empty partition (5)

Disk /dev/sda: 80.0GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x332cf22a

Device Boot Start End Blocks Id System
/dev/sda1 * 1 2550 20482843+ 7 HPFS/NTFS
/dev/sda2 2551 9728 57657285 f W95 Ext’d (LBA)
/dev/sda3 5738 9728 32057676 7 HPFS/NTFS
/dev/sda5 2551 2576 204800 83 Linux
/dev/sda6 2576 5476 23294976 83 Linux
/dev/sda7 5476 5737 2096128 82 Linux swap / Solaris
sh-4.1#
sh-4.1#

Now install grub

sh-4.1# grub-install /dev/sda
The file /boot/grub/stage1 not read correctly.

Made me crazy again 🙂
and did it manually from grub prompt.

sh-4.1# grub
Probing devices to guess BIOS drives. This may take a long time.

GNU GRUB version 0.97 (640K lower / 3072K upper memory)

[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename.]

grub> find /boot/grub/stage1
(hd0,5)

grub> root (hd0,5)
Filesystem type is ext2fs, partition type 0x83

grub> setup (hd0)
Checking if “/boot/grub/stage1” exists… yes
Checking if “/boot/grub/stage2” exists… yes
Checking if “/boot/grub/e2fs_stage1_5” exists… yes
Running “embed /boot/grub/e2fs_stage1_5 (hd0)”… 15 sectors are embedded.
succeeded
Running “install /boot/grub/stage1 (hd0) (hd0)1+15 p
(hd0,5)/boot/grub/stage2
/boot/grub/grub.conf”… succeeded
Done.

grub> quit

Make corrections to (hd0,5) in the file /etc/grub.conf or /boot/grub/grub.conf and this is MANDATORY.

sh-4.1# exit
bash-4.1# reboot

Issue has been fixed 🙂

1

2

 

 

 

 

 

 

 

This can also be done using a Live CD with same OS and architecture.

– Boot to CD/DVD Drive
– Select “Rescue Installed System”

You will be shifting to Live CD environment

[root@livecd ~]#

just mount the /boot partition and install grub like as follows:

[root@livecd ~]# mkdir /oldboot
[root@livecd ~]# mount /dev/sda5 /oldboot (/dev/sda5 is my /boot partition here)
[root@livecd ~]#
[root@livecd ~]# grub-install –root-directory=/oldboot /dev/sda
Installation finished. No error reported.
This is the contents of the device map /oldboot/boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install’.

# this device map was generated by anaconda

(fd0) /dev/fd0
(hd0) /dev/sda

3

 

 

 

 

You are done 🙂

Nov 26

Broken grub and getting only grub prompt at the startup

At this case you will get only a grub prompt while at the startup. Please follow the below steps to install grub.

grub> find /boot/grub/stage1
(hd0,5)

(This means the boot loader lies on the first harddisk hd0 and its 5th logical partition)

grub> root (hd0,5)

grub> kernel /boot/vmlinuz-2.6.18-238.19.1.el5.i386 ro root=/dev/sda6

(I gave /dev/sda6 because that is my “/” partition)

or you can as follows.

(check before that if label is already set or not to your root partition. For that boot in with the help of Live CD or be in rescue mode)
####bash-4.1# e2label /dev/sda6
#### /

(so confirmed label is there)

grub> kernel /boot/vmlinuz-2.6.18-238.19.1.el6.i386 ro root=LABEL=/

grub> initrd /boot/initrd-2.6.18-238.19.1.el6.i386.img

grub> boot

That’s it 🙂

Nov 01

Import mails from a non cPanel server

It’s easy for us to import emails over between two cPanel servers, no matter we are migrating 50 or 100 accounts or so, its an easy job to do via WHM or even via backend of cPanel servers. But what if your task to migrate over all emails from a non cPanel server. aahh now you are in trouble!!! 😛

But trust me, you can do that easily with “imapsync”. Following is the command that I did to import mails of email account from a non cpanel.

suppose you want to migrate userx account on server sourceserver.com to userx account on destinationserver.com

====
imapsync –host1 sourceserver.com –user1 userx@domain.net –password1 enterpasshere –host2 destinationserver.com –user2 userx@domain.net –password2 enterpasshere –regexflag “s/\Forwarded//g” –noauthmd5 –syncinternaldates
====

you will see lot of things going on as below in the screen which is a sync process betweeen the two mail servers, wait for a while to complete and then you are done.

============
msg INBOX/208 {34910} copied to INBOX/445
msg INBOX/209 {81261} copied to INBOX/446
msg INBOX/210 {77615} copied to INBOX/447
msg INBOX/211 {10423} copied to INBOX/448
msg INBOX/212 {7092} copied to INBOX/449
msg INBOX/213 {13977} copied to INBOX/450
msg INBOX/214 {57403} copied to INBOX/451
msg INBOX/215 {75258} copied to INBOX/452
msg INBOX/216 {54282} copied to INBOX/453
msg INBOX/217 {77174} copied to INBOX/454
msg INBOX/218 {3298} copied to INBOX/455
msg INBOX/219 {48916} copied to INBOX/456
msg INBOX/220 {19315} copied to INBOX/457
[INBOX.Drafts] -> [INBOX.Drafts]
[INBOX.Junk] -> [INBOX.Junk]
[INBOX.Sent] -> [INBOX.Sent]
[INBOX.Trash] -> [INBOX.Trash]
++++ End looping on each folder
++++ Statistics
Transfer started on : Fri Nov 1 15:47:37 2013
Transfer ended on : Fri Nov 1 15:48:19 2013
Transfer time : 42 sec
Messages transferred : 232
Messages skipped : 0
Messages found duplicate on host1 : 0
Messages found duplicate on host2 : 0
Messages void (noheader) on host1 : 0
Messages void (noheader) on host2 : 0
Messages deleted on host1 : 0
Messages deleted on host2 : 0
Total bytes transferred : 16188117
Total bytes duplicate host1 : 0
Total bytes duplicate host2 : 0
Total bytes skipped : 0
Total bytes error : 0
Message rate : 5.5 messages/s
Average bandwidth rate : 376.4 KiB/s
Reconnections to host1 : 0
Reconnections to host2 : 0
Memory consumption : 115.4 MB
Biggest message : 3019767 bytes
Memory/biggest message ratio : 40.1
Detected 0 errors
============

Before everything you need to ensure imapsync is installed in server. If not just install it using yum.

=====
yum install imapsync
=====

You may require the following perl modules to install in the server.

=====
Mail::IMAPClient 3.34
IO::Socket 1.31
IO::Socket::INET 1.31
IO::Socket::SSL 1.955
Digest::MD5 2.53
Digest::HMAC_MD5 1.01
Term::ReadKey 2.30
Authen::NTLM 1.09
=====

For their installation, just go to cpan prompt and install them one by one.
For eg:

=====
[~]# cpan
cpan> install Mail::IMAPClient
=====

Please note if you are trying to import mails from pop accounts, them imapsync may not work. Such cases you can refer to poptoimap tool. Please read these:

http://www.linux-france.org/prj/pop2imap/pop2imap
http://imapsync.lamiral.info/FAQ

Nov 01

PHP code error : “Fatal error: Call-time pass-by-reference has been removed”

The function reference “&” has already been deprecated in use from php versions over 5.3 and so. You only need to remove the symbol “&” with the function argument.

Suppose if it is like below in the code

array_function(&$files);

make it change to

array_function($files);

Reload the webpage and see…..tadangg 🙂

Oct 30

Mass migration between virtualmin servers

Basically I was new to this virtualmin administration and its interface was really confusing to me. My task was to do a mass domains migration between two centos servers having virtualmin panel installed in it. Following are the steps I did for the server wide migration.

First reduced the TTLs to 5min prior to hours of migration to avoid downtimes while changing the A records.

virtualmin modify-dns –all-domains –ttl 300

Then I created a directory “/root/backups” to store all the domains backup that I generate in the source server.

virtualmin backup-domain –dest /root/backups/ –all-domains –all-features –newformat –all-virtualmin

Copy it over to new server with same directory path “/root/backups” for easiness in use.

rsync -avzrp /root/backups/ root@destip.x.x.x:/root/backups/

if destination server is using any non standard port for ssh, then make some alteration to above rsync command.

rsync -avzrp -e “ssh -p portno” /root/backups/ root@destip.x.x.x:/root/backups/

Restore your domains in destination server.

* virtualmin restore-domain –source /root/backups/virtualmin.tar.gz –all-virtualmin
* virtualmin restore-domain –source /root/backups/ –all-domains –all-features

Set the TTLs back to 4 hours now.

virtualmin modify-dns –all-domains –ttl 14400

You are done 🙂

Reference: http://www.virtualmin.com/documentation/system/migrate
Virtualmin install: http://www.virtualmin.com/download.html

Oct 28

How to extract .jpa archive file? :)

Some clients may approach you with the backup file as .jpa archive(joomlapack) which cannot extract using the usual tools available in server. This can be done by using the third party script Akeeba Extract Wizard.

Download the Akeeba pack from here https://www.akeebabackup.com/download/official/akeeba-kickstart.html

Upload the kickstart zip archive again in public_html or in the same folder where the you have the .jpa archive. Extract the content of the archive. This will put multiple files in the same folder(you see many .ini files of it).

Access the kickstart.php script inside the unzipped kickstart folder via your domain and browser. For example:

http://yourdomain.com/kickstart.php

(should load the correct path where your kickstart.php resides. If it is in a subfolder, load as http://yourdomain.com/subfolder/kickstart.php)

On the kickstart.php loaded on browser, you can browse the .jpa archive file exists in the same folder and go click Extract. You will see the extracted files and folders in the same folder where your kickstart package downloaded 🙂

Oct 27

PHP 5.4 : Strict standards : Non-static methods called statically

I got the following error while loading up a domain running on php 5.4

=======================
Strict Standards: Non-static method JLoader::import() should not be called statically in /home/user/public_html/libraries/joomla/import.php on line 29
Strict Standards: Non-static method JLoader::register() should not be called statically in /home/user/public_html/libraries/joomla/loader.php on line 71
Strict Standards: Non-static method JLoader::import() should not be called statically in /home/user/public_html/libraries/joomla/import.php on line 32
=======================

and I did the below steps to clear them

=======================
In php.ini,
changed error_reporting = E_ALL | E_STRICT to error_reporting = E_ALL & ~E_NOTICE

changed display_errors = On to display_errors = Off
=======================

If the above still doesn’t help you, do the following too.

In the domains index.php file set it like inside the php division.

========
ini_set(‘display_errors’,0);
========

This should fix it 🙂

Oct 08

Legacy filter_module syntax causing 500 error in apache 2.4

Hey, sometimes you may come up with the following error in error log which is actually causing by legacy filter_module syntax on the htaccess file.


======================
[Sun Oct 06 18:20:24.119633 2013] [core:alert] [pid 47884] [client 5.x.x.x:54039] /home/user/public_html/.htaccess: FilterProvider takes three arguments, filter-name provider-name match-expression
[Sun Oct 06 18:20:31.705923 2013] [core:alert] [pid 48315] [client 157.x.x.x:46020] /home/user/public_html/.htaccess: FilterProvider takes three arguments, filter-name provider-name match-expression
[Sun Oct 06 18:20:31.707094 2013] [core:alert] [pid 48315] [client 157.x.x.x:46020] /home/user/public_html/.htaccess: FilterProvider takes three arguments, filter-name provider-name match-expression
======================

Probably the apache version is 2.4 in your server and it wont take the legacy filter_module syntax. You should need to make some changes in it. For example my users filter_module rules were as follows in his .htaccess file.


FilterDeclare COMPRESS
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/html
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/css
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/plain
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/x-component
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/javascript
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/json
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xhtml+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/rss+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/atom+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/vnd.ms-fontobject
FilterProvider COMPRESS DEFLATE resp=Content-Type $image/svg+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $image/x-icon
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/x-font-ttf
FilterProvider COMPRESS DEFLATE resp=Content-Type $font/opentype
FilterChain COMPRESS
FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no

I changed it to


FilterDeclare COMPRESS
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'text/html'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'text/css'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'text/plain'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'text/xml'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'text/x-component'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/javascript'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/json'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/xml'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/xhtml+xml'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/rss+xml'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/atom+xml'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/vnd.ms-fontobject'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'image/svg+xml'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'image/x-icon'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'application/x-font-ttf'"
FilterProvider COMPRESS DEFLATE "%{Content_Type} = 'font/opentype'"
FilterChain COMPRESS
FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no

The error has gone then 🙂

Sep 27

Trim down load in server without killing your current running process.

It’s a fact that while we initiate some cpu or memory consumable process or job, the load in server goes high and sometimes the server become unresponsive. But what if the situation is same everytime especially in case of shared servers. The processess like pkgacct, copying, moving high sized files/folders can’t be ignored at the event of migration or other instances etc. Suppose if we initiate a pkgacct of one account and certainly the load goes high in server, so we may need to cut the pkgacct process we initiated for reducing the load. We can’t always do this whenever server load goes high, because it must be a real headache to initiate, cut, reinitiate etc process manually whenever the load varies in server.

You can do this task with the help of cpuwatch in cPanel servers. Just do the following.

=====
/usr/local/cpanel/bin/cpuwatch 3 /scripts/pkgacct cPanelusername
=====

In the above, whenever the load goes high over 3, the process “/scripts/pkgacct cPanelusername” pauses automatically and resumes as well when the load reduce under 3.