technical skills grow

Responsive Ads Here

Sunday, July 18, 2021

Create LVM | Phycial Volume | Volume Group | Logical Volume | Format Logical Volume |Mount the Logical Volume (LVM)

 

How to create LVM

Step1 :[root@dev ~]# fdisk /dev/sdb                                    ( Create partition)
Welcome to fdisk (util-linux 2.23.2).Changes will remain in memory only, until you decide to write them. Be careful before using the write command. 

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (4196352-16777215, default 4196352):
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-16777215, default 16777215): +2G
Partition 2 of type Linux and of size 2 GiB is set

Command (m for help): p

Disk /dev/sdb: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x13fe498e

 Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux
/dev/sdb2         4196352     8390655     2097152   83  Linux

Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris          

Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdb: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x13fe498e

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux
/dev/sdb2         4196352     8390655     2097152   8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@dev ~]# partprobe
 

Step2 :- Phycial Volume Create 

[root@dev ~]# pvcreate /dev/sdb2
Physical volume "/dev/sdb2" successfully created.
[root@dev ~]# vgcreate /dev/sdb2 vg_web
  /dev/sdb2: already exists in filesystem
  Run `vgcreate --help' for more information.
 

Step 3: Create Volume Group

[root@dev ~]# vgcreate vg_web_group /dev/sdb2  

 Volume group "vg_web_group" successfully created
[root@dev ~]# vgs
  VG           #PV #LV #SN Attr   VSize   VFree
  centos         1   3   0 wz--n- <59.00g  4.00m
  vg_web_group   1   0   0 wz--n-  <2.00g <2.00g
Step 4 :- Logical Volume Create 

[root@dev ~]# lvcreate -L +500M -n web_lv vg_web_group
Logical volume "web_lv" created.

[root@dev ~]# lvs
  LV     VG           Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home   centos       -wi-ao----  18.08g                                                    
  root   centos       -wi-ao---- <37.04g                                                    
  swap   centos       -wi-ao----  <3.88g                                                    
  web_lv vg_web_group -wi-a----- 500.00m                                                    

Step 5: Format Logical Volume 

[root@dev ~]# mkfs.ext4 /dev/vg_web_group/web_lv
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
128016 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=34078720
63 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks:
    8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

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

Step6:- Mount the Logical Volume
[root@dev ~]# mount /dev/vg_web_group/web_lv devops/
[root@dev ~]# cd devops/

[root@dev devops]# ls
lost+found
[root@dev devops]# touch file{1..10}
[root@dev devops]# ls
file1  file10  file2  file3  file4  file5  file6  file7  file8  file9  lost+found  

Final Step 7 : Check Mount point 

[root@dev devops]# lsblk
NAME                    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                       8:0    0   60G  0 disk
├─sda1                    8:1    0    1G  0 part /boot
└─sda2                    8:2    0   59G  0 part
  ├─centos-root         253:0    0   37G  0 lvm  /
  ├─centos-swap         253:1    0  3.9G  0 lvm  [SWAP]
  └─centos-home         253:2    0 18.1G  0 lvm  /home
sdb                       8:16   0    8G  0 disk
├─sdb1                    8:17   0    2G  0 part /root/linux
└─sdb2                    8:18   0    2G  0 part
  └─vg_web_group-web_lv 253:3    0  500M  0 lvm  /root/devops
sr0                      11:0    1 1024M  0 rom



No comments:

Post a Comment

Powered by Blogger.

Labels

Contact Form

Name

Email *

Message *

Search This Blog

Blog Archive

Ad Code

Responsive Advertisement

Recent Posts