We recently bought a couple HP blade servers. Two of the server have RHEL AS 4 as OS, and will be hosting our HR application. After one and a half day session of up2date, the two RHEL installation are updated.
..And came the bad news. Apparently the HR application requires a much larger space for installation than previously thought. So I was told to do anything necessary to make the requires space auto-magically exist.. sort of..
My plan is to move some folder from their respective partitions, and merge the into one single large partition. The only available option for that is to move my /usr and /var to “root” (/), user the space for the installation. The merging part can easily be done using LVM2. That wasn’t the case for migrating /usr /var. To do that I have to make sure that all security settings and symlink are preserved.
Now, after searching for sometime on google for hints, this is what I do:
Prepare the new partitions
In my case, this is simply my “/” partitions, so what i really do is just create a new folders on “/”. If you want to move the folders to new partitions, you can use tools like gparted to help you.
Backup the /usr and /var partitions
I have several options on how to do this. The first one is just to tar both of the folders, since with root privileges, tar will preserve every attributes of the folder. Or I can boot up the server in rescue mode using the installation CD, and use mv to move them out of the way. Instead i choose to move them by copying. Create folders to backup the content of /usr and /var on the target partitions, in my case it the “/” partition.
#mkdir /var1 #mkdir /usr1
If you’re planning to relocate the folders to new partitions, you can label and mount them on these folders.
#e2label /dev/hda5 /var1 #e2label /dev/hda6 /usr1 #mount /dev/hda5 /var1 #mount /dev/hda6 /usr1
Copy the content of both folders to their respective backup target
cd /var find . -depth -print0 | sudo cpio --null --sparse -pvd /var1 cd /usr find . -depth -print0 | sudo cpio --null --sparse -pvd /usr1
The command above will copy your existing /usr and /var to their respective backup folder, while maintaining all the original attributes. Now we’re ready to replace both of the folders
Replacing the folders
Backup your /etc/fstab file so that you can roll back your change easier.
#cd /etc #cp fstab fstab.bk
Edit /etc/fstab so that /usr and /var partition are not mounted on the next reboot. Open your fstab file by issuing
Comment any line that refers to /var and /usr. This is how my fstab files looks like:
LABEL=/ / ext3 defaults 1 1 none /dev/pts devpts gid=5,mode=620 0 0 none /dev/shm tmpfs defaults 0 0 LABEL=/home /home ext3 defaults 1 2 none /proc proc defaults 0 0 none /sys sysfs defaults 0 0 LABEL=/tmp /tmp ext3 defaults 1 2 #LABEL=/usr /usr ext3 defaults 1 2 #LABEL=/var /var ext3 defaults 1 2 LABEL=SWAP-cciss/c0d0p swap swap defaults 0 0
Reboot your system using rescue mode with your install CD, or a live cd. On RHEL machine, press F5 on the first screen, and type “linux rescue” at the prompt. When asked if you want to mount your installation as read-write, press “Continue” so that you can make changes to your installation in rescue mode. your installation will be mounted on /mnt/sysimage.
Get inside the installation by issuing
and make sure that /mnt/sysimage/usr and /mnt/sysimage/var are empty
As I mentioned above, in my case, I would like to move /var and /usr to root (/), so what I do is I just simply delete /mnt/sysimage/var and /mnt/sysimage/usr, and rename /mnt/sysimage/var1 and /mnt/sysimage/usr1 to /mnt/sysimage/var and /mnt/sysimage/usr. The
command should be like these:
mv /mnt/sysimage/var1 /mnt/sysimage/var
mv /mnt/sysimage/usr1 /mnt/sysimage/usr
Since /var and /usr is now technically under “/”, all I have to do are making sure that /var and /usr are not mounted on a partitions and simply reboot my system. If you’re going to replace the partitions with new ones, you can open the fstab file, and edit them so that it will mount the new partitions as /var and /usr respectively. Open fstab by typing:
Point /var and /usr to their new partition. Mine will look like this:
LABEL=/ / ext3 defaults 1 1
none /dev/pts devpts gid=5,mode=620 0 0
none /dev/shm tmpfs defaults 0 0
LABEL=/home /home ext3 defaults 1 2
none /proc proc defaults 0 0
none /sys sysfs defaults 0 0
LABEL=/tmp /tmp ext3 defaults 1 2
LABEL=/usr1 /usr ext3 defaults 1 2
LABEL=/var1 /var ext3 defaults 1 2
LABEL=SWAP-cciss/c0d0p swap swap defaults 0 0
Save the changes, and reboot. The changes will be active the moment we reboot the system.
After all the steps above the installation should be using/var and /usr on the new area. I need keep the old partitions intact until I’m sure that everything is working properly. You can try running applications that is installed under /usr/bin to check if it’s ok.
If rollback is needed the, simply reboot the system into rescue mode again, and undo the changes from fstab by:
cp fstab fstab.bk2
mv fstab.bk fstab
And reboot the system. /usr and /var should be mounted on the old partitions.
This method should work for different folders. I decided to move /home and /tmp using the same steps, and it works flawlessly