Showing posts with label Creating File System in Linux using LVM. Show all posts
Showing posts with label Creating File System in Linux using LVM. Show all posts

Thursday, June 11, 2020

Creating File System in Linux using LVM

File System using LVM in Linux

If you want to create a file system in linux using Logical volume manager.
Then this post will help you.

First of all, create a .vhd (virtual hard disk) using your storage system, size as you required like 5 GB.
Then follow below steps to create a file system :-


1.Then login your server and find newly created disk by using below command :-

[root@rhelnode1 /]# fdisk -l

If you can not find recently created 5GB disk. Then follow below easy steps to scan your storage path like HBA or SCSI :-

A. Find you scsi hosts


[root@rhelnode1 /]# ls /sys/class/scsi_host
host0  host1  host2

B.Scan each host ports :-

[root@rhelnode1 /]# echo "- - -"> /sys/class/scsi_host/host0/scan
[root@rhelnode1 /]# echo "- - -"> /sys/class/scsi_host/host1/scan
[root@rhelnode1 /]# echo "- - -"> /sys/class/scsi_host/host2/scan

C.now run you can run again fdisk command :-

[root@rhelnode1 /]# fdisk -l 2> /dev/null | egrep '^Disk'| grep -v mapper| grep -v identifier
Disk /dev/sda: 48.3 GB, 48318382080 bytes, 94371840 sectors
Disk label type: dos
Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 sectors
Disk /dev/sdc: 5368 MB, 5368709120 bytes, 10485760 sectors

D. To see block device mapping:-

[root@rhelnode1 /]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0               2:0    1    4K  0 disk
sda               8:0    0  127G  0 disk
├─sda1            8:1    0  700M  0 part /boot
├─sda2            8:2    0  4.9G  0 part
│ └─vg01-swap   253:1    0  4.9G  0 lvm  [SWAP]
└─sda3            8:3    0 49.3G  0 part
  ├─rhel-root   253:0    0 13.7G  0 lvm  /
  ├─rhel-home   253:2    0 11.7G  0 lvm  /home
  ├─rhel-var    253:3    0   12G  0 lvm  /var
  └─rhel-backup 253:4    0 11.8G  0 lvm  /backup
sr0              11:0    1 1024M  0 rom
[root@amiteshjsk /]#


2.Now create a physical volume 

[root@rhelnode1 /]# pvcreate /dev/sdc
  Physical volume "/dev/sdc" successfully created.

3.Now create volume group and display you vg details

[root@rhelnode1 /]# vgcreate vg02 /dev/sdc
  Volume group "vg02" successfully created
[root@rhelnode1 /]# vgdisplay vg02
  --- Volume group ---
  VG Name               vg02
  System ID             
  Format                lvm2
  Metadata Areas        1
  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                1
  Act PV                1
  VG Size               5.00 GiB
  PE Size               4.00 MiB
  Total PE              1279
  Alloc PE / Size       0 / 0   
  Free  PE / Size       1279 / 5.00 GiB
  VG UUID               vovDvR-WQUV-M0sE-OAZG-emAd-Vw77-Nzdkdv
   
[root@rhelnode1 /]# 

4. Now you can create desired size(Max 5GB) logical volumes.
So here I want create two logical volumes (2GB +2.5GB)

[root@rhelnode1 /]# lvcreate -L 2G -n sync vg02
  Logical volume "sync" created.
[root@rhelnode1 /]# lvcreate -L 2.5G -n backup vg02
  Logical volume "backup" created.
[root@rhelnode1 /]# 

5. Now format disk using xfs filesystem

[root@rhelnode1 /]# mkfs.xfs /dev/vg02/sync
meta-data=/dev/vg02/sync         isize=512    agcount=4, agsize=131072 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=524288, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@rhelnode1 /]# mkfs.xfs /dev/vg02/backup
meta-data=/dev/vg02/backup       isize=512    agcount=4, agsize=163840 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=655360, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@rhelnode1 /]# 

6. Now you can mount your logical volumes after creating directories 

[root@rhelnode1 /]# mkdir backup sync

[root@rhelnode1 /]# mount /dev/vg02/sync /sync
[root@rhelnode1 /]# mount /dev/vg02/backup /backup
[root@rhelnode1 /]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/sda2                 21G  3.2G   18G  16% /
devtmpfs                 1.2G     0  1.2G   0% /dev
tmpfs                    1.3G  144K  1.3G   1% /dev/shm
tmpfs                    1.3G  9.0M  1.2G   1% /run
tmpfs                    1.3G     0  1.3G   0% /sys/fs/cgroup
/dev/mapper/rhel-var     7.9G  1.3G  6.6G  16% /var
tmpfs                    247M  8.0K  247M   1% /run/user/0
/dev/mapper/vg01-data    2.0G   33M  2.0G   2% /data
/dev/mapper/vg02-sync    2.0G   33M  2.0G   2% /sync
/dev/mapper/vg02-backup  2.5G   33M  2.5G   2% /backup
[root@rhelnode1 /]# 

7. Now make entries in /etc/fstab file for auto mount after reboot-

[root@rhelnode1 /]# vi /etc/fstab

/dev/mapper/vg01-data     /data     xfs   defaults      0 2
/dev/mapper/vg02-sync     /sync     xfs   defaults      0 2
/dev/mapper/vg02-backup   /backup   xfs   defaults      0 2

Note:-
/etc/fstab contains 6 parameters per row. Each row represents one file system details. They are as below:

1.    Volume                 /dev/mapper/vg02-data
2.    Mount point          /data
3.    File system type   xfs
4.    Options                defaults
5.    Dump                  1,0 (for backup dump in failure) 
6.    Pass                     0,1,2 (for fsck sequence top or bottom)

Introduction to Linux Part 1

Introduction to Linux Part 1

Introduction to Linux Linux is an operating system that works just like Windows and Mac OS X. As an operating system, Linux is a very h...