Friday, 16 September 2016

Ubuntu new external Hard Drive setup partitioning, formatting and tuning

# Checking the location of the new drive. It is /dev/sdb.
sudo lshw -C disk

# Creating the GUID Partition Table (GPT)
sudo parted /dev/sdx mklabel gpt

# Checking that the GPT has been created
sudo parted /dev/sdx print

# see 6001175MB size
sudo parted /dev/sdb print unit MB print free

# Creating partition label
sudo parted --align optimal /dev/sdx mkpart primary ext4 0% 100%

# Creating the partition
# -b sets the block size (do not use for standard drive, set to 64k (65536) if mostly video and images large files

sudo mkfs.ext4 -b size=65536 /dev/sdx1

# Check the drive surface for bad blocks
# -n is non destructive test, it takes longer but does not destroy data on the disk
# -w is destructive (and faster) and will write over any data on the drive
# -s shows progress indicator
# -b specifies the blocksize which is optional but will speed up the scan
# -f force checking even if the volume seems clean
# -c the size of the block written for each test, speeding up the test but using more memory

sudo badblocks -nsvf -b 4096 -c 65536 /dev/sdx
sudo badblocks -wsvf -b 4096 -c 65536 /dev/sdx

sudo badblocks -nsvf -b 65536 -c 1024 /dev/sdx
sudo badblocks -wsvf -b 65536 -c 1024 /dev/sdx

# NOTE - Smartmontools smartctl tests will be a better faster test than badblocks
The SMART surface test is almost certainly a single, and certainly non-destructive, read pass. As has been pointed out it is also internal to the drive; with the possible exception of minor control data, no data is being passed to or from the host during the test.

On the other hand, badblocks -w makes four passes over the drive, each with one write and one read. That alone accounts for an 8× difference in time taken for the test, plus rotational latency. Since it's software running on the host, all that data needs to be shuffled through the disk interface to RAM and handled by the software (badblocks, in our case).

# -t type of test
# -C run the test in the foreground

sudo smartctl -t long -C /dev/sdx

# Show the test results

sudo smartctl -a /dev/sdx


# mount the drive on a folder
sudo mount /dev/sdx1 /media/usb

# Remove reserved blocks (i.e. set to 0%), since this drive is just for user data
sudo tune2fs -m 0 /dev/sdx1

No comments:

Post a Comment