How to add New Disk in Linux CentOS 7 Without Rebooting

Increasing disk spaces on the Linux servers is a daily routine work for very system administrator. So, in this article we are going to show you some simple simple steps that you can use to increase your disk spaces on Linux CentOS 7 without rebooting to your production server using Linux commands. We will cover multiple methods and possibilities to increase and add new disks to the Linux systems, so that you can follow the one that you feel comfortable while using according to your requirements.

1) Increasing Disk of VM Guest:

Before increasing the disk volume inside your Linux system, you need to add a new disk or increase the one its has already attached with the system by editing its settings from your VMware vShere, Workstation or any other infrastructure environment that you are using.

1

2) Check Disk Space:

Run the following command to check the current size of your disk space.

# df -h

and

# fdisk -l

2

Here we can see that the total disk size is still the same that is 10 GB while we have already increased it to 50 GB from the back end.

3) Expanding Space without Rebooting VM

Now run the following commands to expand the disk space in the physical volume of the Operating System without rebooting the virtual machine by Re-scanning the SCSI Bus and then adding SCSI Device.

# ls /sys/class/scsi_host/

# echo "- - -" > /sys/class/scsi_host/host0/scan

# echo "- - -" > /sys/class/scsi_host/host1/scan

# echo "- - -" > /sys/class/scsi_host/host2/scan

Check the names of your SCSI devices and then rescan the SCSI buses using below commands.

# ls /sys/class/scsi_device/

# echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/rescan

# echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan

That will rescan the current scsi bus and the disk size that we increased from the VM guest settings will be show up as you can see in the below image.

3

4) New Disk Partition:

Once you are able to see the increased disk space inside your system then the run the following command to format your disk for creating a new partition by following the steps to increase your physical disk volume.

# fdisk /dev/sda

result:

Welcome to fdisk (util-linux 2.23.2) press the 'm' key for help
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help):

Type the ‘p’ to print the current partition table then create a new primary partition by typing the ‘n’ key and selecting the available sectors. Change the disk type to ‘Linux LVM’ by using ‘t’ command and selecting the code to ‘8e’ or leave as it to its default type that is ’83’.

Now write the table to disk and exit by Entring ‘w’ key as shown.

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)

4

5)Creating Physical Volume:

As indicated above run the ‘partprobe’ or kpartx command so that the tables are ready to use and then create the new Physical Volume using the below commands.

# partprobe

# pvcreate /dev/sda3

To check the newly created volume run the following command to see if the new physical volume has been created and visible. After that we will extend the Volume Group ‘centos’ with the newly create Physical Volume as shown.

# pvdisplay

# vgextend centos /dev/sda3

5

6) Extending Logical Volume:

Now we will extend the Logical Volume to increase the disk space on it using the the below command.

# lvextend -L +40G /dev/mapper/centos-root

Once you get the successfully increased message, run the command as shown below to extend the size of your logical volume .

# xfs_growfs /dev/mapper/centos-root

The size of the ‘/’ partition has been increased successfully, you can check the size of your disk drives by using the ‘df’ command as shown.

6

7) Extending Root Partition by Adding New Disk Without Reboot:

This is the second method with but with quite similar commands to increase the size of the Logical volume in CentOS 7.

So, the first step is to Open the setting of your VM guest settings and click on the ‘Add’ new button and proceed to the next option.

7

Choose the required configuration for the new disk by selecting the size of the new disk and its type as shown in the below image.

8

Then come to the server side and repeat the following commands to scan your disk devices to the new disk is visible on the system.

# echo "- - -" > /sys/class/scsi_host/host0/scan

# echo "- - -" > /sys/class/scsi_host/host1/scan

# echo "- - -" > /sys/class/scsi_host/host2/scan

List the names of your SCSi devices

# ls /sys/class/scsi_device/

# echo 1 > /sys/class/scsi_device/1\:0\:0\:0/device/rescan
# echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan
# echo 1 > /sys/class/scsi_device/3\:0\:0\:0/device/rescan

# fdisk -l

9

Once the new disk is visible run the below commands to create the new physical volume and add it to the volume group as shown.

# pvcreate /dev/sdb

# vgextend centos /dev/sdb

# vgdisplay

10

Now extend the Logical Volume by adding the disk space on it and then add it to the root partition.

# lvextend -L +20G /dev/mapper/centos-root

# xfs_growfs /dev/mapper/centos-root

# df -h

11
Conclusion:

Managing disk partitions in Linux CentOS 7 is a simple process to increase the disk space of any of your logical volumes by using the steps as described in this article. You don’t need to give your production server’s reboot for this purpose but simply rescan your SCSi devices and expand your desired LVM.

Continue Reading

How to Install OwnCloud 9.0.2 on CentOS 7 / RHEL 7

