How to create a partition and mount it

  devops, linux
# be root
sudo su

# list partitions
fdisk -l

Disk /dev/sdb: 1.82 TiB, 1999307276288 bytes, 3904897024 sectors
Disk model: PERC 6/i Adapter

# /dev/sdb is a PERC 6i RAID that's not set up

# create a new partition on /dev/sdb
fdisk /dev/sdb

# p to print

Command (m for help): p
Disk /dev/sdb: 1.82 TiB, 1999307276288 bytes, 3904897024 sectors
Disk model: PERC 6/i Adapter


# n for new, p for primary, ENTER to use defaults:

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): <ENTER>
First sector (2048-3904897023, default 2048): <ENTER>
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-3904897023, default 3904897023): <ENTER>

Created a new partition 1 of type 'Linux' and of size 1.8 TiB.

# write and exit
w

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.


# format it as well
mkfs.ext4 /dev/sdb1

mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 488111872 4k blocks and 122028032 inodes
Filesystem UUID: 1499df2f-ee6e-4e1e-ba9a-a7ad8ffc0b1b
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
        102400000, 214990848

Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done

# create the dir where the mount will stay
mkdir /mnt/raid

# try mounting the drive manually first, before adding it into fstab
mount -t ext4 /dev/sdb1 /mnt/raid

# check it
cd /mnt/raid
df -h .

Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb1       1.8T   28K  1.7T   1% /mnt/raid

# it looks good

# unmount it
cd /mnt
umount /mnt/raid

# next, add it to fstab, by block id

# get the block id
blkid /dev/sdb1

/dev/sdb1: UUID="1499df2f-ee6e-4e1e-ba9a-a7ad8ffc0b1b" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="cd204155-01"


# edit fstab
nano /etc/fstab

# add at the bottom:
UUID="1499df2f-ee6e-4e1e-ba9a-a7ad8ffc0b1b" /mnt/raid ext4 defaults 0 1

# mount it
mount -a

# check
df -h /mnt/raid

# now on reboot, it'll auto-mount