Changing Layout of partition in Linux


There was a requirement of porting some native applications running on FreeBSD Unix to Linux. These applications are written using C language and they  are using /home/app as their root directory. That means we are having   directories like /home/app/bin , /home/tmp , /home/app/sbin , /home/app/var etc on these FreeBSD hosts . These hosts were not running any well known internet services or any OS related application but running only our custom native applications.

Issues and Solutions:

These applications when ported to Linux are failing because of the layout of /tmp directory in Linux . /tmp was created as  a separate partition in our Linux hosts and our requirement was that we need a /tmp directory under /home partition for applications to run properly.  For directories under /home/app , we created the necessary directories based on similar layout of FreeBSD.
We decided to change the layout of /tmp directory of Linux without modifying the code.
The following are the concerns and solutions.
1. We need to umount the /tmp partition. That is easily doable without reboot of the host.
2. We need to create a tmp directory under /home partition with the same permission and ownership of /tmp. rysnc will help us to copy and preserve permission and ownership.
3. Create a symbolic link from /home/tmp to /tmp so that OS related programs which uses /tmp directory donot fail. X and mysql are some applications which creates it's lock file in /tmp directory.


The following are the steps we followed to change the layout of /tmp directory without any reboot of hosts.

1.  sudo rsync -avz /tmp  /home/  
   This will do the copy by preserving the permission and ownersip.

2.  sudo umount -l /tmp/
    Lazy umount helps to unmount the /tmp filesystem. Without the -l option , unmount was failing

3. sudo mv /tmp/  /tmp.old

4. sudo ln -s /home/tmp  /tmp

5.  To utilise the disk-space of original /tmp partition , we can mount that partition under a new directory . I did the following. 

6. sudo mkdir /tmp-temp

7. sudo mount /dev/sda6 /tmp-temp and  did the necessary modifications in /etc/fstab for this new partition.

Conclusion: The migration was done successfully and after that applications are running successfully on Linux . The purpose of writing this abstract , is that we can use the same method to change the layout of other partitions also. Hope this may be helpful to anyone who has a requirement like this.


Popular posts from this blog

How to add check_http as a service in Nagios Monitoring using NRPE

PSSH : Parallel SSH to execute commands on a number of hosts

Using lsof to identify deleted files: