creating the file system in virtual machine

first add the disk in virtual machine then the disk will appear by using below command.

here added the sdc disk in virtual machine.

List the block devices

-------------------

[root@testmachine ~]# lsblk

-----------------------

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda      8:0    0  100G  0 disk 

|-sda1   8:1    0  300M  0 part /boot

|-sda2   8:2    0    2G  0 part [SWAP]

`-sda3   8:3    0 97.7G  0 part /

sdb      8:16   0   26G  0 disk 

`-sdb1   8:17   0   26G  0 part [SWAP]

sdc      8:32   0   20G  0 disk 

sr0     11:0    1 1024M  0 rom  

[root@testmachine ~]# pvcreate /dev/sdc

--------------------------------

  Physical volume "/dev/sdc" successfully created.

[root@testmachine ~]# vgs

[root@testmachine ~]# vgcreate volumegroup1 /dev/sdc

  Volume group "volumegroup1" successfully created

Physical volume is created.

---------------------------

Now add this disc to volume group.

---

[root@testmachine ~]# vgs

--------------------------

  VG           #PV #LV #SN Attr   VSize   VFree  

  volumegroup1   1   0   0 wz--n- <20.00g <20.00g

see the list of physical volumes

-----------------

[root@testmachine ~]# pvs

-------------------------

  PV         VG           Fmt  Attr PSize   PFree  

  /dev/sdc   volumegroup1 lvm2 a--  <20.00g <20.00g

-------------------------

create the logical volumes by giving required the size and logical volume name and volume group name like below

---------------------------

[root@testmachine ~]# lvcreate -L 2G -n logicalvolume_1 volumegroup1 

--------------------------------



  Logical volume "logicalvolume_1" created

if the disk already there with the same lv name it will give the message -already exists

------------

[root@testmachine ~]# lvcreate -L +2G -n logicalvolume_1 volumegroup1 

  Logical Volume "logicalvolume_1" already exists in volume group "volumegroup1"

for instance create another logical volume  2 below.

-------------------------

Logical volume 2  is created


--------------------

[root@testmachine ~]# lvcreate -L +2G -n logicalvolume_2 volumegroup1 

---------------------

  Logical volume "logicalvolume_2" created.


display the logical volumes created

------------------


[root@testmachine ~]# lvs

  LV              VG           Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert

  logicalvolume_1 volumegroup1 -wi-a----- 2.00g                                                    

  logicalvolume_2 volumegroup1 -wi-a----- 2.00g                                                    


create the file system now for the newly added logical volumes.

-------------

[root@testmachine ~]# mkfs.xfs /dev/volumegroup1/logicalvolume_1

meta-data=/dev/volumegroup1/logicalvolume_1 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@testmachine ~]# lvs

  LV              VG           Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert

  logicalvolume_1 volumegroup1 -wi-a----- 2.00g                                                    

  logicalvolume_2 volumegroup1 -wi-a----- 2.00g                                                    


[root@testmachine ~]# mkfs.xfs /dev/mapper/volumegroup1-logicalvolume_2

meta-data=/dev/mapper/volumegroup1-logicalvolume_2 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@testmachine ~]# vi /etc/fstab 

then add the entry like below



/dev/mapper/volumegroup1-logicalvolume_2  /test                   xfs     defaults        0 0

/dev/mapper/volumegroup1-logicalvolume_1  /test2                  xfs     defaults        0 0


-------------------------

if we try to add the existing lvm again creating the file system it will ask to override as a caution.

--------------------------


[root@testmachine ~]# mkfs.xfs /dev/mapper/volumegroup1-logicalvolume_2

mkfs.xfs: /dev/mapper/volumegroup1-logicalvolume_2 appears to contain an existing filesystem (xfs).

mkfs.xfs: Use the -f option to force overwrite.

-------------------------

[root@testmachine ~]# lvs

  LV              VG           Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert

  logicalvolume_1 volumegroup1 -wi-a----- 2.00g                                                    

  logicalvolume_2 volumegroup1 -wi-a----- 2.00g 

-----------------------                                                   

[root@testmachine ~]# pvs

  PV         VG           Fmt  Attr PSize   PFree  

  /dev/sdc   volumegroup1 lvm2 a--  <20.00g <16.00g

