1. Introduction (Moving /opt data to a new partition)
The partition /opt is one of the most-often-moved partitions Because Linux Installs Third Party Software in /opt Directory. For Example Zimbra, Scalix.. So there is Disk Space Issue Occurs after Log Period
Some Times All Space On /opt Becomes Full and Your Application’s Performance Becomes Poor. In That Case you need an additional Harddrive or a Partition That Contains Big Space to Moved
In This Article I Will Show You How to Transfer Your /Opt Data to New Harddisk or Another Partition
Add New Hard Disk onto Your Server
When You Attach New Hard Drive on Server, It Will recognized as /dev/sdb.
Your First Hard Drive should be /dev/sda
2. Create new partition on your new hard drive with fdisk command:
fdisk /dev/sdb
Press n for Create a New Partition
This Will Ask For Primary or Extended Partition
Press p for Primary Partition
Press Enter for Default Setting in cylinder Size of Partition
Type the Size of the Partition That You Want To Allocate To Your New Partition
For Example: +80000M
This Will Create 80 GB New Primary Partition in to Your New Hard Drive
Press w for Save the Settings
Type partprobe Command to update The Kernel about newly added Partition
Now Format the Partition Using ext3 File System So That We Can Use Partition
mkfs –t ext3 /dev/sdb1
You Can Check Newly Created Partition Status Using fdisk –l Command . This Command Will Give You the Status of All the Partition
3. Mount the new file system in /mnt
Create a directory called /mnt/newopt, and then mount the new partition there:
# mount /dev/sdb1 /mnt/newopt
4. Drop to single-user mode
You must go To Single User Mode to Copy All Data in /opt to /mnt/newopt. You shouldn’t have any files open in /home, and entering single-user mode eliminates this possibility:
#Init 1
5. Change directories to /home and copy files
Type The Following
# cd /opt
# cp -avx * /mnt/newopt
The cp -avx command recursively copies the contents of /home to /mnt/newpopt, preserving all file attributes.
After this command finishes, /mnt/newopt will contain an exact copy of all the files and directories currently in /opt.
6a. If you installed /opt on separate partition then follow below steps
Unmount the old partition by typing:
# cd /
# Umount /opt/
Then, unmount and remount the new partition:
# umount /mnt/newopt
# mount /dev/sdb1 /opt
Now, the new partition is available at /opt and is ready to be used. We can perform the last few steps in multiuser mode. Exit single-user mode, so that the system is back up and running Type: init 5
Add This Entry To /etc/fstab File
/dev/sdb1 /opt ext2 defaults 1 2
6b. If you installed /opt on shared partition then follow below steps
These instructions are for systems where the old /opt is on a shared partition.
# cd /
# mv /opt /opt.old
# mkdir /opt
# mount /dev/sdb1 /opt
Add This Entry to /etc/fstab File
/dev/sdb1 /opt ext2 defaults 1 2
That way, your new partition will get mounted correctly the next time the system is rebooted.
We left the old /opt directory/partition behind, just in case there were problems copying files. After verifying that the system is running smoothly, you can remove the /opt.old directory.