Third party cookies may be stored when visiting this site. Please see the cookie information.

PenguinTutor YouTube Channel

Preparing an external disk drive for use with Linux - Ubuntu

Here is a quick rundown of the steps required to prepare an external disk drive with Ubuntu.

This has been tested with Gutsy Gibbon version 7.10, but should work for most versions.

These are the steps required to use and External Disk drive, tested with an 3.5" IDE disk drive in a portable case. You can get a whole variety of different external drives in a variety of shapes and sizes. They are particularly good as a cheap way of extending your storage particularly if you have a laptop (I have one dedicated for Video editing), or for a backup which is small enough to store away from the computer but stores enough information to backup everything you need.

This is a follow on, and uses similar commands to my earlier post: Adding a second hard disk to Linux

Disclaimer - Reformatting disks is destroys data!

Warning some of the commands used are destructive. Enter the wrong information and you can obliterate your entire computer. Ensure you always use the correct device names - the ones on my system may not be the same as yours!

I also recommend you make a backup of all your valuable date before starting.

Identify which device name has been given to the disk

The drive on my machine installed as /dev/sde (partition /dev/sde1). Make sure you know what disks are on your system so you don't overwrite the wrong one. Your "built in" drives may be /dev/hda, /dev/hdb etc. for IDE drives, but SATA and SCSI will probably be /dev/sda, and /dev/sdb. External drives wll normally appear as SCSI whatever their type.
In my case the reason for sde is that I have a built-in card ready with 4 different drive types, which occupy sda, sdb, sdc and sdd.

First physically attach the disk drive to the computer. If you have an existing partition then it should mount automatically and open in a window.

First see what drive letter was assigned by entering
mount
and look for the device name that was mounted. Then

Unmount the partition using your file browser or:

sudo umount /dev/sde1

If the disk doesn't mount then you can take a look for the device in the system log.
view /var/log/syslog
Enter "G" to go to the bottom of the file
Press a "?" followed by "usb-storage" and press enter - which will search backwards to see the message about the device being attached. The following line in the log will then normally give the device name.

Another way of finding the disk is to install the sg3-utils

sudo apt-get install sg3-utils

sudo sg_scan -i
/dev/sg0: scsi0 channel=0 id=0 lun=0 [em]
    IN-WIN    iAPP  HS-CF  0.96 [rmb=1 cmdq=0 pqual=0 pdev=0x0] 
/dev/sg1: scsi0 channel=0 id=0 lun=1 [em]
    IN-WIN    iAPP  HS-MS  0.96 [rmb=1 cmdq=0 pqual=0 pdev=0x0] 
/dev/sg2: scsi0 channel=0 id=0 lun=2 [em]
    IN-WIN    iAPP  HS-SM  0.96 [rmb=1 cmdq=0 pqual=0 pdev=0x0] 
/dev/sg3: scsi0 channel=0 id=0 lun=3 [em]
    IN-WIN    iAPP  HS-SD/MMC  0.96 [rmb=1 cmdq=0 pqual=0 pdev=0x0] 
/dev/sg4: scsi4 channel=0 id=0 lun=0 [em]
    Maxtor 6  Y160P0            YAR4 [rmb=0 cmdq=0 pqual=0 pdev=0x0] 

Mine is the Maxtor disk drive - and the others are for the different types of media (e.g. CF = Compact Flash, MS = Memory Stick, SM = Smart Media and SD/MMC).

This is then mapped to disk drives as:

sudo sg_map
/dev/sg0  /dev/sda
/dev/sg1  /dev/sdb
/dev/sg2  /dev/sdc
/dev/sg3  /dev/sdd
/dev/sg4  /dev/sde

Double check your disk drives using mount

After you have determined which disk drive you are going to edit - check it again using the mount command and make sure there are no mounted partitions on that disk.

mount

Partition the disk drive

Only proceed if you are 100% sure which disk drive is which. If still in doubt go back to the start of this and follow all the different techniques to check.

Now partition the disk using cfdisk. If using another distro you may need to use fdisk or disk druid.

Note you use the device for the disk, not a partition so it is just 3 letters and not 3 letters and a digit.
sudo cfdisk /dev/sde

Delete any existing partitions and create a new one. The default type is Linux, but if you want to be able to share the data with other computers choose FAT32 (0B). Note you can't set the label from here although it is shown.

When you write the changes any partitions that are being deleted will be wiped and any data lost.

Create the filesystem (formatting)

Once the partitions are laid down as required the partitions needs to be have the filesystem created (formatted). I chose to use ext3 as this is for use on Linux only. If you would like the disk to be accessible from Windows etc. then use VFAT.

The command for creating the file system (formatting) the disk is mkfs. This can be used with the -t option specifying the appropriate file system type or there are aliases for the common types.

In my case:
sudo mkfs.ext3 /dev/sde1

Note I am now using sde1 - which is the first partition, rather than sde which refers to the entire disk.

If I wanted to use the disk on Windows as well then I could use
sudo mkdosfs /dev/sde1

WARNING - this will delete any data on the specified disk. In this case it won’t even warn you. Make sure that you enter the disk name correctly, and double check it before hitting enter. YOU HAVE BEEN WARNED.

Label the disk

You can then label the disk. This gives the partition a name. This is not normally essential for an internal disk drive, but for an external drive it will determine the directory where the disk is automounted. I chose ExtBackup to signify an external backup device, but any appropriate label can be used as long as it is no more than 16 characters and preferably doesn't include spaces. Actually it can include spaces, but as I'm using it for backups it makes scripting much easier if it doesn't.

The label is case sensitive. You could make it all lower case to fit in with the Linux file structure better, but I've included capitals so that it makes it clear it is an external device.

For Ext2 / Ext 3 use

sudo e2label /dev/sde1 ExtBackup

For a Windows Compatible (VFAT / FAT32) first install mtools

sudo apt-get install mtools

then use:
mlabel -i /dev/sde1 ::ExtBackup

Check it works

If you then remove and reconnect the disk drive it should be automatically mounted at
/media/ExtBackup

Now the the automounter detects the disk then you should use the usual precautions about always unmounting the drive before physically disconnecting it. This is done by clicking on computer, and then right clicking on the disk or entering
sudo umount /media/ExtBackup

Backup Commands

You can then backup files to the external disk. There are many ways of doing this, but here are some suggestions: