User Tools

Site Tools


ubuntu:disk:add_a_new_hard_disk_or_partition_using_uuid_and_ext4_filesystem

Ubuntu - Disk - Add a new hard disk or partition using UUID and ext4 filesystem

Adding a additional hard disk to your system.

This guide steps through the process of identifying the newly attached drive, preparing and mounting it by referencing UUID which is a preferred method today.

NOTE: If you have just added a virtual disk to a virtual machine, make sure you restart the virtual machine before mounting the new disk.


Determine the device name for the new disk

fdisk -l

This will give you output similar to this:

Disk /dev/sda: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders, total 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000299d1
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    32088063    16043008   83  Linux
/dev/sda2        32090110    33552383      731137    5  Extended
/dev/sda5        32090112    33552383      731136   82  Linux swap / Solaris
 
Disk /dev/sdb: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders, total 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

In this example, disk /dev/sdb doesn't contain a valid partition table.

This is most likely the new disk.


Partition the new disk

cfdisk /dev/sdb
  • New → Primary → Specify size in MB
  • Write → yes
  • Quit

Format the new disk

Using the ext4 filessystem

mkfs.ext4 /dev/sdb1

Create a mount point for the new disk

Create a new directory where the disk will be mounted in the filesystem.

mkdir /disk2

You can name the directory whatever your want and place it in a subfolder of another mounting point, for example /var/disk2.


Determine the UUID of the new disk

It’s preferred to use the device UUID (Universally Unique Identifier) instead of directly linking to the device path because while UUID always stays the same, the device path may change.

blkid

Which shows a list of all partitions and the assigned UUID.

The list should look similar to this:

/dev/sda5: UUID="267cab2a-340a-4f3d-7c8e-0c1df46b8bf7" TYPE="swap"
/dev/sda1: UUID="ce0c7b2c-bf50-4557-bc01-0048664a31d2" TYPE="ext4"
/dev/sdb1: UUID="389d90df-f15a-52f6-ab23-df13cf366de7" TYPE="ext4"

Update fstab

Add the new disk/partition to fstab to automatically mount it on boot

echo "UUID=389d90df-f15a-52f6-ab23-df13cf366de7 /disk2 ext4  errors=remount-ro 0 1" >> /etc/fstab

NOTE: Replace the UDID value to the UDID value displayed in the step above for the new disk and replace /disk2 with the path where you want to mount the disk, i.e. the mount point you created earlier.


Manually mount the disk

mount /disk2

NOTE: /disk2 is the directory created earlier.

Now your new hard disk is mounted and ready to use.

The disk will automatically be mounted at boot time too.

ubuntu/disk/add_a_new_hard_disk_or_partition_using_uuid_and_ext4_filesystem.txt · Last modified: 2020/07/15 09:30 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki