Centos 7 systemctl tips and tricks

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

[code]systemctl list-unit-files[/code]

2. Enable HTTPD + Mysql service on system boot:

[code]
systemctl enable httpd
systemctl enable mariadb
[/code]

3. Reverting to iptables from firewalld

[code]
systemctl stop firewalld
systemctl mask firewalld

yum install iptables-services

systemctl enable iptables
systemctl start iptables

# to save iptables rules use
service iptables save

[/code]

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]

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:

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

To revert this this behaviour to standard, execute

[code]
# dpkg-reconfigure dash
[/code]

dash dpkg-reconfigure debian linux

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

You can check it with following command:

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

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

[code]
kernel: e1000e 0000:02:00.0: eth0: Error reading PHY register
[/code]

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:
[code]
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
[/code]

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

[code]
dmesg | grep PCIe
PCIe ASPM is disabled
[/code]

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