martes, 12 de agosto de 2008

Dar formato a un disco nuevo en Linux

¿Cuál es el comando universal, aquel que se entiende en cualquier plataforma?
fdisk
Y por ahí voy a empezar.
Cuando instalamos un disco duro nuevo, lo primero que tenemos que hacer son las particiones, y les damos forma con el comando fdisk.

Lo que voy a hacer es dar forma al nuevo disco, que para mi máquina será el /dev/sdb.

Tuxxxy:~$ fdisk /dev/sdb
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 1305.
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-1305, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305):
Using default value 1305

Command (m for help): t
Selected partition 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.

Lo que he hecho ha sido hacer una única partición de ese disco, y aprovechar todo el espacio. Ahora tengo la partición /dev/sdb1, y tengo que crear un sistema de archivos en ella. Como trabajo con Linux, la más estandarizada es la ext3, así que lo hago de esta manera:

Tuxxxy:~$ mkfs.ext3 -b 4096 /dev/sdb1
mke2fs 1.40-WIP (14-Nov-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1310720 inodes, 2620595 blocks
131029 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 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

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

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

Y una vez ya tengo el disco particionado y con su sistema de archivos correspondiente, sólo me queda montarlo y utilizarlo.

Para montarlo manualmente lo hago así:

Tuxxxy:~$ mount -t ext3 /dev/sdb1 /data

Y compruebo que se ha montado bien con un

Tuxxxy:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sdb1 9.9G 151M 9.2G 2% /data

Después tocaría hacer pruebas y comprobaciones como si se me permite la escritura en el disco y cosas de este estilo, y una vez estuviéramos seguros de que funciona, pues lo pondríamos en el /etc/fstab para que la unidad se monte cada vez que arranquemos el sistema operativo.

Tuxxxy:~$ vi /etc/fstab

# /etc/fstab: static file system information.
#
#
proc /proc proc defaults 0 0
/dev/sda2 / ext3 defaults,errors=remount-ro 0 1
/dev/sda1 none swap sw 0 0
/dev/sdb1 /data ext3 defaults,errors=remount-ro 0 1

donde he añadido la última línea, la que corresponde a mi disco nuevo, con su nombre, el punto de montaje, el sistema de archivos y las opciones con las que quiero que se monte.

Sólo queda reiniciar para comprobar que el sistema monta el disco solo.
Y con esto y un bizcocho...

No hay comentarios: