Linux: Commands to Add a New Disk

# Step 1: create partitioning table (gpt or msdos/mbr)
device=/dev/sdc
sudo parted $device mklabel gpt

# Step 2: Create primary partition and reserve the whole disk toward it
device=/dev/sdc
sudo parted -a opt $device mkpart primary ext4 0% 100%

# Step 3: Creating an ext4 file system
partition=/dev/sdc1
label=data
mkfs.ext4 -L $label $partition

# Optional: Change disk label
# partition=/dev/sdc1
# label=data
# e2label $partition data

# Step 4: Mount the new partition
mount=/media/data
partition=/dev/sdc1
mkdir -p $mount # create new mount point
mount $partition $mount # mounting partition toward new target mount point

# Add this line to /ect/fstab
LABEL=data /media/data ext4 defaults 0 2

# Reload mounts
mount -a
Posted on Categories Linux

Leave a Reply

Your email address will not be published. Required fields are marked *