1

I am using Ubutnu 18.04.

Currently, /home is mounted on / on an NVME disk according to df command:

Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p2  137G  113G   18G  87% /
...

The size of /dev/sda1 is 400GB which I want to use as my /home according to fdisk -l:

Device          Start        End   Sectors   Size Type
/dev/sda1  1172275200 1953523711 781248512 372.5G Linux filesystem

Using the guides, I have to find the UUID of /dev/sda1 using blkid

/dev/sda1: UUID="3ce518e8-955d-4b26-9dde-c3819d5906d6" TYPE="ext4" PARTUUID="08f6658f-7432-4a48-bdbd-0ee8f16d9b91"

and define the appropriate entry in /etc/fstab. So, the content of that is now

$ cat /etc/fstab 
UUID=3ce518e8-955d-4b26-9dde-c3819d5906d6   /home    ext4    defaults   0   2
UUID=918a1f7d-b27c-4b82-8a10-ba0d622a37dd /               ext4    errors=remount-ro 0       1
UUID=BA35-0600  /boot/efi       vfat    umask=0077      0       1

UUID=36a37d03-0ba7-4196-83ed-876e2782297e none            swap    sw              0       0

After running sudo mount -a, I see that my home folder becomes empty and all files are disappeared.

$ ls /home/mahmood/
$

My previous files are missing however, they exist. Since the usage of / in df -h has not been changed.

Any quick solution?

{UPDATE}

I tired to remount the old partition in /home2 according to the comments. So, I entered sudo mkdir /home2 && chmod -R 777 /home2. Then I edited /etc/fstab to keep old and new partitions

UUID=3ce518e8-955d-4b26-9dde-c3819d5906d6   /home    ext4    defaults   0   2
/dev/nvme0n1p2 /home2 ext4 defaults 0 2

After running sudo mount -a, I see:

$ ls /
bin    dev   home2           lib    libx32      mnt   root  snap  tmp  vmlinuz
boot   etc   initrd.img      lib32  lost+found  opt   run   srv   usr
cdrom  home  initrd.img.old  lib64  media       proc  sbin  sys   var
$ ls /home
DEBIAN  mahmood  virtualbox-6.0_6.0.0-127566-Ubuntu-bionic_amd64.deb  vt  win7.vdi
$ ls /home2/
bin    dev   home2           lib    libx32      mnt   root  snap  tmp  vmlinuz
boot   etc   initrd.img      lib32  lost+found  opt   run   srv   usr
cdrom  home  initrd.img.old  lib64  media       proc  sbin  sys   var

I can see my old files in /home2/home/mahmood. However, I don't know why I see /etc and /home2/etc for example. What is going on then?!

  • 1
    You have to copy the whole /home into the new partition. This is the problem. I suggest you to mount (using fstab) the old partition as /home2 and then you may copy al files into home2 into the new /home. cp -avp /home2/* /home After the copy is done and you verified the operation is correct you may remove the whole /home2 contents (but I think is better that the files deletion will be done after you tested for some time that the new /home is ok) and then you may delete /home2 mount from the fstab file (or not delete it, so you will have it as a immediately disponible backup copy) – Sir Jo Black Dec 29 '18 at 14:43
  • I want to know how to find the missing partition in order to mount that as home2. – mahmood Dec 29 '18 at 14:45
  • I tried commenting UUID=3ce518e8-955d-4b26-9dde-c3819d5906d6 /home ext4 defaults 0 2 in /etc/fstab. However, it has no effect. – mahmood Dec 29 '18 at 14:48
  • @SirJoBlack Please don't post answers as comments. ;-) If you post it as an answer with a few step-by-step instructions and leave me a comment, I'll come back and upvote. 0:-) (go to tty1, dismount /home, remount as home2, copy, reboot and if all is well, mount old home and delete) Alternatively, I can do as well... >:-) – Fabby Dec 29 '18 at 14:51
  • 1
    @mahmood, you may mount the old home using the device name instead of the UUID. /dev/nvme0n1p2 /home2 ext4 defaults 0 2. You also may decomment the other. In this way you will have both directory. – Sir Jo Black Dec 29 '18 at 15:03
1

When you create the new mountpoint /home the data are not moved from the previous /home to the new.

To solve the problem you have to use "simple" workarounds.

There are two cases:

The first case is when the old home was mounted in a partition by means the file fstab.

In this case you may operate as in the following lines:

You have to copy the whole /home into the new partition.

The first step is to ripristinate the old /home as /home2 inserting into the file fstab this line without removing the new line you have inserted

/dev/nvme0n1p2 /home2 ext4 defaults 0 2

The second step is to reboot your PC. In this way you will have both directories: /home (the new home) and /home2 (the old home)

The second case is when the /home directory is a real directory under /.

In this case you have to rename your /home as /home2 (before this you have to delete the new home line from fstab, if it is there, and reboot)

sudo mv /home /home2

Then you have to insert the new /home line into fstab and reboot.

The last step (in both cases) is to copy all files from home2 to home:

sudo cp -apvr /home2/* /home

In this way you will have the new /home and then may consider /home2 as a backup copy.

When you will be sure the new /home is correct you will be free to delete all files in /home2:

sudo rm -rf /home2/*

And then you will remove the /home2 line from the fstab files in the first case or delete the /home2 directory in the second case.

sudo rm -rf /home2 # in the second case.

I suggest you to wait some time before to delete /home2.

  • @mahmood, I saw that I forgotten to indicate the option -r into the cp line. I've modified my answer. the option -r should copy all files including hidden files (that you may see using ls -lad /home2/* or ls -lad /home/*. – Sir Jo Black Dec 30 '18 at 13:34
  • @mahmood. I'm not sure it's all correct. See if all hidden files has been copied for all users, using ls -lad /home2/<username>/.* and ls -lad /home/<username>/.* where <username> shall be substituted with the user you need to verify. – Sir Jo Black Dec 30 '18 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.