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?
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.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.
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
This could work:
You will either need to append
sudo
to each line, or run asroot
[sudo bash
].Merging is not feasible because some numbers, like inodes, are expected to be unique within a filesystem, but some will be repeated when you have two. Internal filesystem structures would conflict in the same way.
Absorbing a filesystem into another is theoretically feasible, but I don't think it has been attempted, because tools that cater to rare use cases have a higher risk of bugs, which can have fatal consequences. You would be required to make backups, and now that you have backups you don't need in-place conversion. If you wanted to implement this, the closest tool is btrfs-convert, which phagocites an ext4 filesystem by keeping both filesystems on the same partition, with the btrfs structures referring to the ext4 structures and copy-on-write ensuring that new files are btrfs-only.