Pense-bête: un deuxième disque dur pour votre GNU/Linux

Date: 11/01/2012 | Catégories: Open-source,Planet-libre,Systeme | Tags: ,,,,,

Petit pense-bête à usage interne pour installer (= partitionner & formater) un deuxième disque dur au format ext4 sur une distribution GNU/Linux.

Notes: les commandes suivantes doivent être effectuées depuis un compte root.

Préparation

On commence par vérifier la liste des disques disponibles avec la commande:

[cc]
# fdisk -l
[/cc]

J'obtiens:

Disk /dev/sda: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0000f7a3

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        1998    16043008   83  Linux
/dev/sda2            1998        2089      731137    5  Extended
/dev/sda5            1998        2089      731136   82  Linux swap / Solaris

Disk /dev/sdb: 34.4 GB, 34359738368 bytes
255 heads, 63 sectors/track, 4177 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

J'ai donc deux disques disponibles (je suis sur une VM donc ne vous étonnez pas des tailles):

  • /dev/sda: d'une taille de 17.2 GB avec 3 partitions (sda1, sda2, sda5)
  • /dev/sdb: d'une taille de 34.4 GB sans partition

C'est ce deuxième disque (sdb) que l'on souhaite installer

Partitionnement

On commence donc par partitionner le disque en question:

[cc]
# fdisk /dev/sdb
[/cc]

Notes: Faites bien attention à lancer la commande fdisk sur le bon disque...

une seule grosse partition qui utilisera la totalité de l'espace disque:

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x852ed7ac.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-4177, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-4177, default 4177): 
Using default value 4177

Puis on demande à fdisk de lui affecter le type 'Linux'

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 83

Puis on valide:

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

La partition que l'on vient de créer portera le nom sdb1.

Formatage en ext4

On utilise ensuite la commande mkfs.ext4 pour formater la partition au format EXT4

[cc]
# mkfs.ext4 -b 4096 /dev/sdb1
[/cc]

mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
2097152 inodes, 8387930 blocks
419396 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
256 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624

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

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

Vérification

On vérifie que tout c'est bien passé:

[cc]
# fdisk -l
[/cc]

Disk /dev/sda: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0000f7a3

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        1998    16043008   83  Linux
/dev/sda2            1998        2089      731137    5  Extended
/dev/sda5            1998        2089      731136   82  Linux swap / Solaris

Disk /dev/sdb: 34.4 GB, 34359738368 bytes
255 heads, 63 sectors/track, 4177 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x852ed7ac

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        4177    33551721   83  Linux

Nous disposons donc bien d'une disque (/dev/sdb1) de 34.4 GB

Utilisation de la nouvelle partition

Pour utiliser ce nouveau disque, il faut le monter ("mount").

On commence donc par créer un répertoire (/mnt/data) dans lequel le contenu du disque sera visible:

[cc]
# mkdir /mnt/data
[/cc]

Puis on édite le fichier /etc/fstab pour lui ajouter la ligne suivante:

/dev/sdb1             /mnt/data    ext4  defaults   1 1

On monte le disque:

[cc]
# mount /mnt/data
[/cc]

et on vérifie que le système le détecte:

[cc]
# df -k
[/cc]

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1             15791024   2446256  12542620  17% /
tmpfs                   513604         0    513604   0% /lib/init/rw
udev                    508732       116    508616   1% /dev
tmpfs                   513604         0    513604   0% /dev/shm
/dev/sdb1             33025240    180152  31167504   1% /mnt/data

Bingo, il ne reste plus qu'à écrire/lire vos données dans le répertoire /mnt/data !

Partager ce billet





WordPress » Erreur

Il y a eu une erreur critique sur ce site.

En apprendre plus sur le débogage de WordPress.