Instalando novo HD SATA no Linux pela linha de comando.
Autor: Leandro Moreira | Publicado: 2012-05-10T16:09:00+03:00

Introdução:
Este é um tutorial que resolvi postar pois necessitei recentemente de efetuar uma manobra parecida e não me lembrava dos comandos necessários.O tutorial está baseado no meu ambiente, porém os comandos são genéricos e acredito funcionar em qualquer distro.Problema:Comprei um novo HD de 1 TB e preciso instalar em meu servidor linux. Nele eu rodo um CentOS 5.7 32bits.Solução:O primeiro passo é verificar se o CentOS reconheceu os novos HDs, vamos fazer isso utilizando o comando fdisk -l :










1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21


[root@mytracelog ~]# fdisk -l



Disk /dev/sda: 107.3 GB, 107374182400 bytes

255 heads, 63 sectors/track, 13054 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes



&nbsp;&nbsp;&nbsp;Device Boot&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Start&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Blocks&nbsp;&nbsp; Id&nbsp; System

/dev/sda1&nbsp;&nbsp; *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 13&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 104391&nbsp;&nbsp; 83&nbsp; Linux

/dev/sda2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 14&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 13054&nbsp;&nbsp; 104751832+&nbsp; 8e&nbsp; Linux LVM



Disk /dev/sdb: 137.4 GB, 137438953472 bytes

255 heads, 63 sectors/track, 16709 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes



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



Disk /dev/sdc: 137.4 GB, 137438953472 bytes

255 heads, 63 sectors/track, 16709 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes



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











Analisando o resultado, podemos ver que os 2 HDs foram reconhecidos com sucesso. O hd1 foi reconhecido como /dev/sdb e o hd2 como /dev/sdc. Outra informação que pode ser vista é que ainda não foram particionados. Criando a partiçãoA criação da partição também é feita pelo fdisk, repare que o fdisk é uma ferramenta interativa, dentro dele será utilizado os comando n e w.









1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29


[root@mytracelog ~]# 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 16709.

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

&nbsp;&nbsp;&nbsp;(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

&nbsp;&nbsp;&nbsp;e&nbsp;&nbsp; extended

&nbsp;&nbsp;&nbsp;p&nbsp;&nbsp; primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-16709, default 1): 1

Last cylinder or +size or +sizeM or +sizeK (1-16709, default 16709): 16709



Command (m for help): w

The partition table has been altered!



Calling ioctl() to re-read partition table.

Syncing disks.










Para verificar se realmente a partição foi criada:





1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22


[root@mytracelog ~]# fdisk -l



Disk /dev/sda: 107.3 GB, 107374182400 bytes

255 heads, 63 sectors/track, 13054 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes



&nbsp;&nbsp;&nbsp;Device Boot&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Start&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Blocks&nbsp;&nbsp; Id&nbsp; System

/dev/sda1&nbsp;&nbsp; *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 13&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 104391&nbsp;&nbsp; 83&nbsp; Linux

/dev/sda2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 14&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 13054&nbsp;&nbsp; 104751832+&nbsp; 8e&nbsp; Linux LVM



Disk /dev/sdb: 137.4 GB, 137438953472 bytes

255 heads, 63 sectors/track, 16709 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes



&nbsp;&nbsp;&nbsp;Device Boot&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Start&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Blocks&nbsp;&nbsp; Id&nbsp; System

/dev/sdb1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 16709&nbsp;&nbsp; 134215011&nbsp;&nbsp; 83&nbsp; Linux



Disk /dev/sdc: 137.4 GB, 137438953472 bytes

255 heads, 63 sectors/track, 16709 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes



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








Formatando a partição em ext3 Com a partição criada, é hora de formatar.Para formatar utilize o mkfs.ext3:




1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23


[root@mytracelog ~]# mkfs.ext3 /dev/sdb1 

mke2fs 1.39 (29-May-2006)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

16777216 inodes, 33553752 blocks

1677687 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=4294967296

1024 block groups

32768 blocks per group, 32768 fragments per group

16384 inodes per group

Superblock backups stored on blocks: 

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4096000, 7962624, 11239424, 20480000, 23887872



Writing inode tables: done&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done



This filesystem will be automatically checked every 25 mounts or

180 days, whichever comes first.&nbsp; Use tune2fs -c or -i to override.








Criando o ponto de montagem Para criar o ponto de montagem:








Montando a partição

Para montar a partição:





1


[root@mytracelog ~]# mount -t ext3 /dev/sdb1 /hd1







Verificando se a partição foi montada com sucesso:





1

2

3

4

5

6

7

8

9


[root@mytracelog ~]# df -h

Filesystem&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Size&nbsp; Used Avail Use% Mounted on

/dev/mapper/VolGroup00-LogVol00

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;92G&nbsp;&nbsp; 14G&nbsp;&nbsp; 73G&nbsp; 17% /

/dev/sda1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 99M&nbsp;&nbsp; 26M&nbsp;&nbsp; 68M&nbsp; 28% /boot

tmpfs&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2.0G&nbsp; 640M&nbsp; 1.4G&nbsp; 33% /dev/shm

D_DRIVE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 800G&nbsp; 618G&nbsp; 183G&nbsp; 78% /media/sf_D_DRIVE

/dev/hdc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 43M&nbsp;&nbsp; 43M&nbsp;&nbsp;&nbsp;&nbsp; 0 100% /media/VBOXADDITIONS_4.1.6_74713

/dev/sdb1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 126G&nbsp; 188M&nbsp; 120G&nbsp;&nbsp; 1% /hd1







Veja nossa nova partição&nbsp;/dev/sdb1&nbsp;montada em&nbsp;/hd1.




Configurando a montagem automática

Agora vamos automatizar a montagem, não queremos montar essa partição toda vez que iniciarmos o CentOS. Para isso temos que editar o&nbsp;/etc/fstab:





1


[root@mytracelog ~]# vi /etc/fstab







Adicione a seguinte linha:




1


/dev/sdb1&nbsp;&nbsp; /hd1&nbsp;&nbsp; ext3&nbsp;&nbsp; defaults&nbsp;&nbsp; 1&nbsp;&nbsp; 2









Conclusão
Como visto, a instalação de um novo HD SATA no CentOS &nbsp;envolve diversos passos. Foi apresentado um contexto de instalação de 2 HDs, o&nbsp;hd1&nbsp;foi utilizado como exemplo, para o&nbsp;hd2&nbsp;basta seguir os mesmos passos com algumas pequenas modificações. O gerenciamento de partição ficou a cargo do&nbsp;fdisk, a formatação foi feito pelo&nbsp;mkfs.ext3, a criação do ponto de montagem pelo&nbsp;mkdir&nbsp;e a montagem pelo&nbsp;mount.





Fonte e créditos:&nbsp;SAKAMOTO&nbsp;-&nbsp;http://mytracelog.blogspot.com.br/2011/11/instalando-novo-hd-sata-no-centos-56.html