2

I made a separate partition for /home, but during installation process I forgot to mount it and hence no entry was made in fstab.

I had everything in partition under the root ( well not the swap and efi system partition). I realised what I did, very late and by that time I had already installed packages and wrote data in the home directory.

Now what I want to know is “is there any way possible to move my home directory to a separate partition with out losing any data?

I was thinking of doing something like mounting the root directory in /mnt and than mount a new partition(for home) in /mnt/home from a liveUSB and than generate the fstab.

But I am like 79% sure that this will wipe out my home directory.

SPEC: Arch Linux x86_64 latest kernel (5.0.4)

Paradox
  • 1,369
  • 3
  • 13
  • 27
Just Khaithang
  • 412
  • 1
  • 5
  • 16

1 Answers1

0

Because you already have an home partition, we should be able to do this with out a live OS.

  • mount the new home on /mnt
  • move files from old-home (/home), to new home (/mnt). (/home should now be empty).
  • remount new-home to /home (bind mount sudo mkdir -p /home && sudo mount --bind /mnt /home (you can also use --move, in place of --bind), or unmount then mount).

It is not as you want, but the mount is not persistent.

  • edit /etc/fstab (There may be tools to help you with this, I can't remember).
ctrl-alt-delor
  • 27,473
  • 9
  • 58
  • 102
  • Will the installed packages turn out fine after this ? Because I have installed package in my home directory. Other files(music ,videos , text files ) will be okay I know , but the I am worried that this may render the environment variables of the software defunct. I am not sure though. – Just Khaithang Apr 06 '19 at 10:09
  • You need to do the move as root, to ensure that ownership info is not lost. However because it will all end up back in `/home` the environment variable will be OK. Just don't use any of these files **during** he migration. – ctrl-alt-delor Apr 06 '19 at 10:15
  • what if instead of move , I do copy? just asking. I mean will original files be erased ? or I will end up with two home directory,? – Just Khaithang Apr 06 '19 at 10:21
  • Did you mean `cp`. If so then the originals will remain, but will be covered by the mount. You can do this, and remove them (or not) latter. You can use a bind mount to mount this part of the root partition on to `/mnt`, when you want to see / remove them. – ctrl-alt-delor Apr 06 '19 at 10:24
  • I can mount the partition to home but cannot bind mount it. I think bind mount is not possible with partition? – Just Khaithang Apr 07 '19 at 22:02
  • **or unmount, then mount** (though bind mount should not be a problem) – ctrl-alt-delor Apr 08 '19 at 08:34
  • i am not familiar with bind mounts . I tried this `mount --bind /path/to/home/partition /path/to/mountpoint` but it gave an error about the mount ... 'Destination is not directory' . Then I tried without the bind parameters and it mounted. So I made the entry in fstab and rebooted and it works fine... at least for now. Hope it stays that way. – Just Khaithang Apr 08 '19 at 09:59
  • Was it a directory (preferably empty)? – ctrl-alt-delor Apr 08 '19 at 13:26
  • no it was not empty. It was the /home directory and all my data is still in it. As i mentioned above , I copied the data from my home directory to the new partition after mounting it on /mnt and than unmounted it and tried to bind mount it to my /home directory. It didn't work but a generic/simple mount worked and I am using that after editing the fstab . Will there be any problem in future with simple mount? Also , how about the bindfs ? can I use that to bind mount ? – Just Khaithang Apr 08 '19 at 13:51
  • Ahh I see. You have to choose ① unmount, then mount. or ② bind mount an already mounted directory/file. So in my example `/mnt` has to already have something mounted on it. (you should not need bind mount, so I would stop worrying about it. Except for fun and future). – ctrl-alt-delor Apr 08 '19 at 15:19