Adding additional disk on Linux

Adding additional disks on linux is very easily done using a few commands. Recently I bought a 2 Terabyte Crucial SSD to expand my homeservers storage and this is how I configured it.

After plugging in the drive and powering on the computer we are going to partition our new drive first. Show which device you would like to partition by using lsblk. Please be careful and choose the correct device subsequently since the commands we are going to run will wipe all data. In my case my drive was assigned as /dev/sdb.

1# lsblk
2NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
3sda      8:0    0 238,5G  0 disk 
4├─sda1   8:1    0  55,9G  0 part /
5├─sda2   8:2    0    48M  0 part /boot/efi
6└─sda3   8:3    0 182,6G  0 part /home
7sdb      8:32   0   1,8T  0 disk 

Since we identified which device we would like to partition we are now going to run the fdisk utility on /dev/sdb as shown below.

 1# fdisk /dev/sdb
 2Welcome to fdisk (util-linux 2.34).
 3Changes will remain in memory only, until you decide to write them.
 4Be careful before using the write command.
 5
 6Device does not contain a recognized partition table.
 7Created a new DOS disklabel with disk identifier 0xba702876.
 8
 9Command (m for help): n
10Partition type
11   p   primary (0 primary, 0 extended, 4 free)
12   e   extended (container for logical partitions)
13Select (default p): p
14Partition number (1-4, default 1): 
15First sector (2048-3907029167, default 2048): # Press enter 
16Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-3907029167, default 3907029167): # Pressing enter here creates 1 partition with all the amount this SSD has. To create a smaller partition type for example +1T
17
18Created a new partition 1 of type 'Linux' and of size 1,8 TiB.
19
20Command (m for help): w
21The partition table has been altered.
22Calling ioctl() to re-read partition table.
23Syncing disks.

Then we are going to create a ext4 filesystem on the partition we just created.

 1# mkfs.ext4 /dev/sdb1
 2ke2fs 1.45.5 (07-Jan-2020)
 3Creating filesystem with 488378390 4k blocks and 122101760 inodes
 4Filesystem UUID: 6a5af775-b741-4kdf-8950-ac306c9383e5
 5Superblock backups stored on blocks: 
 6	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
 7	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
 8	102400000, 214990848
 9
10Allocating group tables: done                            
11Writing inode tables: done                            
12Creating journal (262144 blocks): done
13Writing superblocks and filesystem accounting information: done

After creating the filesystem please note down the UUID as shown above. We need this to mount it later by UUID in the /etc/fstab file. To show it again use sudo blkid like shown below.

1# sudo blkid
2/dev/sda1: UUID="191D-06A1" TYPE="vfat" PARTUUID="ld391822-3hf9-4dob-a747-e242d71f4c64"
3/dev/sda2: UUID="303k096e-8540-4fm2-9ide-7kka294a087d" TYPE="ext4" PARTUUID="51133608-6e96-4172-anbo-fp14143edf10"
4/dev/sda3: UUID="f2a450a1-6595-0f4a-8i8b-f81f19de595b" TYPE="ext4" PARTUUID="a2567p87-64de-49k2-a016-8k0e24590f97"
5/dev/sdc1: UUID="6a5af775-b741-4kdf-8950-ac306c9383e5" TYPE="ext4" PARTUUID="bv702076-02"

Next we create the directory where we want to mount the partition.

# mkdir /data

And finally we add another entry in /etc/fstab to automatically mount the partition at boot time. (Ubuntu 20.04 LTS)

/dev/disk/by-uuid/6a5af775-b741-4kdf-8950-ac306c9383e5 /data ext4 defaults 0 0

Now if we did everything correctly we can issue a mount -a on the terminal to mount our newly added drive and enjoy the additional space!