How to create LVM in centos 6

create LVM

in this post, I'm demo "How to create LVM in centos 6". To run commands as root account!.

The scripts for create LVM (Logical Volume Management):
OS: Centos
HDD1: /dev/sdb
HDD2: /dev/sdc

Step 1: Adding a new partition use fdisk command

fdisk /dev/sdb1
fdisk /dev/sdc1
The output as bellow
Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305):
Using default value 1305
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

Step 2: Select the physical Storage Device for LVM use pvcreate, pvscan, pvdisplay command.

pvcreate /dev/sdb1 /dev/sdc1
pvscan
pvdisplay
The output as bellow
[root@node1 ~]# pvcreate /dev/sdb1 /dev/sdc1
 --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               VolGroup
  PV Size               19,51 GiB / not usable 3,00 MiB
  Allocatable           yes (but full)
  PE Size               4,00 MiB
  Total PE              4994
  Free PE               0
  Allocated PE          4994
  PV UUID               ZrKbdZ-Lvjv-FZXM-onX2-YA0D-e73i-2dgmir
 
  "/dev/sdb1" is a new physical volume of "10,00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name            
  PV Size               10,00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               cWjXtz-dNbH-hd22-j4gb-S2JG-PeZ2-MPoklr
 
  "/dev/sdc1" is a new physical volume of "4,99 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc1
  VG Name            
  PV Size               4,99 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               N8HKyc-f97c-4A3a-IbpW-xWJ1-bgs2-9uMKGj
[root@node1 ~]# pvscan
  PV /dev/sda2   VG VolGroup        lvm2 [19,51 GiB / 0    free]
  PV /dev/sdb1                      lvm2 [10,00 GiB]
  PV /dev/sdc1                      lvm2 [4,99 GiB]
  Total: 3 [34,50 GiB] / in use: 1 [19,51 GiB] / in no VG: 2 [14,99 GiB]
[root@node1 ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup
  System ID          
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               19,51 GiB
  PE Size               4,00 MiB
  Total PE              4994
  Alloc PE / Size       4994 / 19,51 GiB
  Free  PE / Size       0 / 0
  VG UUID               GfqxJf-X4sV-JODl-cGOa-cz85-vLCb-ISNsKe

Step 3: Create the volume group - vgcreate, vgdisplay command.

vgcreate vol_data /dev/sdb1 /dev/sdc1
vgdisplay
The example as bellow
[root@node1 ~]# vgcreate vol_data /dev/sdb1 /dev/sdc1
  Volume group "vol_data" successfully created
[root@node1 ~]# vgdisplay
  --- Volume group ---
  VG Name               vol_data
  System ID          
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               14,98 GiB
  PE Size               4,00 MiB
  Total PE              3836
  Alloc PE / Size       0 / 0
  Free  PE / Size       3836 / 14,98 GiB
  VG UUID               koHb0q-eLoT-QKIm-dJGf-qOkU-MxHb-O27uOK
 
  --- Volume group ---
  VG Name               VolGroup
  System ID          
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               19,51 GiB
  PE Size               4,00 MiB
  Total PE              4994
  Alloc PE / Size       4994 / 19,51 GiB
  Free  PE / Size       0 / 0
  VG UUID               GFqxJf-X4sV-JODl-cGOa-cz85-vLCb-ISNsKe  

The syntax to create logical volume – lvcreate,lvdisplay command

lvcreate -L 10GB -n logical_name vol_name
lvdisplay
mkfs.ext4 /dev/vol_name/logical_name

Step 4: The maximum size of a Logical volume

lvcreate -l 100%FREE -n logical_data vol_data
lvdisplay
mkfs.ext4 /dev/vol_data/logical_data
mount /dev/vol_data/logical_data /opt
df -TH
The example as bellow
[root@node1 ~]# lvcreate -l 100%FREE -n logical_data vol_data
Logical volume "logical_data" created.
[root@node1 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vol_data/logical_data
  LV Name                logical_data
  VG Name                vol_data
  LV UUID                vlsvct-0RC9-NIrC-lPJ9-4DMy-KfhP-WwGxU4
  LV Write Access        read/write
  LV Creation host, time node1, 2016-12-03 17:17:45 +0700
  LV Status              available
  # open                 0
  LV Size                14,98 GiB
  Current LE             3836
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2
[root@node1 ~]# mkfs.ext4 /dev/vol_data/logical_data
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
983040 inodes, 3928064 blocks
196403 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4022337536
120 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208
Writing inode tables: done                          
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 23 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@node1 ~]# mount /dev/vol_data/logical_data /opt
[root@node1 ~]# df -Th
Filesystem           Type   Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                     ext4    18G  5,4G   12G  32% /
tmpfs                tmpfs  358M     0  358M   0% /dev/shm
/dev/sda1            ext4   477M   76M  376M  17% /boot
/dev/mapper/vol_data-logical_data
                     ext4    15G   38M   14G   1% /opt

For raid5 disk (if you setup disk raid5)

lvcreate --type raid5 -l 100%FREE -n logical_data vol_data

How to create LVM resize

lvextend -L +100 /dev/vol_data/logical_data
Thanks for reading! How to create LVM in centos 6.

Comments

Popular posts from this blog

How to Install Python 3.13

Best Linux Distros for AI in 2025

How to Play Minecraft Bedrock Edition on Linux: A Comprehensive Guide for Tech Professionals