Obre el menú principal

Moure /home a altra partició

La revisió el 19:33, 25 des 2012 per Tafol (discussió | contribucions) (traduint)

Pendent de traducció. Text original a https://help.ubuntu.com/community/Partitioning/Home/Moving


Descripció

Aquesta guia ofereix instruccions detallades per a la migració de la carpeta del sistema /home cap a una partició en el disc dur dedicada a tal efecte. Configurar la carpeta /home en una partició separada és beneficiós perquè les configuracions d'usuari, els fitxers personals i l'escriptori es mantindran si s'actualitza el sistema, es torna a instal·lar Ubuntu o altra distribució (com ara Lliurex). Això funciona perquè /home conté una subcarpeta per a cada usuari amb els fitxers que contenen totes les dades i la configuració de eixe usuari.

Es pot dir a Ubuntu què use una partició diferent per a home triant durant el procés d'instal·lació "particionat manual" i especificant que vols que el punt de muntatge de la partició diferent siga /home. Assegureu-vos de no formatar la partició /home durant el procés i de que els usuaris creats coincidisquen amb els que hi havia al la carpeta /home prèvia.

Aquesta guia seguirà 6 passos bàsics:

1. Configuració de la nova partició
2. Còpia de seguretat de /home, edició del fitxer fstab per tal de muntar la nova partició en el punt /media/home (només mentre dura el procés) i reinici del sistema.
3. Utilització de rsync per migrar totes les dades de /home cap a /media/home. 
4. Edició de fstab de nou per tal què la nova partició es munte com a /home en comptes de /media/home però no reiniciar encara.
5. Canviar el nom de l'original /home a /old_home i reiniciar el sistema.
6. Esborrar /old_home.

La guia està escrita de tal manera què en qualsevol moment si hi ha una falla en el sistema, tall d'energia o un reinici a l'atzar, no tindrà un impacte negatiu en el sistema. També estaria protegint contra la possibilitat que l'usuari elimine accidentalment el seu /home en el procés.

Configuració de la nova partició

Abans de configurar la partició, primer s'ha de crear una nova. Això es pot fer amb Gparted o qualsevol altre programa de gestió de particions. Normalment, qualsevol distribució autònoma de linux (Live CD) porta l'aplicació Gparted instal·lada. Quan creeu una nova partició és molt recomanable que siga del tipus ext3 o ext4 (el mateix que tingueu per al sistema de fitxers /) per albergar la nova carpeta /home. Memoritzeu o anoteu la ubicació de la partició, serà una cosa com /sda3 o /hda5 o alguna cosa semblant.

Find the uuid of the Partition

The uuid (Universally Unique Identifier) reference for all partitions can be found by opening a [| command-line] to type the following: {{{ sudo blkid }}} Alternatively, for some older releases of Ubuntu the "blkid" command might not work so this could be used instead {{{ sudo vol_id -u <partition> }}} for example {{{ sudo vol_id -u /dev/sda3 }}} Now you just need to take note (copy&paste into a text-file) the uuid of the partition that you have set-up ready to be the new /home partition.

Setup Fstab

Your fstab is a file used to tell Ubuntu what partitions to mount at boot. The following commands will duplicate your current fstab, append the year-month-day to the end of the file name, compare the two files and open the original for editing.

1. Duplicate your fstab file: {{{ sudo cp /etc/fstab /etc/fstab.$(date +%Y-%m-%d) }}}

2. Compare the two files to confirm the backup matches the original: {{{ cmp /etc/fstab /etc/fstab.$(date +%Y-%m-%d) }}}

3. Open the original fstab in a text editor: {{{ gksu gedit /etc/fstab }}} and add these lines into it {{{

  1. (identifier) (location, eg sda5) (format, eg ext3 or ext4) (some settings)

UUID=???????? /media/home ext3 nodev,nosuid 0 2 }}} and replace the "????????" with the UUID number of the intended /home partition.

NOTE: In the above example, the specified partition in the new text is an ext3, but if yours is an ext4 partition, you should change the part above that says "ext3" to say "ext4", in addition to replacing the ???'s with the correct UUID. Also note that if you are using Kubuntu, Xubuntu or Lubuntu you may need to replace "gedit" with "kate", "mousepad" or "leafpad", respectively. They are text editors included with those distributions.


4. Save and Close the fstab file, then type the following command: {{{ sudo mkdir /media/home }}}

This command will create a new directory, later used for temporarily mounting the new partition. At the end of the procedure this directory can be removed.

Now you can restart your machine. It should now auto-mount the new partition as /media/home. We will edit the fstab again later so this arrangement of the partition is only temporary.

To ensure your partition is mounted, mount all file systems declared in fstab with: {{{ sudo mount -a }}}


Copy /home to the New Partition

Next we will copy all files, directories and sub-directories from your current /home directory into the new partition:

{{{ sudo rsync -aXS --exclude='/*/.gvfs' /home/. /media/home/. }}} The --exclude='/*/.gvfs' prevents rsync from complaining about not being able to copy .gvfs, but I believe it is optional. Even if rsync complains, it will copy everything else anyway. ([here for discussion on this])

Check Copying Worked

You should now have two duplicate copies of all the data within your home directory; the original being located in /home and the new duplicate located in /media/home. You should confirm all files and directories copied over successfully. One way to do this is by using the diff command:

{{{ sudo diff -r /home /media/home }}}

The only difference that should exist is the excluded /.gvfs directory mentioned above.


Preparing fstab for the switch

We now need to modify the fstab again to point to the new partition and mount it as /home. So again on a command-line {{{ gksu gedit /etc/fstab }}} and now edit the lines you added earlier, changing the "/media/home" part to simply say "/home" so that it looks like this: {{{

  1. (identifier) (location, eg sda5) (format, eg ext3 or ext4) (some settings)

UUID=???????? /home ext3 nodev,nosuid 0 2 }}}

Then, press Save, close the file but don't reboot just yet.

Moving /home into /old_home

As long as you have not rebooted yet, you will still see 2 copies of your /home directory; the new one on the new partition (currently mounted as /media/home) and the old one still in the same partition it was always in (currently mounted as /home). We need to move the contents of the old home directory out of the way and create an empty "placeholder" directory to act as a mount point for our new partition.

Type the following string of commands in to do all this at once: {{{ cd / && sudo mv /home /old_home && sudo mkdir /home }}}

By default, when you open a terminal window it places you within your home directory. Typing cd / takes us to the root directory and out of home so we can then use the sudo mv command to essentially rename /home into /old_home, and finally create a new, empty /home placeholder.

With your fstab now edited to mount your new partition to our /home placeholder and the original /home now called /old_home, reboot your computer. Your new partition will mount as /home and everything should look exactly the same as it did before you started.

Deleting the old Home

You can delete your old home directory with: {{{ cd / sudo rm -r /old_home }}} Be careful with the above command as mistyping it could result in the deletion of other files and directories.

Technical Notes and Resources

Rsync was chosen over cp and find|cpio because it seemed to maintain permissions.

http://ubuntu.wordpress.com/2006/01/29/move-home-to-its-own-partition/

http://ubuntuforums.org/showthread.php?t=46866

Different filesystems on the same disk

If you're moving from Windows and your new home partition is going to be an old ntfs partition (the D: disk) while you convert the C: disk to a journaling partition where you install Linux, this won't work, there will be a huge load on the processor. You should convert the two partitions to ext3 or ext4 or keep both partitions as ntfs (I haven't checked this last option). But working with two different filesystems on the same drive simultaneously doesn't seem to be a good option.