Published on

Disk Management

Authors
  • Name
    Jackson Chen

Disks management is part of managing systems as there are requirements to add additional disk, expand disks in Linux and Windows. Systems are mostly virtual machines now-a-days.

Here is not talking how to add a disk from vCenter, Hyper-V or other hypervisor. It is about the proccess after the new disk has been added or the disk has been expanded, to make the new disk or additional space available in Linux or Windows.

Windows Disk Management

We could manage the disk from Command prompt or PowerShell.

Diskpart command is Windows disk management tool

https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-vista/cc766465(v=ws.10)?redirectedfrom=MSDN

Add New Disk - Command Prompt

To view Windows commands

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands

Disk unit size: default 4K, and other sizes, such as 64K

https://www.diskpart.com/articles/change-block-size-from-4k-to-64k-4125.html

Run command prompt as administrator

1. diskpart
2. list disk    # list the existing disk
3. rescan       # rescan the computer looking for new disk been added or disk size has been increased
3. Select disk  <number>    # select the new disk number
4. online disk  # bring the disk online if it is offline
5. attribute disk clear readonly    # change disk to read/write
6. convert gpt  # defaul is MBR
7. list disk   # Verify and ensure the disk has been converted to gpt
8. create partition primary
9. select partition 1   # select the new primary partition
10. list volume    # verify the raw volume has been selected, otherwise select the volume
11. format fs=ntfs label=<partitionName> quick     # default unit size 4k, using unit=64K for SQL, Exchange and backup disks
12. list volume     # Verify the volume number of the new disk
13. select volume <number>
14. assign letter <x>   # assign partition letter, such as D, E
15. exit

Expand Disk - Command Prompt

After increase the disk size for the virtual machine, expand the partition to include the free space

1. diskpart
2. rescan
3. select disk <number>     # select the disk has extra free space
4. detail disk      # verify the volume number for extend
5. select volume <number>   # select the volume number to extend
6. extend
7. list volume      # verify the volume has extended
8. exit

Managing Disk Using PowerShell

We could manage disks from PowreShell

# Run as administrator
1. get-disk
2. clear-disk -number x   -removedata
3. New-Partition -disknumber x -usemaximumsize | format-volume -filesystem NTFS -NewFileSystemLabel <newdrive>
4. Get-partition -disknumber x | Set-partition -NewDriveLetter D

Set-Partition -driveletter D  -newdriveletter  E    # Change drive letter

# Diskpart can also be called from PowerShell   

# Using mbr2gtp commands
1. get-disk | ft -auto
2. mbr2gpt /validate /disk: x  /allowfullOS     # Scan disk for validation
3. mbr2gpt /convert /disk: x

Red Hat Disk Management

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/4/html/introduction_to_system_administration/s2-storage-addrem

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/storage_administration_guide/s1-system-config-lvm-new-hdd

https://www.techotopia.com/index.php/Adding_a_New_Disk_Drive_to_a_RHEL_System

Disk Management Utilities

lsblk       # list block disk, size and mount point, identify the new disk
            # lsblk --output Name,FSType,label,UUID,Mode
df -h       # verify disk usage
            # df -h | grep ^/dev    # list the physical hard disks
fdisk -l    # list disk and partition size
            # it will show /dev/sd<x>
            # sfdisk -l     # show disk, cyclinders, sectors/track
cfdisk      # Linux disk utility
parted -l   # parted disk utility
fdisk /dev/sd<x>    # working on specific partition
        m   # type m for help to see options
        n   # add new partition
        w   # write/commit changes

Add New Disk - Primary Partition Disk

https://www.tecmint.com/fdisk-commands-to-manage-linux-disk-partitions/

fdisk -l        # list the current partition and configurations
                It will show the new disk as /dev/sd(x) with /dev/sd(x)<number>
fdisk /dev/sd(x)        # to partition the new disk
        n               # command used commands:
                        n       Create partition
                        p       Print partition table
                        d       Delete a partition
                        w       Write/save change
                        q       Exit without saving changes
        then select
                p       Primary partition (Up to maximum of 4 new primary partitions)
                e       Extended partition
        p
        Use the default partition number, or change to desired value
        Select First Sector
        Last Sector     type    +<Number>G
        w               Save and exit        
