Formatting a drive

The Pi is capable of reading and writing to NTFS, which Windows uses. It can also
read/write HFS+, which is used by Macintosh. Both these methods are fine for
temporary attachment of removable media if you need to copy something quickly.
The NTFS and HSF+ filesystems are not native to Linux, and they take a lot of
overhead to convert data between what Linux understands and what the other
filesystems understand. Some unexpected errors might occur and cause loss of
data, which nobody wants!
Ext4 is the preferred storage filesystem in Linux. Media mounted using this
filesystem in Linux is really fast and reliable. There are ways to use it on Mac OS X
and Windows, but that is not the goal of this chapter. You should commit to using
the media as a long term storage that will stay connected to the Pi as long as you
would like it to work, hidden behind the coach or in the wardrobe—out of sight.

A word of warning: this step will destroy all data and create an
Ext4 partition.

This command will quickly remove everything from your hard drive, including
partitions and boot sectors. Be sure to use the correct device name that you saw in
fdisk. In this case, it is sda, but you need to double check this on your Pi as it may
be different. This can be done using the following command:

dd if=/dev/zero of=/dev/sda bs=512 count=1

Now, we will create a new partition using fdisk. I want to use the entire drive and
use defaults that fdisk provides. You can use the m command in fdisk at any time
for more help as shown in the following command line snippet:

fdisk /dev/sda
n "new partition"
<enter> "Uses p as the default"
<enter> "Uses 1 as the default"
<enter> "Uses default first sector"
<enter> "Uses last sector available on drive"
w "write partition data and exit"
The last line is used to write the Ext4 filesystem on the newly created partition
found at sda1. The –L flag in the following command line provides the name
of the partition. You can use any short name that you like.
sudo mkfs.ext4 /dev/sda1 –L nas001

No comments:

Post a Comment