martes, 21 de octubre de 2014

Migración de un sistema activo de ext3 a ext4 sistema de archivos


Este artículo tiene la intención de servir como una guía para la migración de un sistema vivo de ext3 a un ext4sistema de archivos, incluyendo la migración de archivos a utilizar extensiones, una característica importante enext4 . En él se describe todo el proceso de migración, incluyendo las trampas más comunes que implican una migración de un sistema vivo, en lugar de hacer una nueva instalación.

Razones para la conversión

La explicación de las ventajas y desventajas de ext4 está más allá del alcance de este artículo. Si no se ven afectados por las limitaciones de ext3 , y que no están dispuestos a correr riesgos, puede no valer la pena. Por otro lado, la finalización con éxito del procedimiento de migración de su sistema puede funcionar más rápido, la experiencia acortado controles del sistema de archivos, y han aumentado la fiabilidad sin efectos nocivos.

Tratando ext4 sin conversión

Una propiedad interesante a destacar es que se puede montar ext3 como sistema de archivos ext4 sin hacer la conversión primera. Todo lo que necesitas hacer es modificar el / etc / fstab que decir "ext4" en lugar de "ext3" para todos los sistemas de archivo, y reiniciar el sistema. De esta manera usted será capaz de volver a ext3 en cualquier momento.
Esto puede ser una buena prueba antes de intentar la conversión total, pero esto sólo permitirá ext4características que son compatibles con ext3 . Y eso significa que ninguna de las principales características deext4 , como extensiones, se habilitará.

La migración a ext4

Una palabra de advertencia

Haga una copia de seguridad antes de intentar este procedimiento. Puede hacer que su sistema no arranca, y puede destruir sus datos.
Los sistemas de ficheros serán incompatibles con ext3 , por lo que necesita para asegurarse de que usted tiene un conjunto de herramientas completo disponible con ext4 apoyo antes de hacer una conversión. Esto incluye un gestor de arranque, e2fsprogs, monte, y un núcleo reciente.

Requisitos previos

  • e2fsprogs 1.41.6
  • mount 2.16
  • linux-image 2.6.30
  • GRUB 1.96 + 20090808
Todos estos paquetes están disponibles en Debian inestable o experimental. Versiones más bajas pueden trabajar, a excepción de e2fsprogs - esto es de hecho la versión más baja.

Conversión de un sistema de archivos no root a ext4

Mientras usted está convirtiendo un sistema de archivos que se puedan desmontar, es un procedimiento bastante sencillo. En este ejemplo vamos a convertir un dev / / sdc1 partición montada como / home directorio.
En primer lugar, desmontar la partición.

umount /dev/sdc1

A continuación, ejecute una comprobación del sistema de ficheros en él para asegurarse de que está en condiciones cuerdo. Todavía estamos en ext3 .
fsck.ext3 -pf /dev/sdc1

Habilitar nuevas funciones de ext4 en el sistema de archivos.
tune2fs -O extents,uninit_bg,dir_index /dev/sdc1

Opción "extensiones" permite el sistema de archivos a utilizar extensiones en vez de mapeo de mapa de bits para los archivos, "uninit_bg" reduce los tiempos de comprobación del sistema de archivos de sólo comprobación partes utilizadas del disco, y "dir_index" permite almacenar los contenidos de los directorios grandes en un htree de más rápido de acceso. Opción "dir_index" también se apoya en ext3 , por lo que puedes estar ya usarlo, pero no hace daño a especificarlo aquí.

Ejecute una comprobación del sistema de ficheros. Encontrará errores. Es normal. Deja que solucionarlos. Es posible que desee ejecutar la verificación dos veces para asegurarse de que el sistema de archivos está limpia.
fsck.ext4 -yfD /dev/sdc1

El parámetro "D" en realidad va a habilitar la opción "dir_index" mediante la reconstrucción de índice del directorio. Puede ser reconstruido (optimizado) en cualquier momento después de ejecutar la verificación con el parámetro.
Ahora edite su / etc / fstab file decir "ext4" en lugar de "ext3" para / home . Otras opciones pueden ser diferentes en su sistema.
/dev/sdc1 /home ext4 defaults 0 2

Trate de montar su nuevo ext4 sistema de archivos.
mount /home

Si tiene éxito, enhorabuena. Si no, no se asuste. No ha perdido sus datos. Y usted tiene una copia de seguridad, después de todo, ¿no? Asegúrese de tener todas las últimas herramientas enumeradas en requisitos previos. Haz que forman Debian inestable o experimental si es necesario. Actualice y vuelva a intentarlo.

The /boot partition

If your /boot is a separate partition, all is good and great. Just leave it as ext3. Latest development grub versions do have support for ext4, but it still may and will fail for some given snapshot of grub.
As ext3 can be mounted ext4 without conversion, you can just edit your /etc/fstab to say "ext4" instead of "ext3" for boot partition.
/dev/sdb1 /boot ext4 defaults 0 1
Most features of ext4 will not be used, but that makes little difference for /boot, as it is only used early at boot time. And since this is essentially still an ext3 partition, grub will have no problem booting it.
If, on the other hand, you do not have a separate /boot partition, you should consider creating one. Otherwise you must be really careful, and not enable features not supported by grub, or make sure that you are using a version of grub that supports all of them.

Converting a root filesystem to ext4

Converting a root filesystem is a bit more tricky because you cannot unmount it, as your system is running on it. Nevertheless it is still possible to do it without using an external bootable media. You should do this in a single-user mode.
First step is to modify your /etc/fstab file to say "ext4" instead of "ext3" for root partition. This is important because you will be operating on a read-only filesystem later, and will not be able to make the change, and this would result in your system unable to mount a root filesystem on next boot.
Let us assume that root partition is /dev/sda1, so your /etc/fstab should look something like this.
/dev/sda1 / ext4 defaults 0 1
Now remount the root filesystem read-only.
mount -o remount,ro /
Then run a filesystem check on the root filesystem.
fsck.ext3 -pf /dev/sda1
It will tell you to reboot the system. That may be a good idea, so simply boot into single-user mode and remount it read-only again. It is fine even though we have already modified /etc/fstab, because ext3 can be mounted asext4 without conversion.
Next, enable all the ext4 features on the root filesystem.
tune2fs -O extents,uninit_bg,dir_index /dev/sda1
And run run a filesystem check on the root filesystem again. It will find and fix errors. This is normal.
fsck.ext4 -yfD /dev/sda1
You can now reboot to your new ext4 system, and enjoy faster filesystem check times, better performance, and all the improvements of ext4. Well, almost; read the next section.

Migrating files to extents

It may seem that the migration from ext3 to ext4 is now complete, and it is almost true. Except that any old files created before the conversion will continue using the bitmap mapping of ext3 instead of extents of ext4.
Files will eventually migrate to the new format as they are updated during normal system operation, because on next write they will be saved using extents. Unfortunately many frequently used files (like application binaries) are often read and rarely written to. The outcome is that the files will remain using the old format for a long time, and you will not be able to experience full potential of ext4.
A utility called e4defrag, which would be able to migrate files, is being developed. But unfortunately it is far complete, and is not suitable for use on real data as of time of writing.
Fortunately it is possible to migrate separate files to extents by using chattr utility, which comes with e2fsprogspackage. It allows you to set an attribute on a file which causes the kernel to rewrite the file using extents. It even possible to do this on a mounted and working file system. In fact, that is the only way to do it.
Please not that this feature is still experimental and has not been tested thoroughly. Performing such operation may be dangerous. It may also flood your system log with warnings and errors. You should first test this on small number of insignificant files.
You can check if a file (or a directory) is using extents with lsattr.
lsattr /home/user/foo/bar
If it not using extents, the output will be something like this.
------------------- /home/user/foo/bar
The dashed line here is simply a placeholder for various attributes a file can have. This means that it has no attributes.
Now set the attribute to use extents on the file.
chattr +e /home/user/foo/bar
Now list the attributes again, and you will notice that the output looks like this.
-----------------e- /home/user/foo/bar
Note the "e", which means that it is now using extents.
Check your system log and look for scary things. Not finding any is a good sign. That means you can continue.
Modifying attributes with chattr can be done on multiple files. Although digging trough the entire directory system is not really feasible, so you can use some of the shell magic to accomplish the task.
find /home -xdev -type f -print0 | xargs -0 chattr +e
find /home -xdev -type d -print0 | xargs -0 chattr +e
The first command will run "chattr +e" on all files in /home, and the second will do the same for directories.
It is possible to run this on the root directory and convert everything at once. But running this on one file system at a time with "-xdev" parameter will prevent it from diving into file systems that do not support extents. It may also be useful to run filesystem check on a partition after conversion.
It may make sense to perform this in single-user mode to minimize the chances of something interfering with a task. You may also want to shutdown syslog, as it may generate a lot of warnings.

Final word

Author takes no responsibility for bad things that may or may not happen. Comments, corrections, and discussions most welcome.

No hay comentarios:

Publicar un comentario