Initial Settings after installing the CentOS 7

1) To change the hostname permanently, edit the following file:

sudo vi /etc/hostname

centos7

Here you can simply put the name of your system (in my case, I have assigned it CentOS-7):

centos7 (1)

After that, edit the hosts file:

sudo vi /etc/hosts

centos7 (2)

Here add the same name, that you have added in the /etc/hostname file, after 127.0.0.1:

centos7 (3)

After reboot, it will display the new hostname.

2) After login to the CentOS7 server(minimal installation), you will notice that the system doesn’t have ifconfig command :

centos7 (4)

Install the net-tools package which will include ifconfig:

sudo yum install net-tools

centos7 (5)

Try the ifconfig command once again:

centos7 (6)

3) Change the default network interface name to “eth0″

CentOS7 has a default nic name as “en016…..”, as we can see in above screenshoot. To change it back to the default network device name like “ethX”, edit the grub file:

sudo vi /etc/default/grub

centos7 (7)

Search for the line “GRUB_CMDLINE_LINUX” and append the following: “net.ifnames=0 biosdevname=0

Will look like this:

GRUB_CMDLINE_LINUX="rd.lvm.lv=rootvg/usrlv rd.lvm.lv=rootvg/swaplv crashkernel=auto 
vconsole.keymap=usrd.lvm.lv=rootvg/rootlv vconsole.font=latarcyrheb-sun16 rhgb 
quiet net.ifnames=0 biosdevname=0"

centos7 (8)

Create a new configuration based on the currently running system using grub2-mkconfig command:

sudo grub2-mkconfig -o /boot/grub2/grub.cfg

centos7 (9)

Rename the interface files by renaming the file “/etc/sysconfig/network-scripts/ifcfg-en01…

sudo mv /etc/sysconfig/network-scripts/ifcfg-eno16777736 /etc/sysconfig/network-scripts/ifcfg-eth0

centos7 (10)

Reboot the system:

centos7 (11)

After reboot, check the interface name:

centos7 (12)

4) Configure the static ip on the server:

Edit the interface file under /etc/sysconfig/network-scripts/ directory:

sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0

centos7 (13)

Here is my ifcfg-eth0 file as a sample, please change it according to your requirement:

DEVICE="eth0"
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.250.50
NETMASK=255.255.255.0
GATEWAY=192.168.250.2
DNS1=192.168.250.2

centos7 (14)

Stop and disable the NetworkManager service, because we don’t need it on the server:

sudo systemctl stop NetworkManager 
sudo systemctl disable NetworkManager

centos7 (15)

Restart the network service(Be careful, if you are connecting remotely, because you will be disconnected after issue this command):

sudo service network restart

centos7 (16)

Check the newly assigned static ip:

centos7 (17)

5) Disable IPv6:

First check that IPv6 is enabled or not:

lsmod | grep -i ipv6

centos7 (18)

Edit the grub file:

sudo vi /etc/default/grub

centos7 (19)

Search for the line “GRUB_CMDLINE_LINUX” and add the following at the beginning: “ipv6.disable=1

Will look like this:

GRUB_CMDLINE_LINUX="ipv6.disable=1 rd.lvm.lv=rootvg/usrlv...

centos7 (20)

Create a new configuration based on the currently running system using grub2-mkconfig command:

sudo grub2-mkconfig -o /boot/grub2/grub.cfg

centos7 (21)

Reboot the system:

centos7 (22)

Once again, check the IPv6 on the system:

centos7 (23)

6) EPEL repository on Centos 7

To install the EPEL repository, issue the following command:

sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/beta/7/x86_64/epel-release-7-0.2.noarch.rpm

centos7 (24)

List your new repos:

sudo yum repolist

centos7 (25)

7) Enable iptables services(instead of firewalld):

When you will try to start/restart the iptables on newly install server, will get this error:

centos7 (26)

To fix this error, install the iptables-services package:

sudo yum install iptables-services

centos7 (27)

Re-run the command to restart the iptables:

sudo service iptables restart

centos7 (28)

Hope this will help you!

Part-4: Restore disk from Clonezilla Auto Restore CD/DVD

Please read the Part-1,2 and 3 before starting this tutorial, in order to get the better understanding.

1) At first, Clonezilla auto restore CD/DVD comes up with this screen just press ENTER:

1

2) Before starting the restoration process, Clonezilla will confirm from you TWICE, If you are sure that everything is fine, than just type “y” twice and press ENTER:

2

3

3) After the second confirmation, Clonezilla will start restoring the image to the selected target hard disk:

4

4) Once the cloning process will complete, Clonezilla will show you the summary, than type 1 to “Reboot” the system. Please also “Remove the Clonezilla auto restore CD/DVD” and press ENTER:

5

5) If everything goes well, your newly restored system will boot normally as per your desire:

6

Hope this will help you!

Part-3: Restore an image of a Hard drive using Clonezilla

In this tutorial, we’ll check that how to restore an image of a hard drive using the Clonezilla, that we have created in the Part-1 and stored it on the SSH Server.

Note: One of Clonezilla’s “Limitations” is that the destination disk must be the same size or larger than the source disk that we have been cloned, so make sure that the destination disk must be the same size or larger.

To restore an image of a hard drive, boot the system from the Clonezilla Live CD and follow the exact same procedure from step 1 to until step 15, that we have performed in Part-1.

1) On step 16, select the “restoredisk” option and press ENTER:

1

2) Select the image (In my case,it reside on SSH Server) that you want to restore:

2

3) In this step, select the target disk on which, you want to restore the image:

3

4) It will prompt you the command to restore the image, just press ENTER:

4

5) Before starting the restoration process, Clonezilla will confirm from you TWICE, If you are sure that everything is fine, than just type “y” twice and press ENTER:

5

6

6) After the second confirmation, Clonezilla will start restoring the image to the selected target hard disk:

7

7) Once the cloning process will complete, Clonezilla expect an ENTER to continue:

8

8) Than type 1 to “Reboot” the system. Please also “Remove the Clonezilla Live CD” and press ENTER:

9

9) If everything goes well, your newly restored system will boot normally as per your desire:

10

Hope this will help you!

Part-2: Creation of autorun recovery Clonezilla live CD/DVD from image

In the first part, we have created the Clonezilla image and store it on SSH Server. In this part, we’ll create the autorun recovery Clonezilla live DVD from that image.

Note: You need to go through the same process again from step 1 to until step 15, that we have performed in Part-1.

1) Select the “recovery-iso-zip” and press ENTER:

1

2) In the next screen, select the image folder (This is the image folder that we have created in part 1):

2

3) Choose the destination disk to be recovered when the recovery DVD being used:

3

4) Select the language that will be used in the recovery Clonezilla live:

4

5) Set the keyboard layout when the recovery DVD is used, default is NONE:

5

6) Select “iso” to create a DVD disk image which can burn on a DVD disc:

6

7) It displays a single command that will be executed, press ENTER to continue:

7

8) It will display a warning for confirmation that you want to continue, press “y“:

8

9) Creation of the iso image begin:

9

10) After the sucessful creation of iso image, Clonezilla will display a summary, press ENTER to continue:

10

11) Finally, select an option (poweroff, reboot etc),Don’t forget to remove the CloneZilla Live CD from the CD drive:

11

Verification of iso image on SSH Server:

check

Hope this will help you!

Part-1: Creation of Hard drive image using Clonezilla

clonezilla

Scenario:

The scenario is really simple, in which I want to backup my Ubuntu server using the “CloneZilla Live” and also want to store it on another server which has an ip address of 192.168.179.141. If you want to learn more about CloneZilla, please visit this link.

Let’s start the tutorial by inserting the CloneZilla Live CD into the server that you want to backup and boot from it.

1) At first, CloneZilla Live comes up with this screen just press ENTER:

1

2) Next, select your desired language:

2

3) If you are using US keymap, just select the default option “Don’t touch keymap” and press ENTER:

3

4) Select “Start Clonezilla” and press ENTER:

4

5) Select “device-image” and press ENTER:

5

6) Here we’ll select that where we want to store the hard drive image. In my case, I have selected SSH server:

6

7) Here, it will ask the network setting (I have selected dhcp):

7

8) Then it will ask the SSH server address (In my case, it is 192.168.179.141):

8

9) Next ssh port (default is 22):

9

10) User account on SSH Server that is allowed to write/read on the server:

10

11) Specify the directory on SSH Server, where CloneZilla image will be saved(In my case, it is /home/arbab/clonezilla):

11

12)Next click on OK:

12

13)and then enter your SSH password:

12a

14) Next screen will confirm the successfully mount. Press “Enter“:

13

15) Choose “Beginner” then hit Enter:

14

16) Select “savedisk” because, we want to create an image of the full hard drive:

15

17) Input the name that you want to give to your image (default is just fine for me):

16

18) Choose the hard drive for which you want to create an image:

17

19) Select an option, if you want to check & repair the file system before saving (I am going with default option, which is skip):

18

20) Select this option, if you want to check the saved image is restorable:

19

21) Hit Enter:

20

22) Then press “y” and Hit Enter to start the image creation process:

21

After this, image creation process will start (please be patient, this may take some time):

23

23) After the successful image creation, press ENTER:

24

24) Select your desired option to Poweroff/Reboot etc the CloneZilla Live system:

25

Login to SSH Server and verify the disk image:

26

Hope this will help you!

How to reduce the root partition in LVM

In this tutorial, I am using the CentOS6(I believe that its also applicable on other Linux distro but didn’t try yet) that has ext4 partition lv_root mounted as / and lv_swap as swap from the volume group vg_centos6 (which is default), that has two hard drives (66GB & 25GB). Due to some reasons, I want to remove the 25GB hard drive from my computer and want to add new 50 GB hard drive. Before, removing the hard drive from the computer, we need to resize the lv_root, then remove it from volume group and at the end from the physical volume.

WARNING: It’s really dangerous, so backup your data before attempting this. Please don’t blame me, if you destory your system. You are responsible for your own actions!

Check the size of lv_root before starting this process:

df -h

0 Boot from CentOS 6 DVD (or any other Linux distro that you are using) and select “rescue” option: 1 Select the Skip, so that it will not mount the filesystem: 2 Run these commands:

pvscan
vgscan
vgchange -a y
lvscan

3 Display the lv_root:

lvdisplay /dev/vg_centos6/lv_root

4 fsck on the large root filesystem (lv_root):

fsck.ext4 /dev/vg_centos6/lv_root

5 Run e2fsck with -f (force) option:

e2fsck -f /dev/vg_centos6/lv_root

6

Issue the resize2fs command to reduce the filesystem (Important: The size here is the actual/total size of the lv_root after reduce, not the size that we want to decrease):

resize2fs -p /dev/vg_centos6/lv_root 65G

7

Now, issue the lvreduce command to reduce the logical volume size:

lvreduce -L 65G /dev/vg_centos6/lv_root

8

Run lvdisplay command to confirm the change:

lvdisplay /dev/vg_centos6/lv_root

9

Reboot the system and login. Remove the disk (in my case it is, /dev/sdb1) from volume group and then from physical volume:

sudo vgreduce vg_centos6 /dev/sdb1

sudo pvremove /dev/sdb1

10

Check the size of lv_root after all these changes:

df -h

11

Success!

Hope this will help you!

How to extend the root partition in LVM

In this tutorial, I am using the CentOS6(but also applicable on other Linux distro) that has ext4 partition lv_root mounted as / and lv_swap as swap from the volume group vg_centos6 (which is default), we pretend that we are running out of space in lv_root(/) and volume group (vg_centos6) doesn’t have any free space. We added a brand new drive with 20 GB space. Now, we need to assign this 20 GB space to volume group and then extend lv_root(/).

WARNING: Backup your data before attempting this.

First, we’ll check the file system disk space usage and logical volume information:

sudo df -h
sudo lvs

1

Get the information about newly added hard disk using the following command:

sudo fdisk -l

2Note: /dev/sdb is the newly added hard disk!

To create the partition on the second Hard disk, use the following command and follow the “on screen” instructions and change the partition type from Linux to LVM (8e):

sudo fdisk /dev/sdb

3

Identify the already mounted lvm file system type:

df -T

4

Format the newly created partition using the following command:

sudo mkfs.ext4 /dev/sdb1

5

Initialize the newly created partition as a physical volume:

sudo pvcreate /dev/sdb1

6

Check the volume groups using the following command:

sudo vgs

7Note: vg_centos6 is the volume group that I want to extend, you can change according to your volume group.

Extend the VG (vg_centos6) with new PV (/dev/sdb1):

sudo vgextend vg_centos6 /dev/sdb1

8

Extend the logical volume (lv_root) with all the free space of the VG(vg_centos6):

sudo lvextend -l +100%FREE /dev/vg_centos6/lv_root

9

Finally, resize the file-system:

sudo resize2fs /dev/vg_centos6/lv_root

10

Verify the file-system is larger using the following commands:

sudo df -h
sudo lvs
sudo vgs

11

Hope this will help you!