sexta-feira, 14 de dezembro de 2012

Como formatar um disco no Linux


No sistema Windows é comum o termo "formatar o disco". Em Linux, essa ação é chamada de "criar um sistema de arquivos".

No Windows, temos basicamente dois sistemas de arquivos: o Fat (em suas várias versões) e o Ntfs. No Linux, há uma infinidade de sistemas de arquivos diferentes para as mais variadas tarefas. Se você quer "formatar" um pendrive para usá-lo em todos os tipos de computadores, formate-o com Fat.

No Linux, o comando mais usado para criar um sistema de arquivos é o mkfs. No exemplo abaixo, vamos formatar a partição /dev/sda5.

# fdisk -l /dev/sda5
GNU Fdisk 1.2.4
Copyright (C) 1998 - 2006 Free Software Foundation, Inc.
This program is free software, covered by the GNU General Public License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.


Disk /dev/sda5: 1 GB, 1019934720 bytes
255 heads, 63 sectors/track, 124 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot      Start         End      Blocks   Id  System 
/dev/sda5p1               1         125     1004031   83  Linux 
Warning: Partition 1 does not end on cylinder boundary.                

Para ver quais sistemas de arquivos o mkfs pode criar, digite mkfs e tecle TAB duas vezes.

# mkfs

mkfs          mkfs.btrfs    mkfs.ext2     mkfs.ext4     mkfs.minix    mkfs.ntfs     
mkfs.bfs      mkfs.cramfs   mkfs.ext3     mkfs.ext4dev  mkfs.msdos    mkfs.vfat     

Primeiramente vamos criar um sistema de arquivos FAT...

# mkfs.vfat /dev/sda5
mkfs.vfat 3.0.9 (31 Jan 2010)

montamos o disco...

# mount /dev/sda5 /mnt/sda5/

e vemos quanto espaço temos disponível.

# df -h /dev/sda5 
Sist. Arq.            Size  Used Avail Use% Montado em
/dev/sda5             975M  4,0K  975M   1% /mnt/sda5

Para criar um NTFS...

# umount /dev/sda5 
# mkfs.ntfs /dev/sda5
Cluster size has been automatically set to 4096 bytes.
Initializing device with zeroes: 100% - Done.
Creating NTFS volume structures.
mkntfs completed successfully. Have a nice day.
# mount /dev/sda5 /mnt/sda5/
# df -h /dev/sda5 
Sist. Arq.            Size  Used Avail Use% Montado em
/dev/sda5             977M  5,4M  972M   1% /mnt/sda5

Ext2...

# umount /dev/sda5 
# mkfs.ext2 /dev/sda5
mke2fs 1.41.12 (17-May-2010)
/dev/sda5 alignment is offset by 512 bytes.
This may result in very poor performance, (re)-partitioning suggested.
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=1 blocks, Stripe width=0 blocks
62592 inodes, 250000 blocks
12500 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=260046848
8 block groups
32768 blocks per group, 32768 fragments per group
7824 inodes per group
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376

Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
# mount /dev/sda5 /mnt/sda5/
# df -h /dev/sda5 
Sist. Arq.            Size  Used Avail Use% Montado em
/dev/sda5             962M  1,3M  912M   1% /mnt/sda5

Ext4...

# umount /dev/sda5 
# mkfs.ext4 /dev/sda5
mke2fs 1.41.12 (17-May-2010)
/dev/sda5 alignment is offset by 512 bytes.
This may result in very poor performance, (re)-partitioning suggested.
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=1 blocks, Stripe width=0 blocks
62592 inodes, 250000 blocks
12500 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=260046848
8 block groups
32768 blocks per group, 32768 fragments per group
7824 inodes per group
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376

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

This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
# mount /dev/sda5 /mnt/sda5/
# df -h /dev/sda5 
Sist. Arq.            Size  Used Avail Use% Montado em
/dev/sda5             974M   30M  896M   4% /mnt/sda5

E o novo sistema Btrfs...

# umount /dev/sda5 
# mkfs.btrfs /dev/sda5

WARNING! - Btrfs Btrfs v0.19 IS EXPERIMENTAL
WARNING! - see http://btrfs.wiki.kernel.org before using

fs created label (null) on /dev/sda5
nodesize 4096 leafsize 4096 sectorsize 4096 size 976.56MB
Btrfs Btrfs v0.19
# mount /dev/sda5 /mnt/sda5/
# df -h /dev/sda5 
Sist. Arq.            Size  Used Avail Use% Montado em
/dev/sda5             977M   56K  851M   1% /mnt/sda5

Reparem que o tamanho real disponível para uso depende do sistema de arquivo. Geralmente, quanto mais seguro o sistema, maior o espaço utilizado para consistências e, consequentemente, menor o espaço "útil" disponível no disco. A excessão é o Ext2 se comparado ao Ntfs.

Nenhum comentário:

Postar um comentário