Day 4 Linux: Disk partitions

Day 4 Linux: Disk partitions

Zero To Hero Linux Series

lsblk

We have only one physical disk xvda with three partitions of xvdaq1, xvdaq14 and xvdaq15.

Attach new disk of your choice.

Ex: I am attaching 4GB disk

Create new partition of Linux Type

sudo fdisk /dev/xvdbb

Our main objective here is to create a partition. To create a new partition, we use the command ‘n’. This will prompt you to specify the type of partition which you wish to create.

Alternatively, you can choose ‘p’ for a primary partition. For this tutorial, we will create a primary partition.

Partition number: 1

First sector : ENTER

Last sector: +1G ENTER

p for print partition table

wq for saving the changes

repeat same steps and create two more partitions

I have created total 3 primary partitions of each 1 GB size

Format the disks

sudo mkfs.ext4 -j /dev/xvdbb1

sudo mkfs.ext4 -j /dev/xvdbb2
sudo mkfs.ext4 -j /dev/xvdbb3

Create 3 directories to mount newly creted volumes

sudo mkdir /mnt_xvdbb{1..3}

Mounting Volumes

sudo mount /dev/xvdbb1 /mnt_xvdbb1
sudo mount /dev/xvdbb2 /mnt_xvdbb2
sudo mount /dev/xvdbb3 /mnt_xvdbb3
df -Th | grep 'dev/xvdbb'

umount /dev/xvdbb3

All these mount points are temporary in nature. Once we reboot the system, mounting will be reverted. To make it permanent, we must edit the File System Table of the Operating System. We should be highly careful while doing this operation. A small error in this file can cause the system to be unbootable and can make the entire system to be nonoperational. Let us open the file in any editor (I will be using the VI editor).

vi /etc/fstab

Add new 3 lines for three mount points

/dev/xvdbb1    /mnt_xvdbb1    ext4   defaults    0     0
/dev/xvdbb2    /mnt_xvdbb2    ext4   defaults    0     0
/dev/xvdbb3    /mnt_xvdbb3    ext4   defaults    0     0

Update filesystem table

sudo mount -a

Creating LVM Partition

If you want to create LVM partition

sudo fdisk /dev/xvdbb

m for help and q for quit

n for new partition

e for extended partition

l for list codes

8e for LVM

+100M

wq save changes

sudo mkfs.ext4 <disk path>