Quick HOWTO: Reduce SWAP Partition Online without reboot in Linux

Recently I had a request to reduce the swap space and allocate that space to some other LV in one of our server.  Below is what I followed and it perfectly worked for me.  :)

Make sure you have enough physical memory to hold the swap contents. 

Now, turn the swap off:
# sync
# swapoff <YOUR_SWAP_PARTITION>
Now check the status
# swapon -s 

Then, Use fdisk command:
# fdisk <YOUR_HARDDISK_Where_SWAP_Resides>
List partitions with "p" commandFind Delete your partition with "d" commandCreate a smaller Linux-Swap partition with "n" commandMake sure it is a Linux-Swap partition (type 82) (Change with "t" command)Write partition table with "w" command


Run "partprobe" to update Filesystem table to kernel. (It is very important before proceeding further)

Then,
mkswap <YOUR_NEW_SWAP_PARTITION>
swapon <YOUR_NEW_SWAP_PARTITION> 
check to make sure swap is turned on
swapon -s 
Now you can use your free space to increase space for other Logical volumes (LV). 

Use fdisk command to create new partition, then 

# partprobe
# pvcreate <NEW_PARTITION_YOU_CREATED>
# vgextend <VG_TO_INCREASE> <YOUR_NEW_PV>
# lvextend -L  +SIZE_TO_INCREASE <LV_NAME> 

Note: It is extreme importance of syncing and turning the swap off before you change any partitions. If you FORGET TO DO THIS, YOU WILL LOST_DATA!!

Create RAID Disk using hpacucli in Linux


1. CHECK UNASSIGNED DRIVES THAT CAN BE USED 

server1:~ # hpacucli
HP Array Configuration Utility CLI 8.70-8.0
Detecting Controllers...Done.
Type "help" for a list of supported commands.
Type "exit" to close the console. 
 => hpacucli ctrl all show config 

Smart Array P400 in Slot 9 (sn: P61XXXXXXXXXN)
 array A (SAS, Unused Space: 0 MB)
 logicaldrive 1 (68.3 GB, RAID 1+0, OK)
 physicaldrive 1I:1:1 (port 1I:box 1:bay 1, SAS, 72 GB, OK)
 physicaldrive 1I:1:2 (port 1I:box 1:bay 2, SAS, 72 GB, OK)
 unassigned      
 physicaldrive 1I:1:3 (port 1I:box 1:bay 3, SAS, 146 GB, OK)  
 physicaldrive 1I:1:4 (port 1I:box 1:bay 4, SAS, 146 GB, OK) 

Note: Last two drives in the output are free and we gonna use them to create RAID  


2. NOW WE ARE GOING TO CREATE RAID 1+0 DISK ARRAY 

=> hpacucli ctrl slot=9 create type=logicaldrive drives=1I:1:3,1I:1:4 raid=1

3. VERIFY THAT THE DISK ARRAY WAS CREATED 

hpasmcli> hpacucli ctrl all show config
 Smart Array P400 in Slot 9 (sn: P61XXXXXXXXXN)
 array A (SAS, Unused Space: 0 MB)
 logicaldrive 1 (68.3 GB, RAID 1+0, OK)
 physicaldrive 1I:1:1 (port 1I:box 1:bay 1, SAS, 72 GB, OK)
 physicaldrive 1I:1:2 (port 1I:box 1:bay 2, SAS, 72 GB, OK)
 array B (SAS, Unused Space: 0 MB)   ß NEW DISK ARRAY
 logicaldrive 2 (136.7 GB, RAID 1+0, OK)
 physicaldrive 1I:1:3 (port 1I:box 1:bay 3, SAS, 146 GB, OK)
 physicaldrive 1I:1:4 (port 1I:box 1:bay 4, SAS, 146 GB, OK) 


VERIFY NEW DISK DRIVE WAS CREATED IN OS LEVEL (LINUX)

server1# cat /proc/driver/cciss/cciss0
cciss0: HP Smart Array P400 Controller
Board ID: 0x3234103c
Firmware Version: 5.20
IRQ: 74
Logical drives: 2
Sector size: 2048
Current Q depth: 0
Current # commands on controller: 0
Max Q depth since init: 9
Max # commands on controller since init: 331
Max SG entries since init: 31
Sequential access devices: 0
cciss/c0d0:       73.37GB       RAID 1(1+0)
cciss/c0d1:       146.7GB       RAID 1(1+0)



server1# fdisk -l | grep cciss
Disk /dev/cciss/c0d0: 73.3 GB, 73372631040 bytes
Disk /dev/cciss/c0d1: 146.7 GB, 146778685440 bytes

Solution for UNIX Error: Terminal too wide


When you are working in an UNIX shell using Putty tool, you may get this error.

Problem: 

When you are trying to open vi editor, you may get error message "Terminal too wide"

How to Fix this??

Enter the below command in the shell and try to open vi editor again. It will work.


stty columns 120

Hope this will help on someone.