Format a device

From ArchWiki
Revision as of 04:48, 28 July 2012 by Fengchao (Talk | contribs) (Add merge request.)

Jump to: navigation, search

Merge-arrows-2.pngThis article or section is a candidate for merging with File Systems.Merge-arrows-2.png

Notes: Format it self is simple while know which format to use is hard. (Discuss in Talk:Format a device#)

This is an HOWTO about device formatting.

Warning: formatting a device removes everything on it, make sure to backup everything you want to keep.
Note: the authors of this article cannot be considered responsible of any data loss, hardware deterioration or any other problem related to this article.

Pre-requirements

Before starting, you need to know which name Linux gave to your device. All device nodes are placed in /dev by udev. Hard drives and USB sticks show up as /dev/sdX, where "X" is a lowercase letter, while partitions show up as /dev/sdxY, where "Y" is a number.

If the device you want to format is mounted, it will show up in the MOUNTPOINT column from:

$ lsblk

If your device is not mounted:

# mount /dev/sdxY /some/folder

And to unmount it, you can use umount:

# umount /dev/sdxY

Step 1: delete the previous partitions

For that you can use fdisk:

# fdisk /dev/<your_device>
Note: enter m for the help

Step 2: create the new file system

In console

To create a file system you just have to use mkfs:

# mkfs -t vfat /dev/<your_device>

As mkfs is just a unified front-end for the different mkfs scripts you need to install the packages providing these scripts.

e2fsprogs contains:

  • mkfs.ext2
  • mkfs.ext3
  • mkfs.ext4
  • mkfs.ext4dev

dosfstools provides FAT16 and FAT32 support:

  • mkfs.vfat
  • mkfs.msdos

ntfsprogs contains:

  • mkfs.ntfs

jfsutils contains:

  • mkfs.jfs

xfsprogs contains:

  • mkfs.xfs

reiserfsprogs contains:

  • mkfs.reiserfs

btrfs-progs contains:

  • mkfs.btrfs

Step 3: check

Now you can check the new file system with fsck:

# fsck /dev/<your_device>

GUI tools

There are several GUI tools for partition management: