“Add & Install a new HDD on Ubuntu 18.04 LTS Server Edition”

AUTO MOUNT

 

1 STEP – AUTOMATIC MOUNT AT BOOT

We have added a hard disk of 1TB capacity on an existing servers to be auto mounted as a /StorageVm partition at next boot. To manage that fdisk is a command line utility to view and manage hard disks and partitions on Linux systems.

1.1 PARTITION THE NEW HDD

If the drive is still blank and unformatted, we can formatting the drive using the command line

$: sudo fdisk -l
Disk /dev/loop0: 87 MiB, 91160576 bytes, 178048 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 /dev/loop1: 54.6 MiB, 57229312 bytes, 111776 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 /dev/sda: 278.5 GiB, 298999349248 bytes, 583983104 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
Disklabel type: gpt
Disk identifier: 631BE3B6-EFA6-4135-B213-C4B7D677ACA4

Device       Start       End   Sectors  Size Type
/dev/sda1     2048   1050623   1048576  512M EFI System
/dev/sda2  1050624 583981055 582930432  278G Linux filesystem

Disk /dev/sdb: 3.6 TiB, 3995997306880 bytes, 7804682240 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
Disklabel type: dos
Disk identifier: 0x94014387

then lets’ begin with the procedure

$: sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-4294967295, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-4294967294, default 4294967294): 

Created a new partition 1 of type 'Linux' and of size 2 TiB.
Command (m for help): w
The partition table has been altered.
Failed to add partition 1 to system: Device or resource busy

The kernel still uses the old partitions. The new table will be used at the next reboot. 
Synching disks.

then

$: sudo mkfs -t ext4 /dev/sdb1
mke2fs 1.44.1 (24-Mar-2018)
/dev/sdb1 contains a ext4 filesystem
last mounted on Wed Aug 29 13:52:29 2018
Proceed anyway? (y/N) y
/dev/sdb1 is mounted; will not make a filesystem here!

and finally

$: sudo mkfs -t ext4 /dev/sdb1
mke2fs 1.44.1 (24-Mar-2018)
/dev/sdb1 contains a ext4 filesystem
last mounted on Wed Aug 29 13:52:29 2018
Proceed anyway? (y/N) y
Creating filesystem with 536870655 4k blocks and 134217728 inodes
Filesystem UUID: 7cdb6e60-b655-4f15-9a8c-982154ac2194
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848, 512000000
Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done

1.2 CREATE A MOUNT POINT

Now that the drive is partitioned and formatted, we need to choose a mount point. This will be the location from which you will access the drive in the future.

$: sudo mkdir /media/StorageVM

1.3 AUTOMATIC MOUNT AT BOOT

to make these last task we need to know the UUID of our new HDD, the command to know that is

$: ls -al /dev/disk/by-uuid/
total 0
drwxr-xr-x 2 root root 100 Aug 29 14:57 .
drwxr-xr-x 7 root root 140 Aug 29 13:52 ..
lrwxrwxrwx 1 root root  10 Aug 29 13:52 421A-0CA5 -> ../../sda1
lrwxrwxrwx 1 root root  10 Aug 29 14:57 7cdb6e60-b655-4f15-9a8c-982154ac2194 -> ../../sdb1
lrwxrwxrwx 1 root root  10 Aug 29 13:52 8d1e89e0-7b7d-4935-8276-401d611eaba1 -> ../../sda2

now edit fstab file

$: sudo nano /etc/fstab

and add the line as we made

UUID=7cdb6e60-b655-4f15-9a8c-982154ac2194        /media/StorageVm       ext4    defaults 0      0
$: sudo reboot

Also that one is completed, see you next time


“cya to the next 1…. Njoy !”
bye dakj

Disclaimer: All the tutorials included on this site are performed in a lab environment to simulate a real world production scenario. As everything is done to provide the most accurate steps to date, we take no responsibility if you implement any of these steps in a production environment.

“We learn from our mistakes”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.