mkfs.xfs /dev/sd(x)     Format the disk, common format type xfs, ext4
mkdir /data             # Create mount point
mount /dev/sd(x) /data  # Mount the new disk to /data
/etc/fstab file update
        /dev/sd(x)      /data   defaults        0  0
fdisk -l        # Verify the partitions after the update

Add New Disk - Logical Volume Management (LVM)

https://linoxide.com/lvm-configuration-linux/

LVM has 3 concepts:

  1. Physical volume (pv) - whole disk or partition of a disk
  2. volume group (vg) - corresponds to one or more pv
  3. Logical volume (lv) - represents a portion of a vg. We create file system on lv

Create Physical Volume

It can be an entire disk, a partition on a disk, or a LUN on the SAN. pvcreate command initialize the disk, so it can be part of a volume group.

pvcreate /dev/sdb /dev/sdc      # initialize both disk
pv or pvdisplay                 # Verify the physical volume, it shows pv size, pv UUID, etc

Create Volume Group

Physical volumes are combined into volume groups (VGs). It creates a pool of disk space which logical volumes can be allocated.

pvcreate vgData /dev/sdb /dev/sdc       # create volume group vgData combines two disks /dev/sdb and /dev/sdc
vgs or vgdisplay       # Verify vg information

Create Logical Volumes

A volume group is divided up into logical volumes.

  1. Linear volume aggregates space from one or more physical volumes into one logical volume, usage logs and provide most storage. ''' lvcreate -n lvData -l 100%FREE vgData lvs # Display logical volume information '''
  2. Striped logical volume improve the efficiency of data I/O for large sequential reads and writes
lvcreate -n lvData -l 100%FREE -i2 -I64 vgData          # -i denotes the number of stripes, depends on number of disks
                                                        # -I64 denotes 64KB
lvdisplay
  1. Mirror Logical Volumes Data is written to both disk identically as data is mirrored.
lvcreate -n lvData -l 100%FREE -m1 vgData       # two disks mirror with default unit size 512KB

Add New Disk - Logical Volume (LvM) Quick Steps

1. pvs           # verify physical volume information, useful for scriptinng

2 . Create physical volume
pvcreate /dev/sdb

3. Create volume group
vgcreate vgData /dev/sdb

4. Create logical volume with all available space
lvcreate -n lvData -l 100%FREE vgData

5. Conver/format logical partition to xfs file system
mkfs.xfs /dev/mapper/vgData-lvData

6. Update /etc/fstab to mount to a directory or mapper
/dev/mapper/vgData-lvData       /data   xfs     noexec,nosuid,nodev     0       0
Note: reboot to take effect

# Manaully mount (no persistent, loss on reboot)
mount /dev/vgData/lvData  /data         # mount to a directory
mount /dev/mapper/vgData-lvData /data   # mount to device mapper
More Detail - Logical volume (LVM)
1. fdisk -l     # list disk information
2. parted /dev/sdc      # Example the new disk is sdc
        type "print"    # see partition information
        mklabel gpt     # convert the disk to gpt
        yes             # accept the change
        unit TB/GB      # select size unit
        print           # verify the disk after change
3. fdisk -l     # verify the partition again
4. pvcreate /dev/sdc    # create physical volume
5. mkfs.xfs /dev/sdc -f     # format disk /dev/sdc
6. fdisk -l     # verify disk again
7. pvs /dev/sdc         # verify physical volume
        y       # confirm disk creation
8. pvs  # verify physical disk volume information
9. pvdisplay /dev/sdc   # display physical volume for /dev/sdc
10. vgcreate logs /dev/sdc  # create logical volume group namely "logs"
11. vgdisplay logs      # verify the volume group
12. lvcreate -n vol_logs_archive -l 100%FREE logs   # create logical volume name "vol_logs_archive"
13. lvs         # list the logical voumes for verification
14. lvdisplay logs/vol_logs_archive         # view vol_logs_archive logical volume information
15. mkfs.xfs /dev/logs/vol_logs_archive     # format as xfs for /dev/logs/vol_logs_archive logical volume
                Note: xfs only allow volume size increase, ext4 allow both increase and decrease
                If need to increase the size
                    lvextend –l  +100%FREE –r /dev/logs/vol_logs_archive
                    vgextend logs /dev/sdx      # To add /dev/sdx to volume group "logs"
16. blkid  /dev/logs/vol_logs_archive
        # Identify the UUID  (a non-changing attribute that unique identifies a formatted storage device) for fstab update
17. less /etc/fstab     # verify /etc/fstab mounts
18. lsblk       # Verify block disk and logical partition
                It now shows /dev/sdx  has lvm created  # lvm TYPE
19. mkdir -p /mnt/logs_archive      # Create mount point
20. Update /etc/fstab
UUID=<new /dev/sdx UUID>    /mnt/logs_archive   xfs defaults    0   0

21. lsblk -o Name,FSTYPE,SIZE,MOUNTPOINT        # show disk and partition information
22. less /etc/passwd    # Verify the required users for permission update
23. Grant required user 751 permission to the new logical volume /mnt/logs_archive
24. Change the owner and group owner for the new logical partition
    chown <loguser> /mnt/logs_archive
    chgrp <logusegroup> /mnt/logs_archive

* Troubleshooting if required
cat /proc/partitions
wipefs -a /dev/sdc      # wipe or clean the new disk if required

Increase Disk Size

https://linoxide.com/how-extend-resize-lvm-partition-linux/

The following process is an example to increase the disk by 50GB

1. Increse the disk from vCenter or Hyper-V
2. ssh to the system, run
        lsblk   # verify all physical disks, /dev/sda, /dev/sdx

2. Reboot computer to take effect, so able to see disk size increase
        echo “---” /sys/class/scsi_host0/scan   # try to scan without reboot computer
        or
        echo 1 > /sys/class/block/sd<x>/device/rescan
                # need to rescan on all disks that have disk size increase
3. fdisk -l     # Verify the disk size warning
        Note:   a) it will show Disk /dev/sda:   150GiB      # additional 50GiB has added
                b) Disk /dev/mapper/rhel-var_log    10GiB   # show the initial partition size

Note: Step 4) and step 5) for non logical disk 
4. cfdisk   # run cfdisk utility to extend /dev/sda3
        select /dev/sda3
        choose Resize
        select Write    # write/commit change
5. run parted
        type print      # verify partition table for size change


6. pvresize -v /dev/sda3    # resize the physical volume for /dev/sda3
        Note:
        Need to resize for all increased disks
7. pvscan       # rescan for change
8. lvextend –l +100%FREE /dev/mapper/rhel-var_log   # extend the logical parition for /var/log
9. lvs      # verify change, it shows /dev/sda3 has increased by 50GiB
10. xfs_growfs -d /dev/mapper/rhel-var_log         
    # grow xfs partition
    # This step is important, otherwise "df -h" will not see disk space changes
11. df -h   # verify partition size change

# Analysis disk, volume group and logical volume size
Run the following command to verify before and after logical volume increase
pvs
vgs
lvs
df -h

pvdisplay
vgdisplay
lvdisplay

If required, run vgextend to extend volume group, then
        run lvextend to extend logical volume

Finally, run xfs_growfs to grow xfs format disk, when format using following command
        mkfs.xfs /dev/mapper/rhel-var_log

Simple way to extend or increase a specific drive

# Steps
1. From vCenter, increase the disk size
2. Verify device name and mount point
        lsblk
                # Verify and note down sdx, vdx for the required disk
                # The folowing example is sdd

        sdd                      8:48   0  200G  0 disk
        └─pvdata-lvbackup        253:5    0  200G  0 lvm  /apps/myapp/backup
3. Enable rescan the required disk (sdd)
        sudo echo 1 > /sys/class/block/sdd/device/rescan
4. Run pvresize to increase the physical volume
        pvresize -v /dev/sdd
5. Run pvscan to verify
        pvscan
