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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Join Greg Farro and Ethan Banks from Packet Pushers ( and Greg Ross from Paessler ( for a discussion about smart network …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

737 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