1

I have this setup of Ubuntu 18: two identical disks. In one (sda) there is / and /boot/efi. In the other disk (sdb) there is /home.

The free space in sda is enough to hold what is used in sdb.

I would like to move /home to sda. It could be the same partition sda1, or it could be a new partition, say sda3.

Here is what gparted shows me:

disks partitions

Is it possible to make this moving?

I don't know if what I'm saying makes sense, but my plan is:

  • resize sda1 to say, 200GB
  • format the empty space in sda to ext4 (creating sda3)
  • copy the content of sdb1 to sda3
  • tell linux that /home now is in sda3 (this part I have no idea how to do)
3
  • this is always a very very bad idea to have not separated /home partition ideal is having separated /home /var /usr and / + /tmp as minimal segmentations etc... specially for /home it is always a good idea to have it on its own separated disk ....depending on your usages risk is more or less acceptable. In your case the best choice is to make a sda3 to your new home keeping it separated even it is on same physical disk.
    – francois P
    Commented Nov 24, 2021 at 12:44
  • Do you think making an sda3 for /home besides being best is easier too?
    – Gustavo
    Commented Nov 24, 2021 at 13:34
  • Very similar to this which is moving to another drive, but a move is a move. To move /home uses rsync- Be sure to use parameters to preserve ownership & permissions help.ubuntu.com/community/Partitioning/Home/Moving Another alternative is to split /home & your data. I keep /home in / (with just the mostly hidden files) and everything else in data partition(s). askubuntu.com/questions/1013677/… & askubuntu.com/questions/1058756/…
    – oldfred
    Commented Nov 24, 2021 at 15:41

3 Answers 3

0

If you use sudo or su instead of logging in directly, you will still lock the home directory and you will be unable to umount /home. If you cannot login directly, you should probably use a live CD.

Another option however would be:

  • create a user safemove, with a home directory /tmp.
  • add safemove to the sudoers file with visudo
  • log in with safemove at the terminal (typically control-shift-f1). This will prevent the creation of the complete graphical desktop under /tmp.
  • make sure everybody else is logged off.
  • as safemove, sudo -s
  • mkdir /mnt/home
  • umount /home
  • mount /dev/sdb1 /mnt/home
  • copy /mnt/home/* to /home if you do not want a separate partition, including ownership and permission flags.
  • remove /home from /etc/fstab
  • take a deep breath and reboot.

You should now have everything in /dev/sda1. Check this first before removing the user safemove.

If you are going to mess with /home, it is always good to have, at least temporarily, a userid that does not have its homedir under /home and that can sudo and/or su.

If you want to

0

It is possible, but you should login as root in order to avoid locking /home. Then you can unmount /home, remount it elsewhere (let’s suppose /mnt), then copy all files from /mnt to /home preserving the permissions (cp -rp /mnt/* /home). Then edit /etc/fstab and change where you mount sdb1.

If you can’t login as root, use a Live CD.

However, having a separate /home enables you to reformat / if you want to change the OS keeping your personal file. But surely, nearly 1TB for the OS is quite important.

5
  • Thanks for your answer. Did you mean "If you can't login as root, use a Live CD."? When the data currently in sdb1/home will be moved to sda?
    – Gustavo
    Commented Nov 24, 2021 at 13:21
  • Some systems lets you connect as root, some others expect you to connect as a normal user, then from the opened session, use sudo to elevate your priviledges. Try login as root, then we will see. Commented Nov 24, 2021 at 13:25
  • Then, logged as root, proceed as inducated ( umount /home, then mount /dev/sdb1 /mnt…..) Commented Nov 24, 2021 at 13:32
  • @FrédéricLoyer "If you can login as root, use a Live CD." You probably mean the inverse, "If you can't login as root, use a Live CD." Commented Nov 24, 2021 at 13:55
  • Yes, I have corrected the answer. Commented Nov 24, 2021 at 14:04
0

YES

my /etc/fstab for example is

UUID=800e924a-a869-4152-9503-9d9cfecbd16e                /                       xfs     defaults        0 0
UUID=4f3da85a-71a9-4f6e-bc5f-dfd23a880b08                /boot                   xfs     defaults        0 0
UUID=1FAB-9515                                           /boot/efi               vfat    umask=0077,shortname=winnt 0 0
/dev/disk/by-uuid/e0791b9e-b620-4274-9857-78389b10f5a5   /data auto nosuid,nodev,nofail,x-gvfs-show 0 0

# my /data is a 15tb hardware raid-5, comes in as /dev/sda1
# my root partition comes in as /dev/sdb3, with /boot and /boot/efi as sda2 and sda1.

I do not have /home as mounted as a separate partition. If it was you would see it as an entry in /etc/fstab as such, it will be quite obvious.

In your case you want to make /home on your root partition, so here is what I would do

  • your existing home is mounted as a separate partition, reference it from /etc/fstab
  • mkdir /newhome
  • cp -rp /home/* /newhome/
  • umount /home
  • rmdir /home
  • mv /newhome /home
  • remove the mount point of /home from your /etc/fstab; that's all that really needs to happen if you want to have /home on your root / partition {which is already being mounted in /etc/fstab as /)

note: the umount command will likely result in failure if logged in as a user where that mount will inherently be busy. So if you log in as root, whose home directory is /root and not under the mounted /home you should have no problem.

note2: you don't even need to use the /home folder convention, simply change the location of user folders in /etc/passwd to wherever you want those user account home folders to reside. For example all my user accounts on my server specified in /etc/passwd have home folders under /data/users/<name>. I do have a /home folder present, but it has nothing in it. My /data is mounted in /etc/fstab and is a raid-5 bunch of disks making 10 tb worth of space.

3
  • The difference between your approach and the other answers is that you copy before mount. Do you know if it makes any difference?
    – Gustavo
    Commented Nov 24, 2021 at 21:16
  • not sure what you are asking... you can't copy from something or to something unless it is mounted. What I posted above was to illustrate the steps involved to get the concept across. I don't get where the other answers were coming from (didn't really read them in depth) but they seemed to be making it more difficult than it needed to be.
    – ron
    Commented Nov 26, 2021 at 1:27
  • his original /home is on a different partition (and already mounted) which he doesn't want. So make any folder (i.e. newhome) on the root partition as a place holder, because you can't use the syntax "/home" just yet its already in use. Get everything copied off the existing /home (which is on that different partition thats unwanted) and onto the root partition under /whatever, then umount existing /home and move /whatever (i.e. newhome) syntactically into its place. hope that helps.
    – ron
    Commented Nov 26, 2021 at 1:30

You must log in to answer this question.

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