6. Extend the logical volume
        lvextend -l +100%FREE /dev/mapper/pvdata-lvbackup
7. Extend the xfs file system
        xfs_growfs -d /dev/mapper/pvdata-lvbackup
8. Verify
        df -Th

Useful Disk and File System Commands

lvscan  # scans for all logical volumes
vgscan  # scan all disks for volume groups and rebuild LVM cache file
pvscan  # scan all LVM block devices for physical volumes

df -T   # Display file system type
df -h   # Display all file sytems in GB
df -m   # Display all file systems in MB

vdf -h | grep -B 1 root    # Verify free space in the root partition
vdu -h /<path>/<filename>  # verify file size

du -h   # Display folder and sub-folder usage
du -sh  # Display summary (total) disk usage of an directory
du -ah  # display all files and folders disk usage
du -ch  # Display total at the last line
du -sch

du -ha --time   /<dir>  # Display disk usage based on modification time

ls -al --full-time
ls -r /var/log  # list file size in reverse order
ls *.gz -sch   
find . -name "*.gz" | xargs du -sch 

find / -xdev -szie +10240k      # list file size > 10240k in the root partition

How to delete LVM volumes (RHEL/Centos)

https://www.thegeekdiary.com/centos-rhel-how-to-delete-lvm-volume/

If the non-root LVM volume, Volume Group, and Physical Volume used for the LV are no longer required on the system, then it could be removed/deleted using following steps.

1.  verify the logical volume
        lvs     # From the output, note down the logical volume, such as data01
2. Verify LVM disk usage
        df -hP | grep -i data01
3. delete the mount point entry in /etc/fstab
        # cat /etc/fstab
        ...
        /dev/mapper/datavg-testlv     /data01      ext4    defaults        0 0
4. umount the mount point
        umount /data01
5. disable LVM volume
        lvremove /dev/datavg/testlv
6. delete lvm volume
        lvremove /dev/datavg/testlv
7. disable volume group
        vgchange -an datavg
8. delete volume group
        vgremove datavg
9. delete the physical volume being used for the volume group
        pvremove /dev/sdb  /dev/sdc     
        # if the volume group is created by two physical disks

How to identify a specific physical disk in a server with many disks

# lsblk -a -o name,model,size,serial

Example
        NAME         MODEL             SIZE SERIAL
        sdh          ST8000DM002-1YW1  7.3T ZA11A1W3

Other useful commands

# To determine whick hdd is plugged into which port
lsscsi -g

Then, use lsscsi to get the list of ports on your MB that correspond to the above devices
lsscsi -H
   or

lsscsi --verbose

# lshw tells which port a particular hdd is plugged into
lshw -c disk -c storage
        # -c    class

        Note:
        It will show all disks
        lshw -class disk | grep -A 5 -B 5 sda   # only show /dev/sda disk information

# smartctl - Query each device independently to find out serial number and other info
smartctl -i /dev/sd<x>


#****** lsblk - list disks
lsblk -f        # list disk with "-f" file systems info
                # shows name, fstype, UUID, Mountpoint

fdisk -l        # list all partitions as well as disks
        fdisk -l /dev/sdx

fwinfo --disk   
     fwinfo --disk --short      # short and consise disk info

# For advanced system admin
ls -l /dev/disk         # look at /dev/disk folder
ls -l /dev/disk/by-id

Match Linux SCSI devices sdx to virtual disks in VMware

https://www.unixarena.com/2015/08/how-to-map-the-vmware-virtual-disks-for-linux-vm.html

https://www.virten.net/2015/08/match-linux-scsi-devices-sdx-to-virtual-disks-in-vmware/

In the vSphere client, the SCSI ID is displayed in the virtual machine configuration

# Example
SCSI (0:4) Hard disk 5

Use PowerCLI to get list of devices with their SCSI ID

$vm="testsrv01"
$vmview = Get-View -ViewType VirtualMachine -Filter @{"Name" = $vm}

