How To Mount A Drive In Linux

This simple step by step guide will show you how to mount a new hard drive or partitions onto your Linux server

Initially you wanna check the hard drives on your system

fdisk -l

so now you now whats being seen by the system

Command Line

mount /dev/partitionId /some/mounting/point
for example
mount /dev/sdb /backup

The mounting point path must already be created with proper permissions. So a more likely flow of commands would be below:

Command Line

mkdir /some/mounting/point
chmod 777 /some/mounting/point
mount /dev/partitionId /some/mounting/point
for example:
mkdir /backup
chmod 777 /backup
mount /dev/sdb /backup
Now you just need to add the addon hard drive into fstab to be booted on startup as well
nano /etc/fstab

How To Unmount A Drive In Linux

Command Line

umount /dev/partitionId

This command is very easy to type wrong. It is NOT unmount. Take another closer look if thats what you saw at first. It is umount — no n here!

How to Add a New Disk to an Existing Linux Server

fdisk is a command line utility to view and manage hard disks and partitions on Linux systems.

# fdisk -l

This will list the current partitions and configurations.

Find linux partition details

After attaching the hard disk of 20GB capacity, the fdisk -l will give the below output.

Find new partition details

New disk added is shown as /dev/xvdc. If we are adding physical disk it will show as /dev/sda based of the disk type. Here I used a virtual disk.

To partition a particular hard disk, for example /dev/xvdc.

# fdisk /dev/xvdc

Commonly used fdisk commands.

n – Create partition
p – print partition table
d – delete a partition
q – exit without saving the changes
w – write the changes and exit.

Here since we are creating a partition use n option.

Create new partition in linux

Create either primary/extended partitions. By default we can have upto 4 primary partitions.

Create primary partition

Give the partition number as desired. Recommended to go for the default value 1.

Give the value of the first sector. If it is a new disk, always select default value. If you are creating a second partition on the same disk, we need to add 1 to the last sector of the previous partition.

Assign sector to partition

Give the value of the last sector or the partition size. Always recommended to give the size of the partition. Always prefix + to avoid value out of range error.

Assign partition size

Save the changes and exit.

Save partition changes

Now format the disk with mkfs command.

# mkfs.ext4 /dev/xvdc1

Format new partition

Once formatting has been completed, now mount the partition as shown below.

# mount /dev/xvdc1 /data

Make an entry in /etc/fstab file for permanent mount at boot time.

/dev/xvdc1	/data	ext4	defaults     0   0
Conclusion

Similar Posts