138

I am going to put an additional (non-USB) hard drive in my system. I already have Ubuntu on my other hard drive so I do not want to install Ubuntu on the additional drive but only use it for storage. How do I add the additional hard drive to my Ubuntu system, e.g. make Ubuntu recognize it and mount it properly?

N.N.
  • 18,219
  • 2
    I thought it would make sense to have a general question for this issue. I tried to find one and asked in chat for one without success. Hint: https://help.ubuntu.com/community/InstallingANewHardDrive – N.N. Apr 26 '12 at 06:45
  • Good idea! Wish I'd found it before I answered this: http://askubuntu.com/questions/488213/how-to-add-a-second-hard-drive-to-an-already-installed-xubuntu-14-04. Perhaps they could be merged. – Elder Geek Jul 04 '14 at 15:56

4 Answers4

125

1 Partition

The easiest and user-friendly way is probably to use gparted after you have installed your new HDD and boot your machine:

sudo gparted

Then you create partitions, by setting their size and type.

  • If a partition table does not exist yet, you likely want to choose the type as gpt for Ubuntu-only machines and msdos (aka MBR) for dual-boot Ubuntu/Windows machines. See this forum post for additional discussion
  • Since your hard drive is additional storage space, you probably want to create one single big partition with the type of ext4
  • After adding the new partition, make sure that the left-most partition column shows a true filepath (i.e. /dev/sdb1) rather than a placeholder like "New partition #1". If you see the latter, click "Edit > Apply all operations" from the top-bar to actually execute the new partition. Otherwise, it is just in a pending state and your mount will fail in step 2.3

Screenshot of gparted

gparted is a very easy to use tool, and yet very advanced.

2 Mount

After you are done creating your partitions (most likely it will be just one ext4 data partition, since this is your additional storage drive), you need to permanently mount it.

At this step you already know what names your new partition(-s) have. If not sure, following command will remind you about existing drives and partitions on them:

sudo fdisk -l

This will output something like this (intentionally skipped /dev/sda system drive info):

Disk /dev/sda: 250.1 GB, 250059350016 bytes
....

Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes 255 heads, 63 sectors/track, 243201 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk identifier: 0x000814e3

Device Boot Start End Blocks Id Syste /dev/sdb1 1 243201 1953512001 83 Linux

Output states, that your new partition is /dev/sdb1. Now you need to mount it to utilize it's precious space. To achieve this, you need to perform three simple steps:

2.1 Create a mount point

sudo mkdir /hdd

2.2 Edit /etc/fstab

Open /etc/fstab file with root permissions:

sudo vim /etc/fstab

And add following to the end of the file:

/dev/sdb1    /hdd    ext4    defaults    0    0

2.3 Mount partition

Last step and you're done!

sudo mount /hdd

Links

  • 1
    Good answer. I think you can improve on it in some ways though. You may want to add a warning that you should only partition is it is a new drive or if you want to lose the data on the drive. Could you please add a short explanation of what mounting means and why you need to add the drive to /etc/fstab? Also, could you please add an explanation of what each part of the /etc/fstab entry means? – N.N. Apr 26 '12 at 09:23
  • 2
    You say you think my proposal is reasonable but you have not edited your answer accordingly. – N.N. Dec 29 '12 at 20:05
  • For more information on fstab, https://help.ubuntu.com/community/Fstab – jchook Oct 22 '17 at 18:25
  • 1
    Small thing, that last mount command requires sudo. – Dave Remy Jul 28 '18 at 14:01
  • 4
    This answer is good but is mounting the disk via the device name /dev/sd??, which could change. UUID is preferred for mounting disks in Ubuntu now. This other answer discusses using blkid to find the UUID and add it to fstab. https://askubuntu.com/revisions/932362/2 – Nelson Nov 18 '18 at 16:58
  • @AndrejsCainikovs cool. Thanks for teaching me an important lesson. – Rishabh Agrahari Jun 20 '19 at 13:13
  • Also missing the step where you actually create a filesystem on it.

    sudo mkfs.ext4 /dev/sdb1

    – Kerel Feb 19 '20 at 13:07
  • Does this simply add space to the existing hard drive? In other words, can you just keep adding files in your home drive or desktop or whatever? Or do you have to out them into a separate folder somewhere else, like you normally do with a thumb drive or whatever? – Dr Xorile Mar 14 '20 at 00:28
  • @DrXorile, this is a separate drive under a dedicated mount point (directory). If you need to combine multiple physical drives into a single storage, you have to use RAID. – Andrejs Cainikovs Mar 14 '20 at 00:36
  • Where does ext4 come from? – Tim Randall Feb 25 '21 at 20:40
  • @TimRandall ext4 is the most popular filesystem type on Linux. There are other types as well, but if you're asking this question you probably don't need to be aware about them. – Andrejs Cainikovs Feb 28 '21 at 14:00
  • 1
    I think CLI is a better approach to everything. So like what do you do when you SSH into your first remote server as a junior sysadmin and you learned only GUI stuff? How do you even start a GUI app on a cli terminal? Just my 2 cents here. That happened to me. ALl the time. – avia May 14 '21 at 12:37
  • 1
    Works perfect. I had to mount an external ssd in /home path, to allow installed programs via snap like mysql-workbench. Thanks. – Rafael Guimarães Sep 19 '21 at 16:55
  • What is the difference between the value of <pass> in /etc/fstab/ in this answer (0) vs. the answer above (2)? @AndrejsCainikovs and @anatoly-techtonik can you clarify? – arash Oct 01 '21 at 12:02
  • @arash: man fstab, check sections The fifth field and The sixth field. – Andrejs Cainikovs Oct 03 '21 at 16:08