ownCloud is based on PHP and a SQLite, MySQL, Oracle or PostgreSQL database, so it can run on all platforms that meet these requirements. It provides almost all possibility of functions that are available on commercial suites; it is released under AGPLv3 license, so you can setup own cloud storage server without any additional cost.

Commercial version of ownCloud is also available.
Features:

What’s new in ownCloud 9:

It is now easier to keep ownCloud updated with the channel of your choice via the built-in Updater app and our package repositories.
ownCloud Server  brings much improved performance in the areas of syncing, file operations and dealing with parallel requests.
To make ownCloud easier to use, documentation has been massively improved and integrated in the interface.

The following are the list of features available on ownCloud.

Mobile and Desktop Syncing
Share With Anybody
External Storage
Encryption and Security
Versioning and Undelete
Activity Feed
Calendars and Contacts
Collaborative Editing
Galleries
Play Music, Watch Movies, Store Passwords

Download and Setup:

Run the following shell commands as root to trust the repository.

rpm --import https://download.owncloud.org/download/repositories/stable/CentOS_7/repodata/repomd.xml.key

Run the following shell commands as root to add the repository and install from there.

wget http://download.owncloud.org/download/repositories/stable/CentOS_7/ce:stable.repo -O /etc/yum.repos.d/ce:stable.repo
yum clean expire-cache
yum install owncloud-files

Allow apache in firewall.

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

Allow the web server to read and write the files on ownCloud directory.

chown -R apache.apache /var/www/html/owncloud/

Start Apache .

systemctl start httpd.service

Auto start the service at system start-up.

systemctl enable httpd.service

SELinux:

Set SELinux to allow OwnCloud to write the data.

semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/data'
restorecon '/var/www/html/owncloud/data'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/config'
restorecon '/var/www/html/owncloud/config'
semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/owncloud/apps'
restorecon '/var/www/html/owncloud/apps'

Extra’s:

The default maximum file size for uploads is 512MB. You can increase this limit by editing .htaccess file.

vi /var/www/html/owncloud/.htaccess

Modify the below entries.

php_value upload_max_filesize 513M
php_value post_max_size 513M

Untitled

My OwnCloud

That’s All!.

Continue Reading

How to Block Ping (ICMP) Responses in Linux System

Blocking ping responses from system can prevent system from hackers to ICMP flood dos attacks. So it can be a best practice for system security but most of online monitoring systems uses ping requests for monitoring system.
Disable Ping using iptables

You can simply block icmp responses directly from firewall in any Linux systems.

# iptables -A INPUT -p icmp --icmp-type echo-request -j DROP

Block Ping with Kernel Parameter

We can also block ping responses from system by directly updating kernel parameters. In this we can block ping responses temporarily or permanently as below.

Block Ping Temporarily

You can block temporarily block ping responses temporarily using following command

# echo "1" >  /proc/sys/net/ipv4/icmp_echo_ignore_all

Block Ping Permanently

In place of blocking ping temporarily, You can block it permanently by adding following parameter in /etc/sysctl.conf configuration file.

net.ipv4.icmp_echo_ignore_all = 1

Now execute following command to apply settings immediately without rebooting system.

# sysctl -p
Continue Reading

How to Install iRedMail on CentOS 7 & RHEL 7

iRedMail is out of the box open source mail server solution on Linux like operating system. The beauty of iRedMail is that it provides web based admin panel from where mail admin or system admins can do all email related operations task. Some of other features are listed below :

Support unlimited email accounts.
It provides Roundcube as webmail (MUA )
It used Postfix as MTA & Dovecot as MDA
It pvoides Calendar service via CalDAV & Contact service via CardDAV
It uses SpamAssassin for Spam scan and Amavis & Clamav for Mail virus scan.
OpenLDAP, MariaDB and PostgreSQL can be used to save mail accounts

In this article we will demonstrate how to install and configure iRedMail on CentOS 7 & RHEL 7. I am going to use followings for iRedMail setup.

OS = CentOS 7 or RHEL 7
Domain = nsitmail.com
Server Hostname = mail.nsitmail.com

Note : In case if you want mails from your mail server to be delivered in inbox not in spam folder then update the DNS records like A & PTR  before installation and TXT ( SPF & DKIM ) after installation.

Step:1 Set hostname and disable Selinux.

Set the proper hostname using hostnamectl command if it is not set.

[root@mail ~]# hostnamectl set-hostname mail.nsitmail.com
[root@mail ~]# hostname -f
mail.nsitmail.com
[root@mail ~]#

Update the /etc/hosts file

127.0.0.1 mail.nsitmail.com localhost.localdomain localhost

Disable Selinux

[root@mail ~]# setenforce 0

Edit the file /etc/sysconfig/selinux , set the parameter “SELINUX=disabled” , Reboot the server to disable selinux completely.
Step:2 Download the tar file of iRedmail.

Download the latest version of iRedmail from their Official Web Site or use below wget command to download from terminal.

[root@mail ~]# wget https://bitbucket.org/zhb/iredmail/downloads/iRedMail-0.9.3.tar.bz2

Step:3 Extract the tar file & execute installation Script.

[root@mail ~]# ll
total 124
-rw-r--r-- 1 root root 126277 Dec 20 19:12 iRedMail-0.9.3.tar.bz2
[root@mail ~]#
[root@mail ~]# tar -jxvf iRedMail-0.9.3.tar.bz2
[root@mail ~]# cd iRedMail-0.9.3
[root@mail iRedMail-0.9.3]# sh iRedMail.sh

After couple of seconds , below screen will appear , Select yes and press enter.

1

Define the folder or directory where users mailbox will be stored.

2

Select the web Server for iRedmail. Default is Nginx.

3

Select the database of your choice which will store domain names and mail accounts. In my case i am using MariaDB.

4

Define the domain name for your mail server. In my case domain name is “nsitmail.com”

5

Set Password for postmaster account.

6

Select Optional Components of iRedmail installation8

Press “y” to continue installation, Mail Server info & Credentials are kept in the file “/root/iRedMail-0.9.3/config”. Please keep this file in secure place.

9

10

As per instructions , reboot the server to enable all mail services.

Postfix mail logs and iRedmail logs are stored in “/var/log/maillog” and “/var/log/iredapd/iredapd.log” respectively.

Note : Default administrator name is “postmaster@nsitmail.com”

Following are the Important URLs after the Installation is completed , replace the domain name as per your setup in mentioned URLs.

iRedAdmin – official web-based admin panel:

https://mail.nsitmail.com/iredadmin/

Username: postmaster@nsitmail.com, password: XXXXXXXXXX

Roundcube webmail URL :

http://mail.nsitmail.com/mail/

SOGo Groupware

https://mail.nsitmail.com/SOGo/

Step:4 Create Users & domain from Admin Panel.

To create users first login to admin panel. Use user name as “postmaster@<domain>” and password that we set during installation.

1-11-2

Click on Add option and then Select Users.

1-3

Add a new Domain :

From the admin Panel , Select “Domain & accounts” option and then click on Add domain

1-4

Define the domain name & Organization Name and then further we can create users on newly created domain.

1-5

Step:5 Access Roundcube (Webmail).

Open the url in the browser “https://mail.nsitmail.com/mail/” , replace the domain name as per your setup.

1-6

1-7

Send a test mail to verify the functionality.

1-8

As we see that i got the mail from iRedmail mail server, so we can say the iRedmail is successfully installed and configured.

Continue Reading

CentOS 7 / RHEL 7 : Reset / Recover forgotten root password

In this post we will learn, how to reset / recover forgotten root password on CentOS 7 / RHEL 7 (Red Hat Enterprise Linux 7). On RHEL 5/6 or CentOS 5/6 series , the method of resetting forgotten root password was same. In latest RHEL 7 / CentOS 7 this time we have found some difference in steps to reset the forgotten root password.

Earlier, root password were used to recover from runlevel in case the boot loader password is not set.

Reset / Recover forgotten root password on CentOS 7 / RHEL 7

Follow the given below procedure to reset forgotten root password.

Step 1: Reboot or start the system, edit grub2

Restart/start the system and on getting GRUB 2 boot screen, first press ESC key so that screen get stopped. Then press e key for editing

vbox-1

Step 2: Initialize the /bin/sh

Now in next screen, scroll down with the help of arrow key and search for any of these two keyword linux16 or linuxefi on UEFI systems.In our case, we have linux16.

Disable rhgb and quiet parameters in order to enable system messages.

In first screenshot you can see, we first scrolldown to line starting with keyword called linux16 . Now remove the parameter rhgb and quiet .

root-passwd-2

In second screenshot you can see, we have removed the rhgb and quiet parameter
Add the below given parameter at the end of line, to initialize the sh shell.

init=/bin/sh

Now press CTRL with x keyword to boot the system. .

root-password-3

Step 3: Remount / root partition , reset root password and autorelable

The filesystem will be in read only mode, hence run the below given command so that you can write on filesystem

mount -o remount, rw /

Now reset root password with given below command

passwd root

Reconfirm the root password.

NOTE: In case system is not writable, the passwd tool fails with the following error:
Authentication token manipulation error

Now run the below given command for relabeling the SELINUX

touch /.autorelabel

Now restart the system. You can use any one of the command.

exec /sbin/init

OR

exec /sbin/reboot

vbox-6

You will see the system is going to reboot and stuck for a short time. Just wait for a few seconds or minute. Keep pay attention that the screen is stopped when SELIUX relabeling info message appeared on screen.
After a few moment, you will see at the bottom of screen some numerical percentage is running. It states about the completion of selinux relabeling in percentage. After completing 100% , the system will be rebooted.

vbox-7

After successful booting, you can use your new root password for login into system.

vbox-8

That is all!

Continue Reading