Difference between revisions of "LVM"

From The Linux Source
Jump to: navigation, search
(Created page with "(all of these apply to both VM and physical systems) === Resizing existing mountpoints (adding more space) === 1. if this is Enterprise 3 or older, umount partition (not nee...")
 
m
Line 80: Line 80:
 
  # free | grep Swap
 
  # free | grep Swap
 
  Swap:      4192924          0    4192924
 
  Swap:      4192924          0    4192924
 
  
 
===  Adding partitions (existing space available) ===
 
===  Adding partitions (existing space available) ===
Line 122: Line 121:
 
1. create a single partition as type LVM (8e) for the whole drive
 
1. create a single partition as type LVM (8e) for the whole drive
 
  # fdisk /dev/sdb
 
  # fdisk /dev/sdb
Note: if your new drive was added to a 'live' system, and it is not showing under 'fdisk -l', you can rescan with:
+
Note: if your new drive was added to a 'live' system, and it is not showing under 'fdisk -l', you can rescan with (may need to do this with more than host0, i.e. host0, host1, etc.):
 
  echo "- - -" > /sys/class/scsi_host/host0/scan
 
  echo "- - -" > /sys/class/scsi_host/host0/scan
But may also need to rescan all SCSI host devices
 
echo "- - -" > /sys/class/scsi_host/host1/scan
 
echo "- - -" > /sys/class/scsi_host/host2/scan
 
  
 
2. initialize new drive as LVM
 
2. initialize new drive as LVM

Revision as of 12:12, 9 May 2017

(all of these apply to both VM and physical systems)

Resizing existing mountpoints (adding more space)

1. if this is Enterprise 3 or older, umount partition (not needed under Ent 4 and newer)

# umount /arsystem

2. check free space available

# vgdisplay pri | grep "Free  PE"
Free  PE / Size       1413 / 44.16 GB

3. add desired space to partition

Ent 7
# lvextend -l +1413 -r /dev/pri/arsystem
OR
# lvextend -l +1413 /dev/pri/arsystem
# xfs_growfs /dev/pri/arsystem

Ent 5/6
# lvextend -l +1413 -r /dev/pri/arsystem
OR
# lvextend -l +1413 /dev/pri/arsystem
# resize2fs /dev/pri/arsystem

Ent 4 only (e2fsadm not avail on Ent 4);
# lvextend -l +1413 /dev/pri/arsystem
# ext2online /dev/pri/arsystem

Ent 3 only;
# e2fsadm -l +1413 /dev/pri/arsystem

Note: if you run this command and the fsck gives errors, fix the errors by running fsck manually, and then run the command again (it will not do it's resizing until fsck runs cleanly)

4. if this is Ent 3 or older, mount partition (not needed under Ent 4 and newer)

# mount /arsystem

Resizing existing mountpoints (reducing space)

1. if this is Ent 3 or older, umount partition (not needed under Ent 4 and newer)

# umount /arsystem

2. check free space available

# df -h | grep arsystem
/dev/mapper/pri-arsystem     199G   13M   198G  1% /arsystem

3. set desired space of partition

Ent 7
NOTE: if reducing xfs, backup your data, you have to recreate the filesystem, all will be lost!
# lvreduce -L 10G /dev/pri/arsystem
# mkfs -t xfs /dev/pri/arsystem

Ent 5/6
# lvreduce -L 10G /dev/pri/arsystem
# resize2fs /dev/pri/arsystem

Ent 4 only (e2fsadm not avail on Ent 4);
# lvreduce -L 10G /dev/pri/arsystem
# ext2online /dev/pri/arsystem

Ent 3 only;
# e2fsadm -L 10G /dev/pri/arsystem

Note: if you run this command and the fsck gives errors, fix the errors by running fsck manually, and then run the command again (it will not do it's resizing until fsck runs cleanly)

4. if this is Ent 3 or older, mount partition (not needed under Ent 4 and newer)

# mount /arsystem

Resizing SWAP

1. unmount swap (the one you want to resize - 'usually' there is only one)

# swapoff /dev/pri/swap

2. check free space, then add desired space to partition

# vgdisplay pri | grep "Free  PE"
Free  PE / Size       1413 / 44.16 GB
# lvextend -L +4g /dev/pri/swap

3. rebuild swap filesystem (there is no swap resize command)

# mkswap /dev/pri/swap

4. re-enable swap

# swapon /dev/pri/swap

5. verify using 'free' command that new size is in use

# free | grep Swap
Swap:      4192924          0    4192924

Adding partitions (existing space available)

1. create new logical volume;

# lvcreate -L 8G -n arsystem pri
OR;
to use all of the remaining space, check "Free PE" from vgdisplay, then use -l option instead of -L, example;
# vgdisplay pri | grep "Free  PE"
Free  PE / Size       1413 / 44.16 GB
# lvcreate -l 1413 -n arsystem pri

2. create filesystem;

Ent 7
# mkfs -t xfs /dev/pri/arsystem
Ent 6
# mkfs -t ext4 /dev/pri/arsystem
Ent 5 or earlier
# mkfs -t ext3 /dev/pri/arsystem

3. make mountpoint;

# mkdir /arsystem

4. add to fstab;

# vi /etc/fstab

5. test fstab entry by mounting w/fstab info;

# mount /arsystem

Removing partitions (for re-allocating/freeing up space)

1. umount partition

# umount /u001

2. remove LVM volume

# lvremove /dev/pri/u001

3. remove from fstab

# vi /etc/fstab

Adding new drives (existing space NOT available)

(this step assumes you added a new drive, whether physical for a physical sys, or virtual for a virtual sys) 1. create a single partition as type LVM (8e) for the whole drive

# fdisk /dev/sdb

Note: if your new drive was added to a 'live' system, and it is not showing under 'fdisk -l', you can rescan with (may need to do this with more than host0, i.e. host0, host1, etc.):

echo "- - -" > /sys/class/scsi_host/host0/scan

2. initialize new drive as LVM

# pvcreate /dev/sdb1

3. add new drive to existing LVM volume

# vgextend pri /dev/sdb1
OR
# vgcreate sec /dev/sdb1

Renaming Volume Group & Logical Volume names

  • Rename Logical Volume (partition name)*
# lvrename /dev/pri/HomeVol home

(make sure to update fstab with the change)

  • Rename Volume Group*
# vgrename VolGroup00 pri

(make sure to update fstab with the change)