Jump to content

LVM operations: Difference between revisions

From Costa's Wiki
Created page with " 1. create disk partition (fdisk) 2. pvcreate /dev/sdb1 3. lvmdiskscan , pvdisplay , pvscan(to check) 4. vgcreate vg_newlvm /dev/sdb1 vgcreate vg_newlvm /dev/sdb1 /dev/..."
 
No edit summary
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
== create LV ==
  1. create disk partition (fdisk)
  1. create disk partition (fdisk)
  2. pvcreate /dev/sdb1
  2. pvcreate /dev/sdb1
Line 9: Line 10:
  6. lvdisplay (to check)
  6. lvdisplay (to check)
  7. mkfs.ext4 /dev/vg_newlvm/centos7_newvol
  7. mkfs.ext4 /dev/vg_newlvm/centos7_newvol
==resize LV ==
1. Identify the Volume Group
    vgs
2. Extend the Volume Group
    vgextend myvolume /dev/sda2
3. Check
    vgs , vgdisplay
4. Extend the Logical Volume
    lvextend -l +100%FREE /dev/myvg/myvolume
Note: You can also extend the file system size using single lvextnd command by adding -r at end, example is shown below
    lvextend -l +100%FREE /dev/myvg/myvolume -r
5. Extend the filesystem
    xfs_growfs /dev/myvg/myvolume
==disable/delete LV ==
1. Delete the entry of the mount point from the /etc/fstab :
# cat /etc/fstab
...
/dev/mapper/datavg-testlv            /data01              ext4    defaults        0 0
...
2. Unmount the mount point :
# umount /data01
3. Disable lvm :
# lvchange -an /dev/datavg/testlv
4. Delete lvm volume :
# lvremove /dev/datavg/testlv
5. Disable volume group :
# vgchange -an datavg
6. Delete volume group :
# vgremove datavg
7. Delete physical Volumes being used for the volume group “datavg” :
# pvremove /dev/sdb  /dev/sdc
==mount LVM from external disk ==
Make sure lvm2 is installed:
$ sudo yum install lvm2
Load the necessary module(s) as root:
$ sudo modprobe dm-mod
Scan your system for LVM volumes and identify in the output the volume group name that has your Fedora volume (mine proved to be VolGroup00):
$ sudo vgscan
Activate the volume:
$ sudo vgchange -ay VolGroup00
Find the logical volume that has your Fedora root filesystem (mine proved to be LogVol00):
$ sudo lvs
Create a mount point for that volume:
$ sudo mkdir /mnt/fcroot
Mount it:
$ sudo mount /dev/VolGroup00/LogVol00 /mnt/fcroot -o ro,user
You're done, navigate to /mnt/fcroot and copy the files and paste somewhere else.
Note: In case of bad sectors on the disk, one can prevent journaling with the option noload.

Latest revision as of 15:21, 28 August 2025

create LV

[edit]
1. create disk partition (fdisk)
2. pvcreate /dev/sdb1
3. lvmdiskscan , pvdisplay , pvscan(to check)
4. vgcreate vg_newlvm /dev/sdb1
   vgcreate vg_newlvm /dev/sdb1 /dev/sdc1 
5. lvcreate --name centos7_newvol -l 100%FREE vg_newlvm
   lvcreate -L 15G vg_newlvm
   lvcreate -l 50%VG -n centos7_newvol vg_newlvm
6. lvdisplay (to check)
7. mkfs.ext4 /dev/vg_newlvm/centos7_newvol

resize LV

[edit]
1. Identify the Volume Group
   vgs
2. Extend the Volume Group
   vgextend myvolume /dev/sda2
3. Check
   vgs , vgdisplay
4. Extend the Logical Volume
   lvextend -l +100%FREE /dev/myvg/myvolume
Note: You can also extend the file system size using single lvextnd command by adding -r at end, example is shown below
   lvextend -l +100%FREE /dev/myvg/myvolume -r
5. Extend the filesystem
   xfs_growfs /dev/myvg/myvolume

disable/delete LV

[edit]
1. Delete the entry of the mount point from the /etc/fstab :
# cat /etc/fstab
...
/dev/mapper/datavg-testlv            /data01              ext4    defaults        0 0
...
2. Unmount the mount point : 
# umount /data01

3. Disable lvm :
# lvchange -an /dev/datavg/testlv

4. Delete lvm volume :
# lvremove /dev/datavg/testlv

5. Disable volume group :
# vgchange -an datavg

6. Delete volume group :
# vgremove datavg

7. Delete physical Volumes being used for the volume group “datavg” :
# pvremove /dev/sdb  /dev/sdc


mount LVM from external disk

[edit]
Make sure lvm2 is installed:

$ sudo yum install lvm2
Load the necessary module(s) as root:

$ sudo modprobe dm-mod
Scan your system for LVM volumes and identify in the output the volume group name that has your Fedora volume (mine proved to be VolGroup00):

$ sudo vgscan
Activate the volume:

$ sudo vgchange -ay VolGroup00
Find the logical volume that has your Fedora root filesystem (mine proved to be LogVol00):

$ sudo lvs
Create a mount point for that volume:

$ sudo mkdir /mnt/fcroot
Mount it:

$ sudo mount /dev/VolGroup00/LogVol00 /mnt/fcroot -o ro,user
You're done, navigate to /mnt/fcroot and copy the files and paste somewhere else.

Note: In case of bad sectors on the disk, one can prevent journaling with the option noload.