Linux Unix help !!

"Give respect to Time, One day at right Time, Time will respect You"

Monday, May 14, 2012

Create filesystem in a partition

One of my application creates un-necessary logs or dumps that fills my filesystem .
Say example I have only root partition "/" and other filesystems(/var/, /usr etc..) are in "/" .
Sometime one of my application creates lots of files and unwaned logs at path /var/log/mycore and that fills my root partition and my oher application stops working .

I want to give a permanent solution, but I have some limitations as below
- I don't have extra free disk block to create new partition
- I can't add any any new disk/LUN etc .
- I can't stop that application logging etc...

Here's solution that have applied on one of my server and it's working as am expected .

## Example
# df -h  /
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              72G   57G   12G  79% /

## I have 12 GB free space now check size of dir: /var/log/mycore
# du -sch /var/log/mycore
2G     /var/log/mycore
2G     total

## Okay now we have 2 way
1> Define quota .. but not preferred .
2> Create a filesystem with allocated space

## Am preferring to go with way-2 as below
As have 12G free space on "/", so I will allocate 3GB to /var/log/mycore as below

Step-1: Create a file usign dd with size 3GB
# dd  if=/dev/zero of=/var/log/FS_mycore bs=1024M count=3

Step-2: Create file system as per your requirement here am going with ext4
# mkfs.ext4  /var/log/FS_mycore

Step-3: Stop your application

Step-4:  Move /var/log/mycore  and create a new directory (Note: Reserve the permissions as original dir has)
# mv /var/log/mycore  /var/log/mycore_old
# mkdir  /var/log/mycore

Step-5: Mount and copy back all files and delete /var/log/mycore_old
# mount  -o loop  /var/log/FS_mycore  /var/log/mycore
# mount  -l


# df -h  /var/log/mycore/
Filesystem            Size  Used Avail Use% Mounted on
/var/log/FS_mycore    3.0G   68M  2.8G   2% /var/log/mycore/

# cp -rp  /var/log/mycore_old/* /var/log/mycore/

# cd  /var/log/mycore/ ; ls -lrth
# rm -fr  /var/log/mycore_old/

## Make entry in fstab
/var/log/mycore_old     /var/log/mycore         ext4    defaults,loop        0 0


##  Testing
# umount  /var/log/FS_mycore # mount -a
# mount -l 

## Step-6: Don't forget to start your application and check logs and all to verify all are okay ...

 


> Shirish Shukla

1 comment:

  1. Good day I am so thrilled I found your webpage, I really found you by
    accident, while I was researching on Digg for something else, Anyhow I
    am here now and would just like to say thank you for a fantastic post and a all round interesting
    blog (I also love the theme/design), I don’t
    have time to go through it all at the minute but I have
    saved it and also added in your RSS feeds, so when I have time I will be back
    to read a lot more, Please do keep up the superb
    jo.

    Feel free to surf to my blog post runder haarausfall
    My web site :: Haarausfall stoppen

    ReplyDelete

Write Here .. your comments are always wellcome ..but no spam please !!

Followers

Pls LIKE my Story !!!