55

Modern drives are huge and need to be partitioned with GPT to allow 2TB+ in size.

  1. Find your disk:

    sudo blkid
    

    If it is already formatted, you should see entry like /dev/sdb1 with UUID and PARTUUID settings.

  2. If your disk is not formatted, create a new partition:

    sudo cgdisk /dev/sdb
    

    and format it:

    sudo mkfs -t ext4 /dev/sdb1
    
  3. Create directory for your hdd:

    sudo mkdir /media/storage
    
  4. Run sudo blkid again, note the UUID of your /dev/sdb1 partition and add it into /etc/fstab (make a backup of fstab by installing etckeeper - this file is important):

    UUID="b4c93..."  /media/storage  ext4  defaults  0  2
    

    fstab wiki page describes what does it mean. This should make it persistent over reboots.

  5. Finally mount it without rebooting to test:

    sudo mount -av
    
  • 1
    blkid needs to be executed as root or there won't be any output. I am trying to mount my third hdd, sda and sdb are already taken so I type in cgdisk /dev/sdc. However, the output is Could not load partitions from '/dev/sdc'! Aborting! – Torsten Mar 11 '18 at 08:22
  • These instructions could be clearer. – mmann1123 Apr 07 '18 at 03:03
  • Sorry, downvoted because 'sudo blkid' does NOT show a new disk. Hence, after that you still don't know that you need to run cgdisk on /dev/sdb or whatever. – Carlo Wood Apr 12 '20 at 19:26
  • also downvoted because I can't find a new disk by "blkid" – Marco Rohner Apr 28 '20 at 12:53
  • for your /etc/fstab the first parameter is UUID= why do you do the UUID instead of the /dev/name? – Trevor Boyd Smith Apr 23 '21 at 12:46
  • thank you both (all) that was helpful and I could mount everything properly thanks – avia May 14 '21 at 12:35
27

First you need to identified the new hard disk.

press CTRL+ALT+T to open a console then type :

lsblk

You will see something similar with this:

loop0    7:0    0 86.6M  1 loop /snap/core/4486
sda      8:0    0    5G  0 disk 
├─sda1   8:1    0  512M  0 part /boot/efi
└─sda2   8:2    0  4.5G  0 part /
sdb      8:16   0   10G  0 disk
sr0     11:0    1 1024M  0 rom 

For example the sdb it's the new hard disk that you want to add.

If the sdb it's a new hard disk , you need to format to ext3 or ext4

sudo mkfs.ext4 -j -L NewHDD /dev/sdb

Keep in mind, command above will delete everything on target hard disk. You can skip this step if there are any data on the hard disk and you want to not lose them.

Now you need the UUID of the new hard disk.

sudo blkid /dev/sdb

You will see something similar with this:

/dev/sdb: LABEL="NewHDD" UUID="5d6c8f68-dcc8-4a91-a510-9bca2aa71521" TYPE="ext4"

next step it's to add the new hard disk in fstab for auto mount after reset:

sudo nano /etc/fstab

And add new line on bottom, with follow content:

/dev/disk/by-uuid/5d6c8f68-dcc8-4a91-a510-9bca2aa71521 /mnt/NewHDD auto nosuid,nodev,nofail,x-gvfs-show,x-gvfs-name=NewHDD 0 0

Remeber to replace the 5d6c8f68-dcc8-4a91-a510-9bca2aa71521 and /mnt/NewHDD with your own UUID and path where will be mounted, CTRL+X then press Y and ENTER to save it.

To mount it use: sudo mount -a , if the result will be:

mount: /mnt/NewHDD: mount point does not exist.

You must create mount point sudo mkdir /mnt/NewHDD then use again: sudo mount -a

Also you need to change owner and group of the new hard disk using next command:

sudo chown user:user -R /mnt/NewHDD

Replace the: user:user with your own user and group that you need it.

anonymous2
  • 4,298
12

There is a good description how to add another drive here:

Basically you have to partition the new disk, create a file system on it and then mount it. Thats is the easy way. Another way would be to use lvm and create virtual disks on the new drive. That would give you more flexibility:

Jorge Castro
  • 71,754
Ruediger
  • 2,182
  • 6
    Answers are generally expected to be self-sufficient. Could you please provide explicit instructions rather than links to make your answer better? – N.N. Apr 26 '12 at 09:17
  • 1
    Especially because, the URLs you linked to; are no longer operational – ZaxLofful May 17 '22 at 07:11