Increasing Disk Space in CentOS using LVM

LVM (Logical Volume Manager) is a tool in Linux which can help you manage disk drives and partition. Usually it being used in server/computer whereby you can easily re-size the partition, creating snapshots backup, combined all hard disk to be run under one partition and many more.

In this case, I already have logical volume “/dev/mapper/VolGroup00-LogVol00” mounted as “/” partition in the server but the disk space is too small which is 50GB. I want to expand it to 170GB with another 120GB hard disk combine together. The new hard disk already plugged in the server and detected by the system. So we are going to do this online without downtime. Variables as below:

OS: CentOS 5.6 64bit
LV name: /dev/mapper/VolGroup00-LogVol00
New HD: /dev/sdb (120GB)

1. Make sure that you have logical volume mapped to your “/” partition. If you are using default CentOS partitioning during installation, you should see something like below:

[[email protected] ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       47G  3.2G   43.8G   8% /
/dev/sda1              99M   13M   81M  14% /boot
tmpfs                 249M     0  249M   0% /dev/shm

2. Check whether new hard disk has been detected on the system or not. It should be /dev/sdb:

[[email protected] ~]# fdisk -l
 
Disk /dev/sda: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        6527    52323705   8e  Linux LVM
 
Disk /dev/sdb: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
Disk /dev/sdb doesn't contain a valid partition table

3. This new hard disk does not have partition table yet. So we need to create one using fdisk:

[[email protected] ~]# fdisk /dev/sdb
......
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-15665, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-15665, default 15665):
Using default value 15665
 
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.

The sequence I press on the keyboard is: n > p > 1 > Enter > Enter > w > Enter

Continue reading “Increasing Disk Space in CentOS using LVM” »

FSniper – Monitor Newly Created Files in Directory

Fsniper is a good utility that waits for a file to be changed, then executes a command on that file. Means, whenever newly files created, we can do something with that files while fsniper returning the path and file name. From this, we can manipulate the result to execute another task like sending notification or move the files to specific folder based on MIME types.

Example of FSniper usage can be as follows:

  1. Categorize newly created files based on MIME into specified directory
  2. Notify system administrator that new files has been created via email
  3. Move or delete unwanted files based on extension from the directory that being watched
  4. Scan new files with ClamAV and send the results via email
  5. Much more, you can think by yourself

In this case, I was using following variables:

Server OS: CentOS 5.6 64bit
Directory to be watched: /home/user/public_html
Files being monitored: Images and text files
Action to be taken: Output it to another text files with date, time and files owner

Login into the server and do as follows:

1. Install dependencies via yum:

yum install pcre* file-libs file-devel -y
									

2. Download fsniper using wget. You can find the source at http://freshmeat.net/projects/fsniper :

wget http://projects.l3ib.org/fsniper/files/fsniper-1.3.1.tar.gz
									

3. Extract the downloaded files:

tar -xzf fsniper-1.3.1.tar.gz
									

4. Enter the directory, configure and install:

cd fsniper-*
./configure
make
make install
									

5. Fsniper is installed. Try to run it by executing following command:

fsniper --verbose
									

6. You will see some error telling you that it cant find the configuration files. So we need to build it. Stop the FSniper process by pressing ctrl+C

7. Create the config files under /root/.config/fsniper/ directory:

touch /root/.config/fsniper/config
									

Continue reading “FSniper – Monitor Newly Created Files in Directory” »