Linux перенести папку home

Move home folder to second drive

I have 2 HDD drives in my computer. At the moment second drive is mounted as /media/storage . How can I move my user data from /home to /media/storage/home ? Can I just move the data over there and then simply symlink it back?

The answer that uses usermod is easiest: create a temp admin user, switch to that account, usermod -m -d /path/to/non_existent_home_dir username , switch back to your account (username), remove temp admin user. Although it is still 5 steps, way fewer than other answers, way less risky and way simpler steps.

6 Answers 6

Moving HOME from command line

To avoid side effects while working in a graphical, environment we should perform all actions to move HOME from a terminal with Ctrl + Alt + F1 .

Temporarily mount the new partition:

sudo mkdir /mnt/tmp sudo mount /dev/sdb1 /mnt/tmp 

assuming /sdb1 is the new partition for HOME

Copy HOME to the new location:

sudo rsync -avx /home/ /mnt/tmp 

We then may mount the new partition as HOME with

to make sure all data are present. Easiest is to delete the old /home at this point (you could do this later but then you will have to boot a live system to see the old home):

sudo umount /home # unmount the new home first! sudo rm -rf /home/* # deletes the old home 

Make HOME permanent

We need to know the UUID of the new partition for the fstab entry seen from:

Note or copy/paste the correct UUID to edit your fstab with

sudo nano /etc/fstab # or any other editor 

and add the following line at the end:

UUID= /home ext4 defaults 0 2 

Take care to choose the appropriate filesystem here, e.g. ext3 if ext3 formatted

Reboot

After a reboot, your /home resides on the new drive having plenty of space.

I recommend logging out of the profile you want to move, you then can also use the distribution tools like usermod for this task.

