7

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?

7 Answers 7

2

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.

4

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.

3

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.

2

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.

1
  • Actually, you're right /dev/sdc is the usb device.
    – sal
    Apr 30, 2009 at 18:57
1

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
1
  • You can merge them, say moving /home to /opt/home and then ln -s /opt/home /home Apr 30, 2009 at 20:56
0

This could work:

# copy files preserving attributes
cp -Rp /home /opt # --recursive --preserve

# comment out old /home entry
perl -pie'$_ = "#$_" if m[/home]' /etc/fstab 

# add a bind entry to the end of fstab
echo /opt/home  /home  none  bind >> /etc/fstab


# unmount both partitions
umount /home
umount /opt

# remove original /home partition
# resize /opt partition to use the freed space


# could also just restart here
mount /opt
mount /home

You will either need to append sudo to each line, or run as root   [sudo bash].

0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .