Monday, December 19, 2016

Managing Swap space in Red Hat Linux

1. To extend a swap logical volume

a. Disable swapping for the concerned logical volume
# swapoff -v /dev/VolGroup00/LogVol05

b. Extend the logical volume by 1GB
# lvm lvresize /dev/VolGroup00/LogVol05 -L +1G

c. Format the logical volume
# mkswap /dev/VolGroup00/LogVol05

d. Enable the swap device
# swapon -va


2. To reduce a swap logical volume

a. Disable swapping for the concerned logical volume
# swapoff -v /dev/VolGroup00/LogVol05

b. Reduce the logical volume by 512MB
# lvm lvresize /dev/VolGroup00/LogVol05 -L -512M

c. Format the logical volume
# mkswap /dev/VolGroup00/LogVol05

d. Enable the swap device
# swapon -va


3. To list all the configured swap devices:

# cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/mapper/VolGroup00-LogVol05         partition       6062072 2180    -1


4. To list the total/used/free swap space:

# free -tm
             total       used       free     shared    buffers     cached
Mem:          7983       7918         65          0        585       4943
-/+ buffers/cache:       2389       5594
Swap:         5919          2       5917
Total:       13903       7920       5982


5. To create a swap file of size 100MB :

# dd if=/dev/zero of=/swap1 bs=1024 count= 102400
# chmod 0600 /swap1
# mkswap /swap1
# swapon /swap1

Finally add the below entry in /etc/fstab so that it enables on every boot.

/swap1          swap            swap    defaults        0 0


6. To enable swap space on a file :

# swapon -v /swap1


7. To disable swap space on a file :

# swapoff -v /swap1

Software RAID in Red Hat Linux

To create a linear RAID array:

# mdadm --create --verbose /dev/md0 --level=linear --raid-devices=2 /dev/sdb /dev/sdc
# mdadm --detail --brief /dev/md0 >> /etc/mdadm.conf


To create a striped RAID array (RAID-0):

# mdadm --create --verbose /dev/md0 --level=0 --raid-devices=2 /dev/sdb /dev/sdc
# mdadm --detail --brief /dev/md0 >> /etc/mdadm.conf


To create a mirrored RAID array (RAID-1):

# mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc
# mdadm --detail --brief /dev/md0 >> /etc/mdadm.conf


To start a RAID Array:

# mdadm --assemble /dev/md0 /dev/sdb /dev/sdc /dev/sdd

                                                    OR

# mdadm --scan --assemble --uuid=a26bf396:31389f83:0df1722d:f404fe4c


To list all software raid arrays and their component devices:

# cat /proc/mdstat
Personalities : [linear]
md0 : active linear sdd[0]
      10485752 blocks super 1.2 0k rounding

md1 : active linear sde[0]
      52428792 blocks super 1.2 0k rounding

unused devices:




 

To query a software raid array :

# mdadm --query /dev/md1
/dev/md1: 129.100GiB linear 1 devices, 0 spares. Use mdadm --detail for more detail.


To list details of a RAID array:

# mdadm --detail /dev/md1
/dev/md1:
        Version : 1.2
  Creation Time : Thu Dec 11 09:32:37 2011
     Raid Level : linear
     Array Size : 52428792 (50.00 GiB 53.69 GB)
   Raid Devices : 1
  Total Devices : 1
    Persistence : Superblock is persistent

    Update Time : Thu Dec 11 09:32:37 2011
          State : clean
 Active Devices : 1
Working Devices : 1
 Failed Devices : 0
  Spare Devices : 0

       Rounding : 0K

           Name : server123:1  (local to host server123)
           UUID : c5804771:253326af:e062f685:cab35fed
         Events : 0

    Number   Major   Minor   RaidDevice State
       0       8       32        0      active sync   /dev/sdc


To examine a RAID array:

# mdadm --examine /dev/md0


To add a raid disk device and extend a linear software raid array :

# mdadm --detail /dev/md3 | tail -n 3
    Number   Major   Minor   RaidDevice State
       0       8        1        0      active sync   /dev/sdc
       1       8       17        1      active sync   /dev/sdd

# mdadm --grow /dev/md3 --add /dev/sde


To remove a RAID array:

# mdadm --stop /dev/md3
# mdadm --remove /dev/md3
# mdadm --zero-superblock /dev/sdc /dev/sdd