how to merge two ext3 partitions on ubuntu from command line?
I have a partition /dev/sdb1
and a partition /dev/sdb2
They are both in /etc/fstab
with proper UUIDs and mounted as /opt
and /home
I'd like to merge them without losing any files
Can this be done from the command line without having to move all the files?
Not that I'm aware of although you could delete one partition and resize the other: http://www.howtoforge.com/linux_resizing_ext3_partitions
Obviously for that to work you'd have to have enough space to store the data in one partition elsewhere however.
No, you'll have to move the files.
Even then you still have an issue: you'd have to mount the partition as "/home" and symlink "/home/opt" to /opt.
When you say merge, I take it you want to have one file system that can use all the space currently allocated to /opt and /home? The only "right" way I know how to do this is recreate the partitions, make them part of a LVM physical volume, and create a logical volume on top of it.
Do you just need to borrow space that's allocated to one and use it in the other? You can use mount --bind
if you don't want to use symlinks.
Are you sure it is /dev/sdb and /dev/sdc? By convention /dev/sdb and /dev/sdc are individual disks and not partitions on a disk. Disk partitions typically have a number associated with them (i.e. /dev/sdb1, /dev/sdb2, /dev/sdc1, etc). You cannot merge partitions on separate physical hard drives, you have to move the data from one to the other.
As has already been said by others, it's not really possible to merge them. You'd have to move the data and resize the partitions appropriately.
You can't merge /opt
and /home
without also having one inside of the other.
For example /home
-> /opt/home
.
Then you could do ln -s /home /opt/home.
or better yet: mount --bind /opt/home /home
or fstab entry is: /opt/home /home none bind
I have actually added the following to my /etc/fstab
file. (actually my real one uses the UUID of the partion instead of [/dev/sdb1
])
/etc/fstab
/dev/sdb1 /share ext3 noatime,errors=remount-ro 0 1 /share/home /home none bind