Move Linux partition to new disk

Posted on 2007-04-03
Last Modified: 2013-12-15
Hi Experts,

I'm running Redhat Linux AS V4 on a DELL 6850.  The server has 2 RAID arrays - a RAID1 with 70GB and a RAID5 with 145GB.  I've installed the OS onto the RAID1 array (/dev/sda) - sda1 is boot and sda2 is LVM - and the RAID5 is /dev/sdb (nothing devices defined yet).

What I'm trying to do is move /opt from /dev/sda2 to the /dev/sdb disk.  What's the easiest way to do this?
Question by:iqaustralia
  • 3
  • 2
LVL 88

Expert Comment

ID: 18841715
Partition sdb, format it to your preferred filessystem, then copy /opt to the new partition. Rename the original opt to something like optorig, and now create a symlink called opt in / that points to the new opt folder.

You could also, if the partition you will be using for opt will only host opt, after copying the opt folder to the new partition, make a folder opt in /, then mount the new opt folder to that folder (add the entry to /etc/fstab and make sure it automounts at bootup). If you do it that way, you'll have to make sure you first enter the old /opt folder and copy those contents to the new partition (there should be no opt folder on that partition, or you'll end up with /opt/opt when the partition is mounted to the /opt folder).

Author Comment

ID: 18841732
Hi there,
Thanks for your quick response.  

I want to move the current /opt on /dev/sda to /dev/sdb and it will be the only folder in /dev/sdb.  I won't have an /opt in /dev/sda.  So, I think this is your second option.

Can you give me the commands to create the new partition in /dev/sdb, how to copy the existing /opt correctly, how to edit fstab and setup the automount?  Sorry, this is all new to me.
LVL 88

Expert Comment

ID: 18841782
As I hate typing and remembering commands, I always use the midnight commander to do such tasks. If it isn't already installed on your system, install it. Then open it with mc.

Now mount the newly created partition, then in one window pane of mc (you can move between panes with the tab key) navigate to the newly mounted partition (I usually create a mount point /mnt/sdb1, then us mount -t ext3 /dev/sdb1 /mnt/sdb1, if it is using the ext3 filesystem). Now use the tab key to make the other mc pane active. Select opt and press enter so you'll be inside /opt.

Now select all folders and files (select the first folder, press the ins key until all folders and files have been selected down to the bottom of the list, selected files and folders are usually marked yellow in a standard mc setup) and then press the F5 key to copy everything to /mnt/sdb1.

When that has finished, press enter at the top of the list so you'll be returned to the /folder. Move to the opt folder with the mc bar and press F6, then rename the folder to optorig.

Now create a new folder by pressing F7, and give it the name opt.

Now navigate to /etc/fstab, press F4 and you can edit the file. Add the following:

/dev/sdb1        /opt         ext3        defaults           0     0

and save the file by pressing F2

Then leave mc with F10 and unmount /mnt/sdb1, and mount it again using mount /dev/sdb1. If everything is OK it should now get mounted to /opt

Test it with rebooting, and after some testing and you know everything works, you can delete the /optorig folder.

Author Comment

ID: 18847491
Hi there,

I've got hold of MC, but how do I create the LVM partition and mount it?  Running the command fdisk -l shows the disk array with no partitions, so I first need to know how to create an LVM partition that occupies the entire disk array.
LVL 88

Accepted Solution

rindi earned 500 total points
ID: 18848798
I haven't used LVM so for that you'd need to read the man pages and readme's on LVM.

To create partitions you can use fdisk,

fdisk /dev/sdb

then use "n" to create the partitions. When done use "w" to commit the changes. After that you have the unformatted partition which you can format using

mke2fs -j /dev/sdb1

if it is going to use ext3 as the filesystem. For further filesystems check the gentoo handbook, it has very good instructions.

If you are using a GUI you could also partition and format the disk in one go using QtParted, which is included in most distro's.

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question