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:
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 :
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 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
Number Start End Size Type File system Flags (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 fdisk. fdisk will verify and only write data to the disk upon exit. Here's how to remove any old partitions:
(parted) rm 1 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
PART-TYPE is one of: primary, logical, extended '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 And verified the created partition with (I used ext2 in this case as ext3 did not work for me in parted):
(parted) print
Number Start End Size Type File system Flags
(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
Device Boot Start End Blocks Id System 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 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.
[…] Red Hat Linux Fedora: Fedora 10 to Fedora 11 upgrade. LINUX / UNIX: Adding a new SATA harddrive using parted instead of fdisk. […]