I followed these instructions for my server and now I cannot access to it via SSH (Permission denied (publickey) :(:(:(

If you want to just move your home directory i.e /home/your-username then simply copy your home directory to other partition and then use System->Administration->Users & Groups to open user settings dialog. Click on the keys icon to authenticate your self

Читайте также:  Установка calculate linux desktop

alt text

After that select the user that you want to change and click properties, go to advanced tab

alt text

change the home directory to new directory i.e the directory that you copied to other partition.

Indeed. it is a great way to easily change the home directory location of a specific user. While reading the question, I was understanding that this would have been for the /home directory globally. In this case, you could create the partition on the other device, manually move all files there and then change the device for the mount point in /etc/fstab file itself.

If you’re copying your home directory with ‘cp’ on the command line, you’d better use ‘cp -rPa *’ : r for recursive, P for not following links, a for preserving ownership and permission flags.

Unity in 13.04 has no «Users & Groups», just a «Users» setting that does not include these options. Can you mention the corresponding terms for Unity in 13.04?

If your using Ubuntu 12.04 or greater the option to use the GUI method may not be available, at least for me it’s not. I had to use this method found here: help.ubuntu.com/community/Partitioning/Home/Moving

The official detailed procedure is here on the Ubuntu help wiki

Find the UUID of the Partition

Set up Fstab

and add these lines into it

UUID=. /media/home ext4 defaults 0 2 

and replace the . with the UUID number of the intended /home partition.

Save and close the fstab file, then type the following command:

Copy /home to the new partition

sudo rsync -aXS --progress --exclude='/*/.gvfs' /home/. /media/home/. 

Check copying worked

sudo diff -r /home /media/home -x ".gvfs/*" 

Note: You can also expect to see some errors about files not found. These are due to symbolic links that point to places that don’t presently exist (but will do after you have rebooted). You can ignore these — but check out anything else.

Preparing fstab for the switch

and now edit the lines you added earlier, changing the /media/home part to simply say /home so that it looks like this:

UUID=. /home ext4 defaults 0 2 

Moving /home into /old_home

cd / && sudo mv /home /old_home && sudo mkdir /home 

Reboot or Remount all

Reboot or remount all with this:

Indeed. it is a great way to easily change the home directory location of a specific user. While reading the question, I was understanding that this would have been for the /home directory globally. In this case, you could create the partition on the other device, manually move all files there and then change the device for the mount point in /etc/fstab file itself

ok, the only way I found this would work is to create another user, give it admin authority, logoff the main id, logon with the new id and then use usermod command.

  • Check availability and format two HDDs: «WD Purple» and «WD Gold».
  • Mount two HDDs to Ubuntu file system.
  • Move HOME folder to «WD Gold» HDD.
  • Terminal method of formatting storage drive — https://askubuntu.com/a/517365/672237
  • Add additional HDD in Ubuntu — https://askubuntu.com/a/956516/672237
  • Move home folder to second drive — https://askubuntu.com/a/50539/672237
Читайте также:  Add second ip linux

Format disks

enter image description here

Plugin all necessary SATA and power cables to your HDDs. Load Ubuntu. Press keyboard and type «Disks». «Disks» utility will be opened:

In this utility you could format your HDDs into Ext4 file system. Otherwise to format disks use commands:

For example, but I’m not sure with parameters because used GUI «Disks»:

sudo mkfs.ext4 -L purple /dev/sdb # not sure with parameters sudo mkfs.ext4 -L gold /dev/sdc # not sure with parameters 

Keep in mind, that formatting will delete everything on target hard disk. You can skip this step if there are any data on the hard disk and you want to not lose it.

Slow formatting should take a lot of time: from 16 up to 20 hours for 4TB disk.

Permanently mount disks

# Press CTRL+ALT+T and open a console. # Check your /dev/sdb and /dev/sdc discs are visible: lsblk # Create directories for the new HDD WD Purple and WD Gold sudo mkdir /hdd_purple sudo mkdir /hdd_gold # temporary directory # Temporary mount to the new mount point sudo mount /dev/sdb1 /hdd_purple sudo mount /dev/sdc1 /hdd_gold # Unmount drives sudo umount /dev/sdb1 sudo umount /dev/sdc1 # Configuration file /etc/fstab has list of all partitions that will be mounted at boot. # 1. Show and copy UUID of the HDD with this command: sudo blkid # My data is: # /dev/sdb1: LABEL="purple" UUID="6ce9ec1f-3bf5-420f-8502-1b4f55f2fc60" TYPE="ext4" PARTUUID="a14c8357-a8ce-42e4-9772-64ccfad3e226" # /dev/sdc1: LABEL="gold" UUID="1d049c7c-4565-480b-a181-2459e8ff8c1b" TYPE="ext4" PARTUUID="4c691b21-b4e3-4dab-ab91-d7bf7272b2b5" # Make a backup of that file to be able to revert changes. sudo cp /etc/fstab /etc/fstab.2018.11.29.bak # 2. Add a new partitions by editing /etc/fstab file as root: sudo nano /etc/fstab # 3. At the bottom of fstab file add 2 lines similar to this: UUID=6ce9ec1f-3bf5-420f-8502-1b4f55f2fc60 /hdd_purple ext4 defaults 0 2 UUID=1d049c7c-4565-480b-a181-2459e8ff8c1b /hdd_gold ext4 defaults 0 2 # Your UUID have to be different! # Write the file with keys then . Quit the editor with . # If you have Midnight Commander running, then save before quitting with , # because will switch from nano editor to your MC. # To see if the drive is mounted correctly we can simulate the mount process at boot with: sudo mount -a 

Moving HOME from command line

# To avoid side effects while working in a graphical, environment # we should perform all actions to move HOME from a terminal with Ctrl+Alt+F3. # Press and swidth to console mode. # Login in the console mode. # Copy HOME to the new location: sudo rsync -avx /home/ /hdd_gold # Delete everything in the HOME directory. # Be careful with this command, make sure you have a backup. rm -rf /home/* # Make HOME permanent -- edit /etc/fstab configuration file sudo nano /etc/fstab # Change string UUID=1d049c7c-4565-480b-a181-2459e8ff8c1b /hdd_gold ext4 defaults 0 2 # to string UUID=1d049c7c-4565-480b-a181-2459e8ff8c1b /home ext4 defaults 0 2 # /hdd_golds change to /home directory # After a reboot, your /home resides on the new drive having plenty of space. sudo reboot 

Источник

Читайте также:  Adding swap file in linux

Перенос папки home на другой диск

n-новый раздел
p-primary
три раза жмем ENTER. И в конце сохраняем запись в таблицу w.

Видим наш диск как блочное устройство /dev/xvdb1

Тип файловой системы можете выбрать ext3, ext4, или xfs

Копируем файлы пользователей в папку /tmp. Если данных много, то сохраняем их на внешний носитель, как подключить внешний диск в Linux читайте в статье про mount.

Монтируем наш новый диск в каталог /home

Возвращаем папки пользователей в /home

При желании можно было добавить диск в LVM группу и увеличить всю файловую систему как это сделать можно прочитать здесь. Неудобство этого подхода заключается в том, что при использовании скажем виртуальных машин, при переносе виртуалки на другой сервер, придется переносить и данные пользователей. Которые часто занимают достаточно большой объем. Если же каталог пользователей будет на отдельном виртуальном диске, то достаточно перенести систему, а потом примонтировать диск пользователей.

Так же можно создать отдельный LVM том для каталога /home, как это сделать читайте здесь. Это позволит в будущем использовать все преимущества LVM.

Не забудьте добавить в файл /etc/fstab, следующую строку

/dev/xvdb1 /home xfs defaults 0 0

Иначе после перезагрузке диск будет отмонитрован.

Если вы нашли ошибку, пожалуйста, выделите фрагмент текста и нажмите Ctrl+Enter.

Источник

Как перенести папку home на другой диск?

Сейчас появился второй жесткий диск, как правильно на него перенести папку /home чтоб не какие программы не поломались?

Xuxicheta

пусть /dev/sda1 это ваш старый диск и раздел
а /dev/sdb1 — новый, отформатированный раздел, куда вы хотите перенести /home

mkdir /mnt/newhome && mount /dev/sdb1 /mnt/newhome rsync -a /home /mnt/newhome

Проверяете все ли нормально перенеслось.

редактируете /etc/fstab
там ищете старый хоум, или если его нет вписываете что-то вроде

/dev/sdb1 /home ext4 defaults 0 1

kotov666

Вот так у меня fstab выглядит:
# /etc/fstab: static file system information.
#
# Use ‘blkid’ to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
#
# / was on /dev/sda3 during installation
UUID=3a7d9cb3-80a0-40dd-bd8f-1193c86e9b26 / ext4 errors=remount-ro 0 1
# /boot/efi was on /dev/sda1 during installation
UUID=49E7-3A3F /boot/efi vfat umask=0077 0 1
# swap was on /dev/sdb3 during installation
UUID=26bce490-9995-4577-b6bb-8a78f38b1ab8 none swap sw 0 0

Xuxicheta

Денис Котов: можно указать устройство через UUID, можно через адрес в /dev
UUID более надежно и точно указывает устройство, но если не перетыкать туда сюда диски адрес в /dev не изменится.

Источник

Оцените статью
Adblock
detector