Online resize LVM partitions – shrink home / extend root

By default, most Linux Installers create separate /home partition, occupying most of the drive space.
When server is used mostly for system services, you may transfer free space from /home partition to /root.

Before adjustment we have 98% filled root partition and 141GB free space on /home, which we would like to use:
[code]
[root@oracle ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_oracle-lv_root
50G 1G 50G 98% /
tmpfs 630M 0 630M 0% /dev/shm
/dev/cciss/c0d0p1 477M 106M 346M 24% /boot
/dev/mapper/vg_oracle-lv_home
149G 60M 141G 1% /home
[/code]

1. First step is to unmount /home partition
[code]
umount /home
[/code]
System may refuse to unmount /home if you have users logged on to the box or services running from /home. After logging off / stopping services command should succeed.

2. Shrink old /home partition to 20GB, (system will force you to check filesystem for errors by running e2fsck)
[code]
e2fsck -f /dev/mapper/vg_oracle-lv_home
resize2fs /dev/mapper/vg_oracle-lv_home 20G
[/code]

3. Reduce the LVM to 20G
[code]
lvreduce -L 20G /dev/mapper/vg_oracle-lv_home
[/code]

4. Extend /root LVM to new size, utilizing 100% of free space on disk
[code]
lvextend -l +100%FREE /dev/mapper/vg_oracle-lv_root
[/code]

5. Grow /root (ext3/4) partition to new LVM size
[code]
resize2fs /dev/mapper/vg_oracle-lv_root
[/code]

6. Mount /home
[code]
mount /home
[/code]

Result
[code]
[root@oracle ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_oracle-lv_root
178G 50G 128G 28% /
tmpfs 630M 0 630M 0% /dev/shm
/dev/cciss/c0d0p1 477M 106M 346M 24% /boot
/dev/mapper/vg_oracle-lv_home
20G 45M 19G 1% /home

[/code]

After these simple steps we have 72% of free disk space of root partition.

TL;DR

Resizing /home partition (/dev/mapper/vg_oracle-lv_home) to 20GB and transfering remaining space to /root (/dev/mapper/vg_oracle-lv_root):

[code]
umount /home
e2fsck -f /dev/mapper/vg_oracle-lv_home
resize2fs /dev/mapper/vg_oracle-lv_home 20G
lvreduce -L 20G /dev/mapper/vg_oracle-lv_home
lvextend -l +100%FREE /dev/mapper/vg_oracle-lv_root
resize2fs /dev/mapper/vg_oracle-lv_root
mount /home
[/code]

Apache error 500 after PHP upgrade

When upgrading your server from old PHP release to 5.4 make sure your application does not use deprecated functions such as session_register.
This function may be used in older CMS versions, as Tiger CMS.

To comment out all occurrences of incompatible functions in the code you can use following command:
Example for session_register:

[code]
find . -type f -exec sed -i ‘s/session_register/\/\/session_register/g’ {} \;
[/code]

Generic troubleshooting steps for error 500 in Apache:

1. Check Apache error log
/var/log/apache2/error.log

2. Turn on PHP Error reporting in etc/php.ini (/etc/php5/apache2/php.ini)
[code]
error_reporting(E_ALL);
[/code]

3. Create an info.php file to test php, with content:

[code]

[/code]

So you can see what version you use and if it is loaded correctly.

Good Luck!

Automating tasks with cron on CheckPoint Gaia

To use cron on CheckPoint Gaia firewall you need to create a separate user, as “admin” user crontab file is overwritten on every reboot by /bin/cron_xlate.

Instead of using default command :
> crontab -e
It will warn you as follows:
[code]
# This file was AUTOMATICALLY GENERATED
# Generated by /bin/cron_xlate on Wed Jan 14 13:33:33 2015
#
# DO NOT EDIT
#
SHELL=/bin/bash
MAILTO=””
#
# mins hrs daysinm months daysinw command
#
[/code]

You will also need to specify the user:

> crontab -u cron_user -e

To create a new user for cron, use following commands:

[code]
add user cron_user uid 0 homedir /home/cron_user
set user cron_user gid 100 shell /bin/bash
add rba user cron_user roles adminRole
set user cron_user password
[/code]

Make sure you use new user’s home folder for output in your scripts, to avoid issues with permissions.