12 jun 2012

Particionar y Formatear un nuevo disco duro con ext3

Recientemente me informaron acerca de la configuración de discos duros de los nuevos servidores, la necesidad es crear una partición primaria con ext3 y montarla en el directorio /data02.

Manos a la obra:

Lo primero que necesitamos es consultar la tabla de particiones y ubicar el disco que vamos a ocupar, aquí mucho cuidado, cualquier error nos puede arruinar el día. Por lo tanto ejecutamos fdisk de la siguiente forma:
# /sbin/fdisk -l
Disk /dev/cciss/c0d0: 299.9 GB, 299966445568 bytes
255 heads, 63 sectors/track, 36468 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/cciss/c0d0p1 * 1 16 128488+ 83 Linux
/dev/cciss/c0d0p2 17 36468 292800690 8e Linux LVM

Disk /dev/cciss/c0d1: 599.9 GB, 599932844032 bytes
255 heads, 32 sectors/track, 143596 cylinders
Units = cylinders of 8160 * 512 = 4177920 bytes


Disk /dev/cciss/c0d1 doesn't contain a valid partition table
El disco a trabajar es /dev/cciss/c0d1, y tal como lo dice el mensaje: No contiene una tabla de partición válida. Para comenzar, usamos nuevamente el comando fdisk de la siguiente forma (Se resaltan las opciones en negritas):
# /sbin/fdisk /dev/cciss/c0d1
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

The number of cylinders for this disk is set to 143596.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help):n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-143596, default 1): 1
Last cylinder or +size or +sizeM or +sizeK (1-143596, default143596 ): 143596

Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): 83

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
No olviden la "w", de lo contrario los cambios no se escribirán en la tabla de particiones.

Ahora vamos a crear el sistema de archivos ext3 (o formatear, como normalmente se dice)
# /sbin/mkfs.ext3 -b 4096 /dev/cciss/c0d1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
73236480 inodes, 146467979 blocks
7323398 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
4470 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000


Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done


This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
Ahora que el disco está particionado y formateado, el último paso es "montarlo", recordemos que el directorio donde deseo montar mi nuevo disco es /data02. Primero creamos el directorio /data02.

# mkdir /data02
Y luego editamos el archivo /etc/fstab para agregar la entrada (en azul):
/dev/vg_root/lv_root   /        ext3   defaults       1 1
/dev/vg_root/lv_tmp    /tmp     ext3   defaults       1 2
/dev/vg_root/lv_data01 /data01  ext3   defaults       1 2
/dev/vg_root/lv_usr    /usr     ext3   defaults       1 2
/dev/vg_root/lv_var    /var     ext3   defaults       1 2
LABEL=/boot            /boot    ext3   defaults       1 2
tmpfs                  /dev/shm tmpfs  defaults       0 0
devpts                 /dev/pts devpts gid=5,mode=620 0 0
sysfs                  /sys     sysfs  defaults       0 0
proc                   /proc    proc   defaults       0 0
/dev/vg_root/lv_swap            swap   swap defaults  0 0
/dev/cciss/c0d1        /data02  ext3   defaults       1 1
Después de crear la entrada, lo que resta es montar el disco:
# mount /data02
Verificamos que todo quedó bien:
# /bin/df -h
Filesystem                     Size Used Avail Use% Mounted on
/dev/mapper/vg_root-lv_root    2.0G 399M 1.5G   22% /
/dev/mapper/vg_root-lv_tmp     3.9G 137M 3.6G    4% /tmp
/dev/mapper/vg_root-lv_data01  250G 188M 237G    1% /data01
/dev/mapper/vg_root-lv_usr     5.9G 1.1G 4.5G   20% /usr
/dev/mapper/vg_root-lv_var     5.9G 292M 5.3G    6% /var
/dev/cciss/c0d0p1              122M  13M 103M   11% /boot
tmpfs                           16G     0 16G    0% /dev/shm
/dev/cciss/c0d1                550G 198M 522G    1% /data02