Centos 7 systemctl tips and tricks

1. List all services enabled/disabled on boot (ex chkconfig –list)

systemctl list-unit-files

2. Enable HTTPD + Mysql service on system boot:

systemctl enable httpd
systemctl enable mariadb

3. Reverting to iptables from firewalld

systemctl stop firewalld
systemctl mask firewalld

yum install iptables-services

systemctl enable iptables
systemctl start iptables

# to save iptables rules use
service iptables save

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:

[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

1. First step is to unmount /home partition

umount /home

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)

e2fsck -f /dev/mapper/vg_oracle-lv_home
resize2fs /dev/mapper/vg_oracle-lv_home 20G

3. Reduce the LVM to 20G

lvreduce -L 20G /dev/mapper/vg_oracle-lv_home

4. Extend /root LVM to new size, utilizing 100% of free space on disk

lvextend -l +100%FREE /dev/mapper/vg_oracle-lv_root

5. Grow /root (ext3/4) partition to new LVM size

resize2fs /dev/mapper/vg_oracle-lv_root

6. Mount /home

mount /home

Result

[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

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):

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

PHP exec system calls not working in Debian 6

After migrating Current website to Debian 6, PHP calls exec and system stopped working.
The reason for it is debian package dash which modifies behaviour of system default shell:

# ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Dec  9 20:25 /bin/sh -> dash

To revert this this behaviour to standard, execute

# dpkg-reconfigure dash

dash dpkg-reconfigure debian linux

Select “No” and default shell will be changed to standard bash.

You can check it with following command:

# ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Dec  9 20:26 /bin/sh -> bash

kernel: e1000e eth0: Error reading PHY register

In recent CentOS version 6.3 is an unresolved bug, which causes the network card to freeze the server.

Following message appears in /var/log/messages

kernel: e1000e 0000:02:00.0: eth0: Error reading PHY register

To work around the problem you will need to turn off Active-State Power Management (ASPM)
(Feature that saves power in the Peripheral Component Interconnect Express (PCI Express or PCIe) subsystem by setting a lower power state for PCIe links when the devices to which they connect are not in use)

For GRUB bootloader edit the following file: /boot/grub/grub.conf and append pcie_aspm=off to the end of kernel boot line.

For example:

kernel /vmlinuz-2.6.32-279.el6.x86_64 ro root=UUID=81e9e0a2-0a51-4d75-955d-909aaf848192 rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_NO_DM rd_MD_UUID=c6855f45:016a63bb:2d79bfb2:07371ed8 rd_NO_LVM rd_MD_UUID=5d5a434e:6c20cfcd:51340c3f:29c29151 pcie_aspm=off

To verify the change, reboot the server and run the following command:

dmesg | grep PCIe
PCIe ASPM is disabled

If your output is different, the change in grub.conf did not take an effect.

OpenVPN route all traffic via VPN

To add default route via VPN server add following lines into your server’s configuration file (usually /etc/openvpn/server.conf).

 push "redirect-gateway def1"
 push "dhcp-option DNS 8.8.8.8"

DNS option may be required, if you are having troubles with name resolution after connecting to VPN.