Header Shadow Image


LINUX / UNIX: Adding a new SATA harddrive using parted instead of fdisk.

Here we'll go over how to connect, configure and format a SATA I / II hard drive on Linux.  The intent for this drive ultimately was to share the drive through SAMBA between our home PC's and to hold home movies from the Sony HDR-SR7 camcorder I have.  Ultimately, I will be using this drive and ffmpeg to convert movies from M2TS format to AVI format using the x264 codec available on Linux.  I'll need the space.

Here's how to go about doing just this:

The first thing you will need to do is to connect the drive.  My system already had two drives and I did not want to pack things any tighter as I would like to ensure space between devices.  This is to reduce heat buildup between hardware components.  Here's an image on how I ended up connecting the whole lot:

Device Setup showing spaces between components.

The drive I have is an older Western Digital WD2500KS drive that's been virtually sitting around collecting dust.  The motherboard is a K8V-X SE.  Because the motherboard didn't support SATA II as I found out after checking the manual, the first order of business was to downgrade the drive to SATA I using the jumper 5-6 settings :

Enabling SATA I through jumper 5-6

The motherboard supports Raid 0, 1 through SATA I (Version 1.0) however no SATA II (Version 2.0).  No choice here.

 

LINUX: PREPARING THE DRIVE

STEP DESCRIPTION COMMAND
1 Check if Linux can see the drive.

Run:

# fdisk -l
.
.
Disk /dev/sdc: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000f0f3b
.
.
#

If you get output similar to above, Linux can see your drive.  Note that device /dev/sdc has been assigned to it.

 2 Start partitioning tool on the device from step 2.

To start the parted CLI run below:

# parted /dev/sdc
GNU Parted 1.8.8
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: ATA WDC WD2500KS-00M (scsi)
Disk /dev/sdc: 250GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      32.3kB  206MB   206MB   primary  ext2         boot
 2      206MB   4310MB  4104MB  primary  linux-swap
 3      4310MB  250GB   246GB   primary  ext2

(parted)

Notice we used the parted print command to get some basic drive information including some old partitions still existing on the disk.

 3

WARNING: This step is not necessary if you have an empty drive.  As in my case I have a number of old partitions I will need to remove. ANY DRIVE DATA ON THESE PARTITIONS WILL BE DESTROYED.

 

Unlike fdisk, parted instantly removes the partition from the disk when you run the remove commands below.  For this reason, I believe parted is unsafe in this respect compared to fdiskfdisk will verify and only write data to the disk upon exit.  Here's how to remove any old partitions:

(parted) rm 1
(parted) rm 2
(parted) rm 3

(parted) print
Model: ATA WDC WD2500KS-00M (scsi)
Disk /dev/sdc: 250GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start  End  Size  Type  File system  Flags

(parted)

All partitions were removed.

 4 Create a new partition.  Here, I was not interested in making a bootable filesystem.  I was just interested in creating one large formatted disk partition for file storage and sharing purposes.

To make a new partition, it's good to find out what type of partitions are available through parted.  The command to make a partition is mkpart (type (parted) help to show other commands).  So to find out what parameters I needed to specify to mkpart, I typed:

(parted) help mkpart
  mkpart PART-TYPE [FS-TYPE] START END     make a partition

        PART-TYPE is one of: primary, logical, extended
        FS-TYPE is one of: ext3, ext2, fat32, fat16, hfsx, hfs+, hfs, jfs, linux-swap, ntfs, reiserfs, hp-ufs, sun-ufs, xfs, apfs2, apfs1, asfs, amufs5, amufs4,
        amufs3, amufs2, amufs1, amufs0, amufs, affs7, affs6, affs5, affs4, affs3, affs2, affs1, affs0
        START and END are disk locations, such as 4GB or 10%.  Negative values count from the end of the disk.  For example, -1s specifies exactly the last
        sector.

        'mkpart' makes a partition without creating a new file system on the partition. FS-TYPE may be specified to set an appropriate partition ID.

I followed this by running this line:

(parted) mkpartfs primary ext2 0 -1s
writing per-group metadata… 85%       (time left 00:13)

And verified the created partition with (I used ext2 in this case as ext3 did not work for me in parted):

(parted) print
Model: ATA WDC WD2500KS-00M (scsi)
Disk /dev/sdc: 250GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start  End    Size   Type     File system  Flags
 1      512B   250GB  250GB  primary  ext2

(parted) quit
#

 

5 Verify with fdisk that the partition exists and mount it.

Again, run fdisk to check the status of the new partition:

# fdisk -l /dev/sdc

Disk /dev/sdc: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000f0f3b

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1       30402   244198583+  83  Linux
#

Create a folder such as /mnt/homevideos or /media/sdc-drive like this:

# mkdir /mnt/homevideos

OR

# /media/sdc-drive

Mount the new drive:

# mount -v /dev/sdc1 /mnt/homevideos

 

6 Add the configuration to /etc/fstab to mount the drive everytime you start up.

Add this entry to the /etc/fstab file to automount the partition whenever the system is booted up:

# cat /etc/fstab
.
.
/dev/sdc1               /mnt/homevideos         ext2    defaults        0 0
.
.
#

You're done!

Granted, EXT2 filesystem really isn't the best choice here and when I have time I'll see if I can change that to either XFS, EXT3 or better yet, EXT4.  Unfortunately, EXT3 and XFS were not available through parted.

Cheers!
Tom K.

Leave a Reply

 


     
  Copyright © 2003 - 2013 Tom Kacperski (microdevsys.com). All rights reserved.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License