The following file described how to use fdisk to format a hard drive clearly.
How to format a hard drive on Ubuntu 12.04 using Fdisk
Today I will show you how to format a hard disk using Fdisk. Fdisk comes already installed on most modern Linux distributions by default.
For the purpose of this tutorial I will be using Fdisk on Ubuntu 12.04 to format a 16Gb USB penstick with the ntfs file system.
First we need to see what our 16Gb USB penstick is mounted as so open up a terminal and type:
sudo fdisk -l
and type your password when prompted. You should get a screenshot similar to the one below.
In this case my 16Gb USB penstick is mounted at /dev/sdc1.
sudo fdisk /dev/sdc1
and you should get the command prompt shown below.
Now we need to check the existing partitions on the penstick so type:
to get the screenshot below.
Now we know what is on the drive it is time to delete it so type:
You will then be asked for the partition number (1-4). In my case I have 4 partitions on the disk and I need to delete them all. So I will type 1 and this will erase the 1st partition only. I would then be left with partitions 2 – 4 and to remove these I would repeat the procedure until all the partitions have been erased.
We now need to set up the new partition so in your terminal type:
Because this is the first partition on the drive type:
You will now be asked for a partition number. Choose 1 and then press return. When asked to specify the First Sector choose the default by pressing Return. Again accept the default Last Sector by pressing Return.
Now that the partition parameters have been specified we need to write them to the hard drive and we do that by typing:
All that is left to do is to make the filesystem on the hard drive and to do that we type:
sudo mkfs -t ntfs /dev/sdc1
Next time I will show you how to accomplish the same task using GParted (for those who like a GUI).
A link with lots of information about GPT disk:
create a file system, (i.e., a system for organizing a hierarchy of directories, subdirectories and files) on a formatted storage device or media, usually a partition on a hard disk drive (HDD).
A partition is a logically independent section of a HDD. A formatted partition or disk is one to which a low level format, also called a physical format, has been applied. It consists of dividing the disk’s tracks into a specified number of sectors and filling the data area of each sector with dummy byte values or with a pattern of test values. This results in the destruction of any existing data on the disk. Formatting of new HDD and floppy disks is done at the factory. It is rarely necessary to perform a low level format on a HDD. Low level formats are more commonly performed on floppy disks (using the fdformat command) to prepare them for use with a different type of filesystem and operating system.
The creation of a filesystem is also referred to as high level formatting or logical formatting. It includes creation of a table of contents for the partition or disk, and it does not destroy data already on the partition or disk.
mkfs’s syntax is
mkfs [ -V ] [ -t fstype ] [ fs-options ] filesys [ blocks ]
mkfs -t type (ntfs,ext3 … …) /dev/sdb
The items in square brackets are optional, and the only mandatory argument (i.e., input) is filesys. filesys is the name of a device file (i.e., a file that the system uses to implement access to a physical device), such as /dev/hda3, the third partition on the first hard disk, or /dev/fd0, the first floppy disk drive. It can also be the mount point (i.e., the point where it is attached to the system) for the new filesystem, such as the root directory, /usr or /home.
The most commonly used option is -t, which is followed by the type of filesystem to be created. If this option is not used, the default is ext2 (second extended filesystem). Among the other types of filesystems that can be created are ext3, minix, msdos, vfat, ntfs and xfs.
As an example, the following would create an ext2 filesystem on a formatted floppy disk that has been inserted into the first floppy drive:
The following would be used to create a vfat (i.e., Microsoft Windows-compatible) filesystem on the second partition of the first HDD:
mkfs -t vfat /dev/hda2
The -V option produces verbose output, including all filesystem-specific commands that are executed. Specifying this option more than once prevents the execution of any filesystem-specific commands.
fs-options are filesystem-specific options that are to be passed to the real filesystem creation program (i.e., the program for which mkfs is serving just as a front end). Although not guaranteed, they are supported by most such programs. They are -c, which checks the device for bad blocks (i.e., defective areas on the storage medium) before building the filesystem, -l, which reads the bad blocks list from a file whose name follows it, and -v, which produces verbose output.
All generic options must precede and not be combined with filesystem-specific options. Some filesystem-specific programs do not support the -V option nor return meaningful exit codes (which indicate whether the command was successful or failed). Also, some filesystem-specific programs do not automatically detect the device size and thus require a blocks argument to be provided.
Although it is stated in the man built-in manual that mkfs is used to build a Linux file system on a device, the semantics might be a bit confusing if one thinks of the definition of a filesystem as being a hierarchy of directories. That is, mkfs does not actually create a hierarchy of directories, but rather it prepares a disk or a partition thereof so that a user can create a specific type of filesystem on it. Thus, it might be more appropriate to think of a filesystem as being a way of organizing directories and files rather than the hierarchy itself.
lshw -C disk