Storage device information (partitioning, formatting and mounting in Linux)
Disk drive and partition information
To find out information about disk drives and partitions on a system from the terminal, type:
# [root] fdisk -l
Partitioning
A drive can be partitioned using the fdisk utility. Start fdisk using the following command:
# [root] fdisk /dev/hdDrive
The command above is where /dev/hdDrive is the location of your device. See disk drive and partition information to find out the location of your drive.
Some basic fdisk commands include:
- m - lists the options available
- p - prints the partition table
- n - creates a new partition
- d - deletes a partition
- q - quit without saving changes
- w - write the new partition table and exit
Formatting
All storage devices require some form of file system so that they can be used by an operating system.
The most popular file systems in use for Linux desktop computers are ext2 and ext3. Simply put, ext3 is a newer version of ext2 with journalling, which allow the system to recover from serious errors more easily.
A device can be formatted using the utility mke2fs. Start mke2fs using the following command:
# [root] mkfs.ext3 -m /dev/hdDrive
Mounting and unmounting
Mount:
To mount a drive use the following command:
# [root] mount /dev/hdDrive /mnt/hdDrive
Note: The command above is where /dev/hdDrive is your drive and /mnt/hdDrive is your mount point.
Tip: A mount point is just a directory on your system. You can create a directory using
mkdir. For example:
# mkdir /mnt/hdDrive
Unmount:
To unmount a drive use the following command:
# [root] umount /mnt/hdDrive
Note: The command above is where /mnt/hdDrive is your mount point.
Auto mount:
To auto mount a drive at start up, edit the fstab file using the following command:
# [root] vi /etc/fstab
A new line needs to be added to the end of the file. This should contain the following:
- The device location (1st column)
- The mount point (2nd column)
- The file system type (3rd column)
- Other options
An example drive mounted as ext3, would be:
- /dev/hdDrive /mnt/hdDrive ext3 defaults 0 0
Tip: Always make sure there is a carriage return at the end of the last line or else the device will not mount.
Adding a new hard disk drive (complete steps)
- The examples below are where:
- /dev/hdDrive is the location of your device.
- /mnt/hdDrive is the mount point.
- Physically install the hard drive and boot up the computer.
- If the device has been recognised it will have been given a location on the system but will not be accessible until it is formatted and mounted. To find out the location of the drive, use the fdisk command:
# [root] fdisk -l
- Once you have found the location of your drive, you can use fdisk to partition it:
# [root] fdisk /dev/hdDrive
- Enter p to view the partition table. Here you can check for any existing partitions and check you are partitioning the correct drive by checking the size is as you expected.
- To delete an existing partition, enter d and press return.
- To create a new primary partition, enter n, press return and then enter p. When asked for a number enter 1.
- Next you will be asked which cylinder the partition should begin and then end at. You can accept the default values for both of these by just pressing return at each prompt.
- Now back at the fdisk command prompt, enter w to write the partition table and exit fdisk.
- Format the drive (as ext3):
# [root] mkfs.ext3 -m /dev/hdDrive
- Create a directory to mount the drive in:
# [root] mkdir /mnt/hdDrive
- To auto-mount the drive on boot, open the fstab file:
# [root] gedit /etc/fstab
- Add the following line to the end of fstab:
- /dev/hdDrive /mnt/hdDrive ext3 defaults 0 0
Tip: Always make sure there is a carriage return at the end of the last line or else the device will not mount.
- Restart the system.
The new drive should now be accessible from the mount point you created in step 5.
Accessing a USB drive:
- The examples below are where:
- /dev/usbDrive is the location of your device.
- /mnt/usbDrive is the mount point.
- Insert the USB drive into an available slot.
- If the device has been recognised it will have been given a location on the system but will not be accessible until it is mounted. To find out the location of the drive, use the fdisk command:
# [root] fdisk -l
- Create a directory for the USB drive using the following command:
# [root] mkdir /mnt/usbDrive
- Mount the USB drive:
# [root] mount /dev/usbDrive /mnt/usbDrive
Go back to the How-to Guides main page.