Showing posts with label Some Important commands for Linux administration. Show all posts
Showing posts with label Some Important commands for Linux administration. Show all posts

Sunday, April 6, 2025

To Reduce XFS File System /var in Linux and remove physical volume from the Volume group



How to Reduce XFS File System /var in Linux and remove physical volume from the Volume group-



Task -
We have additional physical disk into varlv which is unused and want to remove the disk from Logical volume and Volume group.


[root@rhel8-node2 var]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.4G 0 1.4G 0% /dev
tmpfs 1.4G 0 1.4G 0% /dev/shm
tmpfs 1.4G 8.6M 1.4G 1% /run
tmpfs 1.4G 0 1.4G 0% /sys/fs/cgroup
/dev/sda1 49G 5.3G 42G 12% /
/dev/mapper/rootvg-varlv 16G 1.1G 15G 7% /var
tmpfs 279M 0 279M 0% /run/user/0
[root@rhel8-node2 var]#


[root@rhel8-node2 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
varlv rootvg -wi-ao---- <8.11g
[root@rhel8-node2 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 rootvg lvm2 a-- <10.09g 1.98g
/dev/sdc1 rootvg lvm2 a-- <5.02g <5.02g
[root@rhel8-node2 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
rootvg 2 1 0 wz--n- <15.11g 7.00g
[root@rhel8-node2 ~]#


As per above logs, we can remove easily remove /dev/sdc1 because /var utilization is only 1.1 Gb and LV having 10G and 5G disks.
So we can remove any disk which we want. Here I am taking example to remove /dev/sdc1 disk from /var xfs file system.



Warning: -
As /var is a root file system, and it is using by running process so before performing any activity, we need to take downtime for services
as well as need to check latest backup.


– Install the xfsdump package

[root@rhel8-node2 /]# yum install xfsdump -y

Updating Subscription Management repositories.
-
-
-
Installed products updated.


Upgraded:
xfsdump-3.1.8-7.el8_9.x86_64


Complete!
[root@rhel8-node2 /]#


- Backup the Data using xfsdump



[root@rhel8-node2 /]# xfsdump -f /tmp/var.dump /var
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.8 (dump format 3.0) - type ^C for status and control


============================= dump label dialog ==============================


please enter label for this dump session (timeout in 300 sec)
-> d
session label entered: "d"


--------------------------------- end dialog ---------------------------------


xfsdump: level 0 dump of rhel8-node2:/var
xfsdump: dump date: Sun Apr 6 12:35:33 2025
xfsdump: session id: 83e15d09-b78a-4d8f-97f0-9569c5d7529e
xfsdump: session label: "d"
xfsdump: ino map phase 1: constructing initial dump list
xfsdump: ino map phase 2: skipping (no pruning necessary)
xfsdump: ino map phase 3: skipping (only one dump stream)
xfsdump: ino map construction complete
xfsdump: estimated dump size: 984386048 bytes


============================= media label dialog =============================


please enter label for media in drive 0 (timeout in 300 sec)
-> var
media label entered: "var"


--------------------------------- end dialog ---------------------------------


xfsdump: creating dump session media file 0 (media 0, file 0)
xfsdump: dumping ino map
xfsdump: dumping directories
xfsdump: dumping non-directory files
xfsdump: ending media file
xfsdump: media file size 981625112 bytes
xfsdump: dump size (non-dir files) : 979741224 bytes
xfsdump: dump complete: 63 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /tmp/var.dump OK (success)
xfsdump: Dump Status: SUCCESS
[root@rhel8-node2 /]#


Now unmount the /var File system-


[root@rhel8-node2 /]# umount /var
[root@rhel8-node2 /]#


Now reduce the Logical volume and give the desired size of /var File system


[root@rhel8-node2 /]# lvreduce -L 5G /dev/mapper/rootvg-varlv
WARNING: Reducing active and open logical volume to 5.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce rootvg/varlv? [y/n]: yes
Size of logical volume rootvg/varlv changed from <15.11 GiB (3867 extents) to 5.00 GiB (1280 extents).
Logical volume rootvg/varlv successfully resized.
[root@rhel8-node2 /]#


Format the partition with XFS File system-


[root@rhel8-node2 /]# mkfs.xfs -f /dev/rootvg/varlv
meta-data=/dev/rootvg/varlv isize=512 agcount=4, agsize=327680 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=0 inobtcount=0
data = bsize=4096 blocks=1310720, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@rhel8-node2 /]#


Post that remount File system-

[root@rhel8-node2 /]# mount /dev/rootvg/varlv /var



Now we can restore the backup-



[root@rhel8-node2 tmp]# xfsrestore -f /tmp/var.dump /var
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.8 (dump format 3.0) - type ^C for status and control
xfsrestore: searching media for dump
xfsrestore: examining media file 0
xfsrestore: dump description:
xfsrestore: hostname: rhel8-node2
xfsrestore: mount point: /var
xfsrestore: volume: /dev/mapper/rootvg-varlv
xfsrestore: session time: Sun Apr 6 12:35:33 2025
xfsrestore: level: 0
xfsrestore: session label: "d"
xfsrestore: media label: "var"
xfsrestore: file system id: 38ca1029-5051-45ae-ad1d-84bafeeeede0
xfsrestore: session id: 83e15d09-b78a-4d8f-97f0-9569c5d7529e
xfsrestore: media id: 504c1e39-55dd-4f9b-bf7e-f2e30b22999b
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 772 directories and 2822 entries processed
xfsrestore: directory post-processing
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 3 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore: stream 0 /tmp/var.dump OK (success)
xfsrestore: Restore Status: SUCCESS
[root@rhel8-node2 tmp]#


Post that validate the content of /var File system-


[root@rhel8-node2 tmp]# df -Th /var
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/rootvg-varlv xfs 5.0G 1008M 4.1G 20% /var
[root@rhel8-node2 tmp]#


Validate the reduced size and free space-


[root@rhel8-node2 tmp]# vgs
VG #PV #LV #SN Attr VSize VFree
rootvg 2 1 0 wz--n- <15.11g <10.11g
[root@rhel8-node2 tmp]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 rootvg lvm2 a-- <10.09g <5.09g
/dev/sdc1 rootvg lvm2 a-- <5.02g <5.02g
[root@rhel8-node2 tmp]#


Now we can reduce volume group-

[root@rhel8-node2 tmp]# vgreduce rootvg /dev/sdc1
Removed "/dev/sdc1" from volume group "rootvg"
[root@rhel8-node2 tmp]#
[root@rhel8-node2 tmp]# vgs
VG #PV #LV #SN Attr VSize VFree
rootvg 1 1 0 wz--n- <10.09g <5.09g
[root@rhel8-node2 tmp]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 rootvg lvm2 a-- <10.09g <5.09g
/dev/sdc1 lvm2 --- <5.02g <5.02g
[root@rhel8-node2 tmp]#


Finally, we can remove physical volume from the server and as well as ask VM Team to remove /dev/sdc1 disk from VM


[root@rhel8-node2 tmp]# pvremove /dev/sdc1
Labels on physical volume "/dev/sdc1" successfully wiped.
[root@rhel8-node2 tmp]#
[root@rhel8-node2 tmp]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 rootvg lvm2 a-- <10.09g <5.09g
[root@rhel8-node2 tmp]#

Tuesday, February 18, 2020

Some Important commands for Linux administration....

1. To register linux server with your account: -

[root@AMITESHJSK /]#subscription-manager register --username amiteshjsk --password *******  --auto-attach

2.To check Kernel version in Linux

[root@AMITESHJSK /]# uname -a
Linux AMITESHJSK 3.10.0-514.el7.x86_64 #1 SMP Wed Oct 19 11:24:13 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux

3.To check the inode number of a file or directory

Inode number or Index number is the entry in inode table containing the informations      (metadata) of a file or directories .

[root@AMITESHJSK /]# ls -li kisna.txt
14441 -rw-r--r--. 1 root root 0 Jun 30 10:30 kisna.txt

4. To create Soft links and Hard links

Soft link or symbolic link or symlink is same as shortcuts in windows OS, an easiest way to link files or directories .
To create Soft links 
[root@AMITESHJSK /]# ln -s /etc/ssh/sshd_config sshd
[root@AMITESHJSK /]# ls -ltr |grep -i sshd
lrwxrwxrwx.   1 root root   20 Jun 30 10:40 sshd -> /etc/ssh/sshd_config

Note: - /etc/ssh/sshd_config (source file)
            sshd  (link file)  

To create Hard links

[root@AMITESHJSK /]# ln /etc/ssh/sshd_config sshdhard
[root@AMITESHJSK /]# ls -ltr | grep -i sshdhard
-rw-------.   2 root root 4360 Jun 24 10:20 sshdhard

Note: - /etc/ssh/sshd_config (source file)
            sshdhard  (link file)

5. To mount your .iso file in linux server: -

[root@AMITESHJSK /]#mount -o loop rhel-server-7.3-x86_64-dvd.iso /mnt/iso

Mount Options :
ro  –  read only,  rw  –  read write,  user  –  user can mount,  exec  –  script can be execute,  noexec  –  script can’t be execute,  noauto  –  partition will not mount automatically,  auto  –  mounts automatically,  sync  –  input and output will synchronize.

6.To set Proxy address in Linux server: -

[root@AMITESHJSK /]#export http_proxy=http://192.168.11.40:8080/
----------------------------------------------------------------------------------------------------------------------

7.To configure NFS in Linux server: -

A.) First of all you have to make entry in /etc/exports of nfs server like:-

/mnt/iso (rw,sync,no_root_squash)



Note: - /mnt/iso (desired mount which you want to share)
 If you want to share mount point with only selected host(eg.- 192.168.11.42) then make entry in /etc/exports like: -

/mnt/iso 192.168.11.42 (rw,sync,no_root_squash)

B.) After that restart nfs service: -


