LVM: Difference between revisions

From 太極
Jump to navigation Jump to search
 
(7 intermediate revisions by the same user not shown)
Line 2: Line 2:


* [https://en.wikipedia.org/wiki/Logical_Volume_Manager_%28Linux%29 Logical Volume Manager (Linux)]
* [https://en.wikipedia.org/wiki/Logical_Volume_Manager_%28Linux%29 Logical Volume Manager (Linux)]
* [https://linuxhint.com/whatis_logical_volume_management/ Benefits of LVM]
* [https://i.pinimg.com/originals/3c/bb/33/3cbb339e0b3a8c71c80662598a63f877.png A layout illustration]
* [https://i.pinimg.com/originals/3c/bb/33/3cbb339e0b3a8c71c80662598a63f877.png A layout illustration]
* [http://www.linuxjournal.com/content/lvm-demystified LVM Demystified]
* [http://www.linuxjournal.com/content/lvm-demystified LVM Demystified]
Line 8: Line 9:
** [https://www.howtogeek.com/211937/how-to-use-lvm-on-ubuntu-for-easy-partition-resizing-and-snapshots/ How to Use LVM on Ubuntu for Easy Partition Resizing and Snapshots]
** [https://www.howtogeek.com/211937/how-to-use-lvm-on-ubuntu-for-easy-partition-resizing-and-snapshots/ How to Use LVM on Ubuntu for Easy Partition Resizing and Snapshots]
* [https://manjaro.site/how-to-extend-lvm-disk-on-ubuntu-20-04/ How to Extend LVM Disk on Ubuntu 20.04]
* [https://manjaro.site/how-to-extend-lvm-disk-on-ubuntu-20-04/ How to Extend LVM Disk on Ubuntu 20.04]
* [https://www.2daygeek.com/extend-increase-resize-lvm-logical-volume-in-linux/ How to Extend/Increase LVM’s (Logical Volume Resize) in Linux]
* [https://www.2daygeek.com/extend-increase-resize-lvm-logical-volume-in-linux/ How to Extend/Increase LVM’s (Logical Volume Resize) in Linux], [https://ostechnix.com/resize-lvm-partitions-linux/ How To Resize LVM Partitions In Linux]
* [https://www.answertopia.com/ubuntu/adding-a-new-disk-to-an-ubuntu-volume-group-and-logical-volume/ Adding a New Disk to an Ubuntu 20.04 Volume Group and Logical Volume]
* [https://www.answertopia.com/ubuntu/adding-a-new-disk-to-an-ubuntu-volume-group-and-logical-volume/ Adding a New Disk to an Ubuntu 20.04 Volume Group and Logical Volume]
* [https://www.makeuseof.com/how-to-set-up-flexible-file-system-storage-with-lvm-in-linux/ How to Set Up Flexible File System Storage With LVM in Linux]
* [https://www.makeuseof.com/how-to-set-up-flexible-file-system-storage-with-lvm-in-linux/ How to Set Up Flexible File System Storage With LVM in Linux]
Line 18: Line 19:
* [http://www.datadisk.org.uk/html_docs/redhat/rh_lvm.htm datadisk.org.uk]
* [http://www.datadisk.org.uk/html_docs/redhat/rh_lvm.htm datadisk.org.uk]
* [https://www.privex.io/articles/linux-lvm-cheatsheet/#show-physical-volumes privex.io]
* [https://www.privex.io/articles/linux-lvm-cheatsheet/#show-physical-volumes privex.io]
== Naming convention ==
* /dev/vg_<hostname>_<type><number>/lv_<filesystem>. See [https://listman.redhat.com/archives/linux-lvm/2011-April/msg00061.html this]
* /dev/vg_`hostname -s`_[0-9][0-9]/lv_{foo|bar}. See [https://linux-lvm.redhat.narkive.com/r5sJR3R6/lvm-naming-convention this].


= Creation =
= Creation =
Line 24: Line 29:
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
# Step 1 Find your drive names
# Step 1 Find your drive names
# lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL
lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL
 
NAME        FSTYPE        SIZE MOUNTPOINT  LABEL
NAME        FSTYPE        SIZE MOUNTPOINT  LABEL
sda                      223.6G               
sda                      223.6G               
Line 117: Line 123:
</syntaxhighlight>
</syntaxhighlight>
</li>
</li>
<li>[https://manjaro.site/add-new-disk-existing-volume-group/ How to add new disk to existing Volume Group]
</ul>
== Add new disk ==
<ul>
<li>[https://manjaro.site/add-new-disk-existing-volume-group/ How to add new disk to existing Volume Group] '''vgextend'''
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
# Step 1 Create Physical Volume
# Step 1 Create Physical Volume
Line 126: Line 135:
vgextend manjaro_lvm /dev/vdc
vgextend manjaro_lvm /dev/vdc
vgdisplay
vgdisplay
</syntaxhighlight>
</li>
<li>[https://www.suse.com/support/kb/doc/?id=000018068 Adding a New Disk Into an Existing Logical Volume]. '''lvextend'''
<syntaxhighlight lang='bash'>
umount /dev/serverdata/data
fdisk -l
pvcreate /dev/sdb
vgextend serverdata /dev/sdb
vgdisplay serverdata
lvextend -l +100%FREE /dev/serverdata/data
# OR something like
# lvextend -L+25G /dev/serverdata/data
lvdisplay serverdata
e2fsck -f /dev/serverdata/data # optional
resize2fs /dev/serverdata/data
e2fsck -f /dev/serverdata/data # optional
</syntaxhighlight>
</syntaxhighlight>
</li>
</li>
Line 156: Line 183:
<li>[https://www.looklinux.com/how-to-remove-volume-group-and-physical-volume-on-lvm/ How to Remove Volume Group and Physical Volume on LVM] </li>
<li>[https://www.looklinux.com/how-to-remove-volume-group-and-physical-volume-on-lvm/ How to Remove Volume Group and Physical Volume on LVM] </li>
<li>[https://faun.pub/linux-quick-tip-how-to-delete-or-remove-lvm-volumes-7df4447102af Linux Quick Tip: How to Delete or Remove LVM volumes] </li>
<li>[https://faun.pub/linux-quick-tip-how-to-delete-or-remove-lvm-volumes-7df4447102af Linux Quick Tip: How to Delete or Remove LVM volumes] </li>
<li>[https://linuxconfig.org/using-lvm-to-manage-physical-volumes-volume-groups-and-logical-volumes-rhcsa-objective-preparation Using LVM to manage physical volumes, volume groups, and logical volumes] </li>
<li>[https://linuxconfig.org/using-lvm-to-manage-physical-volumes-volume-groups-and-logical-volumes-rhcsa-objective-preparation Using LVM to manage physical volumes, volume groups, and logical volumes] – RHCSA Objective Preparation </li>
</ul>
</ul>
= Move =
[https://ostechnix.com/move-lvm-volume-group-to-another-machine/ How To Move LVM Volume Group To Another Machine In Linux]


= Snapshot =
= Snapshot =
Line 166: Line 196:
* [https://tuxfixer.com/backup-and-restore-logical-volume-using-lvm-snapshot/ Backup and Restore Logical Volume using LVM Snapshot]
* [https://tuxfixer.com/backup-and-restore-logical-volume-using-lvm-snapshot/ Backup and Restore Logical Volume using LVM Snapshot]
* [https://linuxconfig.org/create-and-restore-manual-logical-volume-snapshots LVM backup and restore snapshot in Linux]
* [https://linuxconfig.org/create-and-restore-manual-logical-volume-snapshots LVM backup and restore snapshot in Linux]
* [https://www.bleepingcomputer.com/news/linux/kali-linux-adds-vm-like-snapshot-feature-to-bare-metal-installs/ Kali Linux adds VM-like snapshot feature to bare-metal installs]


= Raspberry Pi =
= Raspberry Pi =
* [https://raspberrypi.stackexchange.com/questions/85958/easy-backups-and-snapshots-of-a-running-system-with-lvm Easy backups and snapshots of a running system with LVM]
* [https://raspberrypi.stackexchange.com/questions/85958/easy-backups-and-snapshots-of-a-running-system-with-lvm Easy backups and snapshots of a running system with LVM]

Latest revision as of 15:10, 24 February 2023

Resource

Cheatsheet

Naming convention

  • /dev/vg_<hostname>_<type><number>/lv_<filesystem>. See this
  • /dev/vg_`hostname -s`_[0-9][0-9]/lv_{foo|bar}. See this.

Creation

  • Setup LVM and pool hard drives in Ubuntu or Kodibuntu
    # Step 1 Find your drive names
    lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL
    
    NAME         FSTYPE        SIZE MOUNTPOINT   LABEL
    sda                      223.6G              
    ├─sda1                    1007K              
    ├─sda2       vfat          512M /boot/efi    
    └─sda3       LVM2_member 223.1G              
      ├─pve-swap swap            8G [SWAP]       
      └─pve-root ext4        215.1G /            
    nvme0n1                  465.8G              
    └─nvme0n1p1  ext4        465.8G /mnt/pve/vm1 
    
    # Step 2 Format your drives
    fdisk /dev/sdX
    
    # Step 3 Create physical volume
    pvcreate /dev/sd[bcd]
    pvdisplay
    
    # Step 4 Adding the VG (Volume Group) to the LVM
    vgcreate {VG_NAME} /dev/sd[bcd]
    vgdisplay
    
    # Step 5 Adding the LV (Logical Volume) to the LVM VG (Volume Group)
    lvcreate -l 100%FREE -n {LV_NAME} {VG_NAME}
    lvdisplay
    
    # Step 6 FORMATTING OUR NEW LVM LV (LOGICAL VOLUME)
    mkfs.ext4 {LV_PATH}
    
    # Step 7 MOUNT LVM LV (LOGICAL VOLUME) ON BOOT
    blkid
    # Grab the UUID of your storage space, 
    # it will be after the /dev/mapper/{VG_NAME}-{LV_NAME}
    nano /etc/fstab
    mount -a
    
    # Step 8 ENABLE SMART DRIVE MONITORING
    nano /etc/defaults/smartmontools
    nano /etc/smartd.conf
  • LVM Layout & Arch Linux Tutorial – Configure LVM on Arch Linux 2017
    # Step 0 See available physical disks
    fdisk
    
    # Step 1 Create new Physical Volume
    pvcreate /dev/vdb
    pvcreate /dev/vdc
    pvdisplay 
    
    # Step 2 Create new Volume Group (VG)
    vgcreate archVG /dev/vdb /dev/vdc
    vgdisplay
    
    # Step 3 Logical Volume
    lvcreate -L 5G archVG -n archLV01
    lvcreate -L 15G archVG -n archLV02
    lvdisplay
    lsblk 
    
    # Step 4 Format the new volume
    mkfs.ext4 /dev/mapper/archVG-archLV01
    
    # Step 5 Mount
    mount /dev/mapper/archVG-archLV01 /mnt
  • How to Extend LVM Disk on Ubuntu 20.04
    # Step 1. Check the file system list
    sudo df -h /home/
    
    # Step 2. Check the Physical Volume (pv)
    sudo pvs
    sudo vgdisplay
    sudo lvdisplay
    
    # Step 3. Create a New Physical Volume
    sudo fdisk -l
    sudo lvmdiskscan
    sudo pvcreate /dev/sdb
    sudo lvmdiskscan -l
    
    # Step 4. Add the new Physical Volume (pv) to Existing Logical Volume (lv)
    sudo vgextend ubuntu-vg /dev/sdb
    sudo lvm lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
    
    sudo resize2fs -p /dev/mapper/ubuntu--vg-ubuntu--lv
    sudo df -h

Add new disk

  • How to add new disk to existing Volume Group vgextend
    # Step 1 Create Physical Volume
    pvcreate /dev/vdc
    
    # Step 2 Add Physical Volume to Existing Volume Group
    vgdisplay
    vgextend manjaro_lvm /dev/vdc
    vgdisplay
  • Adding a New Disk Into an Existing Logical Volume. lvextend
    umount /dev/serverdata/data
    fdisk -l
    pvcreate /dev/sdb
    vgextend serverdata /dev/sdb
    vgdisplay serverdata 
    
    lvextend -l +100%FREE /dev/serverdata/data
    # OR something like 
    # lvextend -L+25G /dev/serverdata/data
    lvdisplay serverdata
    
    e2fsck -f /dev/serverdata/data # optional
    resize2fs /dev/serverdata/data
    e2fsck -f /dev/serverdata/data # optional

Delete

Move

How To Move LVM Volume Group To Another Machine In Linux

Snapshot

Raspberry Pi