[root@testmachine ~]# vgs

  VG           #PV #LV #SN Attr   VSize   VFree  

  volumegroup1   1   2   0 wz--n- <20.00g <16.00g


mount the file system

-------------------------


[root@testmachine ~]# mount /test

-----------------------


see the mount details 

------------------------

[root@testmachine ~]# df -Th /test

-------------------------

Filesystem                               Type  Size  Used Avail Use% Mounted on

/dev/mapper/volumegroup1-logicalvolume_2 xfs   2.0G   33M  2.0G   2% /test


[root@testmachine ~]# pvs

  PV         VG           Fmt  Attr PSize   PFree  

  /dev/sdc   volumegroup1 lvm2 a--  <20.00g <16.00g


[root@testmachine ~]# lvs

  LV              VG           Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert

  logicalvolume_1 volumegroup1 -wi-a----- 2.00g                                                    

  logicalvolume_2 volumegroup1 -wi-ao---- 2.00g

--------------------------------                                                    

[root@testmachine ~]# pvs

  PV         VG           Fmt  Attr PSize   PFree  

  /dev/sdc   volumegroup1 lvm2 a--  <20.00g <16.00g

[root@testmachine ~]# lsblk

NAME                           MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda                              8:0    0  100G  0 disk 

|-sda1                           8:1    0  300M  0 part /boot

|-sda2                           8:2    0    2G  0 part [SWAP]

`-sda3                           8:3    0 97.7G  0 part /

sdb                              8:16   0   26G  0 disk 

`-sdb1                           8:17   0   26G  0 part [SWAP]

sdc                              8:32   0   20G  0 disk 

|-volumegroup1-logicalvolume_1 253:0    0    2G  0 lvm  