[root@AMITESHJSK /]#service nfs restart


C.) Now you can check shared mount point details by below command: -

[root@AMITESHJSK /]#showmount -e
Export list for MONITORING:
/mnt/iso *

D.) Now mount in client server after creating a directory 

[root@AMITESHJSK /]#mkdir iso
[root@AMITESHJSK /]#mount -t nfs 192.168.11.41:/mnt/iso /iso


Note: - 192.168.11.41 (NFS Server IP )

root_squash – If we are putting root_squash, then it will map root UUID/ GID to anonymous UUID/GID. So in client side the client root user will be denied for accessing, creating file in mounted NFS partition.

no_root_squash  – In no_root_squash , It won’t map root UUID/GID to anonymous user and thus the client root user have all the privileges on the mounted NFS partition.

------------------------------------------------------------------------------------------------------------------------

8.To check list of Listening ports in Redhat Linux:-

[root@AMITESHJSK /]#netstat -tulpn














9. To find a file by name on system from any directory path: -


[root@AMITESHJSK /]#locate filename

-----------------------------------------------------------------
Creating yum  repository file for installing Redhat cluster Software Pacemaker :-

A.) First of all, Mount ISO image file in Server by using below command: -

[root@AMITESHJSK /]#mkdir iso 
[root@AMITESHJSK /]#mount -o loop rhel-server-7.3-x86_64-dvd.iso /iso

