Code Snippet

Just another Code Snippet site

[How-To] CentOS & RHEL

Create a new PV / VG / LV from an empty disk

# To retrieve the drive name 
lsblk

Create partition with fdisk

fdisk /dev/sdX
p # print partition table
n # create new partition
p # type = primary partition
ENTER # partition number (default or a value)
ENTER # default - start at beginning of disk
ENTER # 100 MB boot partiton
t # change partition's type
8e # type : Linux LVM
w # write changes

Create PV / VG / LV

# Create PV
pvcreate /dev/sdX1
vgcreate vg_NAME  /dev/sdX1
lvcreate -n lv_NAME -l 100%FREE vg_NAME
mkfs -t ext4 /dev/vg_NAME/lv_NAME # -t disk type (ext4, xfs, etc)

Edit /etc/fstab & mount drive:

/dev/mapper/vg_NAME-lv_NAME        /MOUNT_POUNT                 ext4     defaults        0 0
mkdir /MOUNT_POUNT # create mount point
mount -a # mount fstab content

———-
Extend an existing partition by adding a new disk

Create a new PV / VG / LV from an empty disk

# To retrieve the drive name 
lsblk

Create partition with fdisk

fdisk /dev/sdX
p # print partition table
n # create new partition
p # type = primary partition
ENTER # partition number (default or a value)
ENTER # default - start at beginning of disk
ENTER # 100 MB boot partiton
t # change partition's type
8e # type : Linux LVM
w # write changes

Create PV / VG / LV

# Create PV
pvcreate /dev/sdX1

#Retrieve the VG to extend with : 
vgdisplay

# Extend VG
vgextend vg_NAME  /dev/sdX1

# With the utility pvscan you can see what physical volumes are available, and how much free space there is within them
pvscan

# Extend LV
lvextend /dev/vg_NAME/lv_NAME /dev/sdX1

# Resize disk 
xfs_growfs  /dev/vg_NAME/lv_NAME
or 
resize2fs /dev/vg_NAME/lv_NAME

# Check result
lsblk
df -h

, , ,


17 thoughts on “[How-To] CentOS & RHEL

Leave a Reply

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