`-volumegroup1-logicalvolume_2 253:1    0    2G  0 lvm  /test

sr0                             11:0    1 1024M  0 rom  


[root@testmachine test]# df -Th /test/

Filesystem                               Type  Size  Used Avail Use% Mounted on

/dev/mapper/volumegroup1-logicalvolume_2 xfs   2.0G   33M  2.0G   2% /test

[root@testmachine test]# vi /etc/fstab 

[root@testmachine test]# mkdir /test2

[root@testmachine test]# mount /test2

[root@testmachine test]# df -Th /test2

Filesystem                               Type  Size  Used Avail Use% Mounted on

/dev/mapper/volumegroup1-logicalvolume_1 xfs   2.0G   33M  2.0G   2% /test2

[root@testmachine test]# df -Th 

Filesystem                               Type      Size  Used Avail Use% Mounted on

/dev/sda3                                xfs        98G  4.8G   93G   5% /

devtmpfs                                 devtmpfs  895M     0  895M   0% /dev

tmpfs                                    tmpfs     910M     0  910M   0% /dev/shm

tmpfs                                    tmpfs     910M   11M  900M   2% /run

tmpfs                                    tmpfs     910M     0  910M   0% /sys/fs/cgroup

/dev/sda1                                xfs       297M  157M  140M  53% /boot

tmpfs                                    tmpfs     182M   12K  182M   1% /run/user/42

tmpfs                                    tmpfs     182M     0  182M   0% /run/user/0

/dev/mapper/volumegroup1-logicalvolume_2 xfs       2.0G   33M  2.0G   2% /test

/dev/mapper/volumegroup1-logicalvolume_1 xfs       2.0G   33M  2.0G   2% /test2


--------------------------


extend the file system

--------------------

[root@testmachine test]# lvextend -L +2G /dev/mapper/volumegroup1-logicalvolume_2

  Size of logical volume volumegroup1/logicalvolume_2 changed from 2.00 GiB (512 extents) to 4.00 GiB (1024 extents).

  Logical volume volumegroup1/logicalvolume_2 successfully resized.


---------------------

resize or reduce the size 

----------------------

[root@testmachine test]# lvreduce -L 2G /dev/mapper/volumegroup1-logicalvolume_2

  WARNING: Reducing active and open logical volume to 2.00 GiB.

  THIS MAY DESTROY YOUR DATA (filesystem etc.)

Do you really want to reduce volumegroup1/logicalvolume_2? [y/n]: y

  Size of logical volume volumegroup1/logicalvolume_2 changed from 4.00 GiB (1024 extents) to 2.00 GiB (512 extents).

  Logical volume volumegroup1/logicalvolume_2 successfully resized.



------------------------

[root@testmachine test]# lvs

  LV              VG           Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert

  logicalvolume_1 volumegroup1 -wi-ao---- 2.00g                                                    

  logicalvolume_2 volumegroup1 -wi-ao---- 2.00g  


reduced to 2GB .

----------------------------------                                                  

[root@testmachine test]# lvextend -L +2G /dev/mapper/volumegroup1-logicalvolume_2

  Size of logical volume volumegroup1/logicalvolume_2 changed from 2.00 GiB (512 extents) to 4.00 GiB (1024 extents).

  Logical volume volumegroup1/logicalvolume_2 successfully resized.


---------------------

[root@testmachine test]# lvs

  LV              VG           Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert

  logicalvolume_1 volumegroup1 -wi-ao---- 2.00g                                                    

  logicalvolume_2 volumegroup1 -wi-ao---- 4.00g                                                    

[root@testmachine test]# lvextend -L +2G /dev/mapper/volumegroup1-logicalvolume_2 -r

  Size of logical volume volumegroup1/logicalvolume_2 changed from 4.00 GiB (1024 extents) to 6.00 GiB (1536 extents).

  Logical volume volumegroup1/logicalvolume_2 successfully resized.

meta-data=/dev/mapper/volumegroup1-logicalvolume_2 isize=512    agcount=4, agsize=131072 blks

         =                       sectsz=512   attr=2, projid32bit=1

         =                       crc=1        finobt=0 spinodes=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               bsize=4096   blocks=2560, version=2

         =                       sectsz=512   sunit=0 blks, lazy-count=1

realtime =none                   extsz=4096   blocks=0, rtextents=0

data blocks changed from 524288 to 1572864



[root@testmachine test]# lvs

  LV              VG           Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert

  logicalvolume_1 volumegroup1 -wi-ao---- 2.00g                                                    

  logicalvolume_2 volumegroup1 -wi-ao---- 6.00g  

------------------------------------

                                                  

[root@testmachine test]# lvreduce -L 2G /dev/mapper/volumegroup1-logicalvolume_2

  WARNING: Reducing active and open logical volume to 2.00 GiB.

  THIS MAY DESTROY YOUR DATA (filesystem etc.)

Do you really want to reduce volumegroup1/logicalvolume_2? [y/n]: y

  Size of logical volume volumegroup1/logicalvolume_2 changed from 6.00 GiB (1536 extents) to 2.00 GiB (512 extents).

  Logical volume volumegroup1/logicalvolume_2 


successfully resized.

---------------------

[root@testmachine test]# lvs

  LV              VG           Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert

  logicalvolume_1 volumegroup1 -wi-ao---- 2.00g                                                    

  logicalvolume_2 volumegroup1 -wi-ao---- 2.00g   

-------------------------------                                                 

[root@testmachine test]# lvextend -L 3G /dev/mapper/volumegroup1-logicalvolume_2 -r

  Size of logical volume volumegroup1/logicalvolume_2 changed from 2.00 GiB (512 extents) to 3.00 GiB (768 extents).

  Logical volume volumegroup1/logicalvolume_2 successfully resized.

fsadm: Xfs filesystem shrinking is unsupported.

  /usr/sbin/fsadm failed: 1


---------------------------------

[root@testmachine test]# lvextend -L +3G /dev/mapper/volumegroup1-logicalvolume_2 -r

  Size of logical volume volumegroup1/logicalvolume_2 changed from 3.00 GiB (768 extents) to 6.00 GiB (1536 extents).

  Logical volume volumegroup1/logicalvolume_2 successfully resized.



History commands for this.



  pvs

  lvs

  lsblk

 


  df -Th /test/

  vi /etc/fstab 

  mount /test2

  mkdir /test2

  mount /test2

  df -Th /test2

  df -Th 


  lvextend -L +2G /dev/mapper/volumegroup1-logicalvolume_2 -r

   lvs

  lvreduce -L 2G /dev/mapper/volumegroup1-logicalvolume_2

  lvs

 


Popular posts from this blog

script and validation for the lvm

Important concepts and bits

shell script to create and extending the volume