foreach ($VirtualSCSIController in ($vmview.Config.Hardware.Device | where {$_.DeviceInfo.Label -match "SCSI Controller"})) {
        foreach ($VirtualDiskDevice in ($vmview.Config.Hardware.Device | where {$_.ControllerKey -eq $VirtualSCSIController.Key})) {
 Write-Host SCSI" ("$($VirtualSCSIController.BusNumber):$($VirtualDiskDevice.UnitNumber)")" $VirtualDiskDevice.DeviceInfo.Label
 }
}

Determine SCSI ID from Linux

# Determine SCSI ID from device names in Linux (/dev/sdx)
ls -d /sys/block/sd*/device/scsi_devices/*

# You can see the the device name, and 4 numbers a:b:c:d
a = Hostadapter ID
b = SCSI channel
c = Device ID   <---- Linux device ID
d = LUN

Device ID is always c

# To have output more cleanly
ls -d /sys/block/sd*/device/scsi_device/* |awk -F '[/]' '{print $4,"- SCSI",$7}'
        Example output
        sda - SCSI 0:0:0:0
        sdb - SCSI 0:0:1:0

# dmesg
dmesg |grep -i attached  |grep disk
        [ 1.465282] sd 0:0:1:0: [sdb] Attached SCSI disk        # example
        # VMware SCSI ID is 0:1

In some cases(RDM disk are assigned to VM) , the above mapping is not sufficient to map the VMware guest disks. You might require another validation prior to confirming the disk mapping.

# look at the “sgx” numbers at the output
dmesg |grep sg |grep Attached
        [   10.220942] sd 0:0:0:0: Attached scsi generic sg0 type 0     # example

Important
        The “sgX” numbers will be always stays in the “N-1” to the VMware disk numbers

How to change the RHEL partition size without change disk size

There are times that we are required to change the partition size and the physical disk size if fixed as the servers is physical server.

  1. Need to access the server console either via iLO, iDRAC or Hitachi BMC, and click remote console.
  2. Reboot the RHEL server, and Example
# Prerequistie
1. Attach RHEL ISO to the VM
2. Reboot the VM, and during the GRUB2 boot screen
3. Press "e" key and edit the selected kernel (select the first line, first option)
4. Depending on the RHEL version, find the link starts with "linux16" or "linux", navigate to the end
   of the line, and append "single"
5. Press Ctrl + x to continue
6. Enter the root password

# Total disk size is 240GB
Before change               After change
/               25              25
/home           10              10
/tmp            30              10
/var            50              25
/var/log        25              10
/var/log/audit  10               5
                                /opt    25      # new partition

# verify all partitions
lsblk           # check the partition table

# Resize /tmp by shrinking the size
umount /tmp
lvremove /dev/mapper/rhel_rhel01-tmp
lvcreate -n tmp -L 10G rhel_rhel01      # Create new logical volume name tmp with 5GiB size
mkfs.xfs /dev/mapper/rhel_rhel01-tmp    # Format the logical volume using xfs format
mount /tmp

# Resize /var/log/audit & Copy the contents back, and fix SELinux permission
umount /var/log/audit
lvrename rhel_rhel01  var_log_audit   var_log_audit2
lvcreate -n var_log_audit  -L 5G rhel_rhel01
mkfs.xfs /dev/mapper/rhel_rhel01-var_log_audit
mount /var/log/audit
mkdir /mnt/a
mount /dev/mapper/rhel_rhel01-var_log_audit2   /mnt/a
cp -pr  /mnt/a/*   /var/log/audit       # copy all files and directories back
restorecon -R  /var/log/audit           # Fix SELinux permission
umont /mnt/a
lvremove /dev/mapper/rhel_rhel01-var_log_audit2         # delete the old partition

# Resize /var/log & Copy the contents back, and fix SELinux permission
umount /var/log/audit
umount /var/log
lvrename rhel_rhel01  var_log   var_log2
lvcreate -n var_log  -L 10G  rhel_rhel01
mkfs.xfs /dev/mapper/rhel_rhel01-var_log
mount /var/log
mount /dev/mapper/rhel_rhel01-var_log2  /mnt/a
cp -pr /mnt/a/*  /var/log
restorecon -R /var/log
umount /mnt/a
lvremove /dev/mapper/rhel_rhel01-var_log2
mount /var/log/audit

# Resize /var
umount /var/log/audit
umount /var/log
lvcreate -n var2 -L 25G rhel_rhel01
mkfs.xfs /dev/mapper/rhel_rhel01-var2
mount /dev/mapper/rhel_rhel01-var2  /mnt/a
cp -pr /var/*   /mnt/a
rm -r /mnt/a/log/*
sed -i `/var  /s/var/var2/`   /etc/fstab
shutdown -r now         # Reboot to have the system partitions fixed before create new partition /opt

# Create /opt
restorecon -R  /var
lvremove  /dev/mapper/rhel_rhel01-var   # remove the old /var partition
lvcreate -n opt  -L 25G  rhel_rhel01
mkfs.xfs  /dev/mapper/rhel_rhel01-opt
mount /dev/mapper/rhel_rhel01-opt  /mnt/a
mv /opt/<existing-folder>   /mnt/a
vi /etc/fstab   # update /etc/fstab with /opt mount point
umount /mnt/a
mount /opt
restorecon -R /opt

## Veriyf /etc/fstab
/dev/mapper/rhel_rhel01-opt     /opt    xfs     nosuid  nsuit   0       0
/dev/mapper/rhel_rhel01-tmp     /tmp    xfs     nosuid  nsuit   0       0
/dev/mapper/rhel_rhel01-var2     /var    xfs     nosuid  nsuit   0       0
/dev/mapper/rhel_rhel01-var_log     /var/log    xfs     nosuid  nsuit   0       0
/dev/mapper/rhel_rhel01-var_log_audit     /var/log/audit    xfs     nosuid  nsuit   0       0
How to increase partition size - Non boot disk partition
# Prerequistie
1. Attach RHEL ISO to the VM
2. Reboot the VM, and during the GRUB2 boot screen
3. Press "e" key and edit the selected kernel (select the first line, first option)
4. Depending on the RHEL version, find the link starts with "linux16" or "linux", navigate to the end
   of the line, and append "single"
5. Press Ctrl + x to continue
6. Enter the root password

# System partions, such as /var, /tmp partition increase will be increased differently than data partition
1. lsblk        # verify sda, sdx  disk size, may need to increase the disk space first
2. In VMware, increase the disk size, such as sda (OS disk)
3. Reboot the server, or type the command to increase the disk
   echo 1 > /sys/class/block/sda/device/rescan  # rescan the disk to take effect
4. lsblk        # verify to ensure the sda has been increased
5. fdisk -l     # list all partitions
                # get /var partition mapping and size, compare with lsblk
                # /dev/mapper/rhel-var
5. cfdisk /dev/sda      # To resize
        select  "Resize"        on the sda2
        select  "Write"         to commit change

Alternative
   parted       # using parted
   print        # verify disk size and allocation
   print free   # Verify free disk space
                Note down the "End" of the free space, such as 215GB
                This will be used for the resize size
   resizepart   # resize partition
        3       # sda3          # Enter the partition number, /dev/sda3     if need to resize sda3
        <total size>GB          # type the total size GB
   print free   # verify the disk after resize   
   quit         # exit parted      
6. lsblk        # verify size to ensure it has been updated
7. pvresize -v /dev/sda2        # resize sda2   example
8. df -Th       # verify file type for /dev/mapper/rhel-var     "xfs" or other file system type
8. xfs -growfs -d /dev/mapper/rhel-var          # grow xfs file system
9. df -Th       # verify /var partition to ensure it has been increased
How to change partition size - boot disk partition

When need to increase or change partition in boot disk, if the partition has mount point under the subfolder of the partition, such as /var/log/audit, then need to umount the mount point in the subfolder too.

# Prerequistie
1. Attach RHEL ISO to the VM
2. Reboot the VM, and during the GRUB2 boot screen
3. Press "e" key and edit the selected kernel (select the first line, first option)
4. Depending on the RHEL version, find the link starts with "linux16" or "linux", navigate to the end
   of the line, and append "single"
5. Press Ctrl + x to continue
6. Enter the root password

# Assume the the following partition table
Name                    Size    Type    Mountpoint
--------------------------------------------
sda
  sda1                  600M    part    /boot/efi
  sda2                  1G      part    /boot
  sda3                  200G    part
     rhel-root          10G     lvm     /
     rhel-swap          4G      lvm     [swap]
     rhel-var_log_audit 5G      lvm     /var/log/audit
     rhel-var           45G     lvm     /var
     rhel-home          5G      lvm     /home
     rhel-tmp           50G     lvm     /tmp
     rhel-var-log       50G     lvm     /var/log

# Verify partition, volume group and logical volume
lsblk   # verify partition
vgs     # verify volume group
lvs     # verify the logcial volume
ls -l /dev/mapper       # verify logical volume

# Resize /tmp
umount /tmp
lvremove /dev/mapper/rhel-tmp
lvcreate -n tmp -L 15G rhel     # create "tmp" logical volume with 15G size
mkfs.xfs /dev/mapper/rhel-tmp   # format "tmp" with xfs format
mount /tmp                      # mount /tmp

#************* Rezie /var/log, /var/log/audit
# **** Method 1
# resize audit partition
umount /var/log/audit
lvrename rhel var_log_audit var_log_audit2      # rename var_log_audit logical volume
lvcreate -n var_log_audit -L 5G rhel            # create new var_log_audit logical volume
mkfs.xfs /dev/mapper/var_log_audit
mount /var/log/audit                            # mount /var/log/audit

mkdir /mnt/a            # create a temporary directory
mount /dev/mapper/rhel-var_log_audit2  /mnt/a   # mount the old var_log_audit to /mnt/a
cp -pr /mnt/a/*  /var/log/audit                 # copy all file and folders to the new audit partition
restorecon -R /var/log/audit                    # run restorecon, to reset the security context (type) (extended attributes)
umount /mnt/a                                   # umount /mnt/a
lvremove /dev/mapper/rhel-var_log_audit2        # remove the old audit logical volume

# resize /var/log partition
umount /var/log/audit                   # need to umount sub directory mount
umount /var/log
lvrename rhel var_log var_log2          # rename logical volume
lvcreate -n var_log -L 15G rhel         # create new var_log logical volume
mkfs.xfs /dev/mapper/rhel-var_log
mount /var/log
mkdir /var/log/audit                    # create /var/log/audit directory for mount point
mound /var/log/audit                    # remount /var/log/audit

mount /dev/mapper/rhel-var_log2 /mnt/a  # mount the old var_log to /mnt/a
cp -pr /mnt/a/*  /var/log               # copy all files and folders from old var_log to new "var_log"
restorecon -R /var/log                  # run restorecon
umount /mnt/a
lvremove /dev/mapper/rhel-var_log2      # remove the older var_log2 logical volume


# ****** Method 2
# resize audit partition
mkdir /tmp/a /tmp/b                     # create temporary directory for to store /var/log, and /var/log/audit files and folders
cp -pr /var/log/*  /tmp/a               # copy all file and folders in /var/log to /tmp/a
cp -pr /var/log/audit/*  /tmp/b         # copy all file and folders in /var/log/audit to /tmp/b

ls -l /tmp/a
ls -l /tmp/b                            # verify all files and folders have been saved

umount /var/log/audit
umount /var/log                         # umount both parititions

lvremove /dev/mapper/rhel-var_log       # remove var_log logical volume
lvcreate -n var_log -L 15G  rhel        # re-create var_log logical volume
mkfs.xfs /dev/mapper/rhel-var_log       
mount /var/log                          # mount /var/log again
mkdir /var/log/audit

cp -pr /tmp/a/*  /var/log               # copy /var/log file and folders back (restore files and folders)
cp -pr /tmp/b/*  /var/log/audit

restorecon -R /var/log
restorecon -R /var/log/audit

ls -l /var/log
ls -l /var/log/audit                    # verify the files and folders have been restored

rm -rf /tmp/a/
rm -rf /tmp/b/                          # delete the tempoary copy of the file and folders