B.) Then create a repository file in /etc/yum.repos.d/ path:-

[root@AMITESHJSK /]#vi ha.repo
[repo-update]
gpgcheck=0
enabled=1
baseurl=file:///iso
name=repo-update

[repo-ha]

gpgcheck=0
enabled=1
baseurl=file:///iso/addons/HighAvailability
name=repo-ha

[repo-storage]

gpgcheck=0
enabled=1
baseurl=file:///iso/addons/ResilientStorage
name=repo-storage


C.) Exit by using :wq! from vi editor.

D.) Now we can check our repolist by:-

#yum repolist
epo id                                      repo name                                                                  status
repo-ha                                      repo-ha                                                                        37
repo-storage                                 repo-storage                                                                   42
repo-update                                  repo-update                                                                 4,751
rhel-7-server-rpms/7Server/x86_64            Red Hat Enterprise Linux 7 Server (RPMs)                                   28,773
repolist: 33,603

E.) After that we can install pacemaker by using below command: -

[root@AMITESHJSK /]#yum install -y pacemaker pcs psmisc policycoreutils-python


Stay tuned for installation and configuration of pacemaker.
--------------------------------------------------------------------------------------------------------------------------



Click below link to know more important commands----
https://lalganjrbl.blogspot.com/2020/03/small-but-thick-knowledge.html





Introduction to Linux Part 1

Introduction to Linux Part 1

Introduction to Linux Linux is an operating system that works just like Windows and Mac OS X. As an operating system, Linux is a very h...