LVM: Difference between revisions

From Edgar BV Wiki
Jump to navigation Jump to search
New page: LVM management: vgscan # scans the devices and adds them to lvmtab.d directory <Before fdisking the disk!> pvcreate /dev/hde /dev/hdf /dev/hdg /dev/hdh # initialize a disk or part...
 
 
(21 intermediate revisions by 2 users not shown)
Line 1: Line 1:
LVM management:
= LVM management: =


vgscan # scans the devices and adds them to lvmtab.d directory
vgscan # scans the devices and adds them to lvmtab.d directory


<Before fdisking the disk!>
<Before fdisking the disk!>
 
<pre>
pvcreate /dev/hde
pvcreate /dev/hde
/dev/hdf
/dev/hdf
/dev/hdg
/dev/hdg
/dev/hdh # initialize a disk or partition for use by LVM
/dev/hdh # initialize a disk or partition for use by LVM
</pre>


NB if creating on /dev/md0 (raid devices) ensure that
NB if creating on /dev/md0 (raid devices) ensure that
<pre>
md_component_detection = 1  
md_component_detection = 1  
</pre>
in /etc/lvm/lvm.conf
in /etc/lvm/lvm.conf


vgcreate tripserv_vol /dev/hde /dev/hdf /dev/hdg /dev/hdh # creates the volume group tripserv_vol
== Preparing the Volume group (physical disks)  ==
<pre>
vgcreate fileserv_vol -s 64M /dev/hde /dev/hdf /dev/hdg /dev/hdh # creates the volume group fileserv_vol
</pre>


lvcreate -i3 -I4 -L100M -nvolumename tripserv_vol # create the logical volume where
== Creating the Logical Volumes ==
<pre>
lvcreate -i3 -I4 -L100M -nvolumename fileserv_vol
</pre>
creates the logical volume where


# -i = Gives the number of stripes.  This is equal to the number of physical volumes to scatter the logical volume.
* -i = Gives the number of stripes.  This is equal to the number of physical volumes to scatter the logical volume.


# -I = Gives the number of kilobytes for the granularity of the stripes.
* -I = Gives the number of kilobytes for the granularity of the stripes.
              StripeSize must be 2^n (n = 2 to 9)


# -L = size
StripeSize must be 2^n (n = 2 to 9)


# -n = name of logical volumename
* -L = size


# tripserv_vol = volumegroupname
* -n = name of logical volumename


mke2fs -j -Lfslabel /dev/tripserv_vol/volumename #formats the partition for use
* fileserv_vol = volumegroupname


# -j = journaling filesystem
or
# -L = labelname
<pre>
lvcreate -n volumename -l 100%FREE fileserv_vol
</pre>
to use all of the disk


# for snapshot volumes first unmount the drive you want to snapshot to then use  
== Format the logical volume / partition for use ==
lvcreate -L50M -s -n volumename /dev/tripserv_vol/journaleddevicename
<pre>
# mount it directly no need to mke2fs it
mke2fs -t ext4 -Lfslabel /dev/fileserv_vol/volumename
</pre>


then in /etc/fstab
== Mount in fstab ==
/etc/fstab entry looks like
<pre>
/dev/mapper/fileserv_vol-volumename /some/mountpoint        ext4    defaults        0      2
</pre>


for journaled volumes:
test mount with
<pre>
mount -a
</pre>


/dev/tripserv_vol/code          /export/home/code              ext3 defaults  0      0
= Extending and reducing for LVM2 =
<pre>
unmount the volume
e2fsck -f /dev/vg/lvname
resize2fs /dev/vg/lvname sizeM/G
lvresize /dev/vg/lvname -L sizeM/G
</pre>
just in case and to test:
<pre>
resize2fs /dev/vg/lvname
e2fsck -f /dev/vg/lvname
</pre>
then check using lvscan


for non-journaled:
== Reducing ==
<pre>
unmount /dev/fileserv_vol/volumename
e2fsck -f /dev/fileserv_vol/volumename
resize2fs /dev/fileserv_vol/volumename 150G
</pre>
will make the filesystem 150G large
<pre>
lvreduce /dev/fileserv_vol/volumename -L 150G
</pre>
will make the logical volume 150G large. If you use -15G you subtract 15G from the current disk size. The resize2fs tool doesn't support this


/dev/tripserv_vol/sfx          /export/home/sfx                ext2 defaults  0      0
== Extending ==
<pre>
unmount /dev/fileserv_vol/volumename
e2fsck -f /dev/fileserv_vol/volumename
lvextend /dev/fileserv_vol/volumename -L +100G
</pre>
-L +100G increases the size of the extent by 100G. This works because in the next step you don't have to specify the size of the new volume.
<pre>
resize2fs /dev/fileserv_vol/volumename
</pre>


for snapshots:
== Resizing a root LV ==
NB. If you want to resize an LVM root partition, start up using the Debian CD untill you get to the partitioner. Then open a second terminal and log in through that. If the lv's are not available (and e2fsck doesn't work, there's nothing in /dev/fileserv_vol/ etc), do


/dev/tripserv_vol/codesnap /export/home/codesnap ext3 ro 0 0
<pre>
vgscan
lvchange -a y /dev/fileserv_vol/volumename
</pre>
which activates it.


mount -a
[https://wiki.edgarbv.com/index.php/VMWare_ESXi#Expanding_HDs_on_a_VM Expanding HDs on a VM]


# extending, reducing and removing
= Renaming a VG (if it's got the root on there) =
start up the debian rescue and open a shell:
<pre>
vgchange -a n oldvgname
vgrename oldvgname newvgname
vgscan
lvscan
vgchange -a y newvgname
</pre>
Then you need to put the newvgname into /etc/fstab and /boot/grub/menu.lst before rebooting
NB. Use nano to edit, vi / vim / emacs are probably not available!


= Depreciated! LVM1 =
extending, reducing and removing NB This all only works for LVM1
to extend:
to extend:


(only lvm1)
(only lvm1)
unmount /dev/tripserv_vol/volumename
<pre>
e2fsadm -L+15G /dev/tripserv_vol/volumename
unmount /dev/fileserv_vol/volumename
 
e2fsadm -L+15G /dev/fileserv_vol/volumename
</pre>
will make the volumename 15G larger
will make the volumename 15G larger


OR
OR
 
<pre>
unmount /dev/tripserv_vol/volumename
unmount /dev/fileserv_vol/volumename
lvextend /dev/tripserv_vol/volumename -L+100M (to enlarge by 100MB)
lvextend /dev/fileserv_vol/volumename -L+100M (to enlarge by 100MB)
 
</pre>
check the drive and resize2fs the drive to make it larger, then fsck to check integrity
check the drive and resize2fs the drive to make it larger, then fsck to check integrity
 
<pre>
e2fsck -fv /dev/tripserv_vol/volumename
e2fsck -fv /dev/fileserv_vol/volumename
resize2fs /dev/tripserv_vol/volumename
resize2fs /dev/fileserv_vol/volumename
e2fsck -fv /dev/tripserv_vol/volumename
e2fsck -fv /dev/fileserv_vol/volumename
 
</pre>
to reduce:
to reduce:
umount /dev/tripserv_vol/volumename
<pre>
resize2fs /dev/tripserv_vol/volumename 20971520 (new size of volume in blocks)
umount /dev/fileserv_vol/volumename
lvreduce /dev/tripserv_vol/volumename -L-10G
resize2fs /dev/fileserv_vol/volumename 20971520 (new size of volume in blocks)
e2fsck -fv /dev/tripserv_vol/volumename
lvreduce /dev/fileserv_vol/volumename -L-10G
mount /dev/tripserv_vol/volumename
e2fsck -fv /dev/fileserv_vol/volumename
mount /dev/fileserv_vol/volumename
</pre>
Note: you can find the proper size in blocks by doing an lvreduce then e2fsck. It will give the block size in the error message, after which you can lvextend it back to where it was, e2fsck it and then resize2fs it with the correct paramaters.


Note: you can find the proper size in blocks by doing an lvreduce then e2fsck. It will give the block size in the error message, after which you can lvextend it back to where it was, e2fsck it and then resize2fs it with the correct paramaters.
NB if you lose the files but everything /looks/ fine, they could well be in the lost+found directory...


After these operations the computer needs rebooting!
After these operations the computer needs rebooting!


to remove:
to remove:
 
<pre>
lvremove /dev/tripserv_vol/volumename
lvremove /dev/fileserv_vol/volumename
 
</pre>
# Snapshots
== Snapshots ==


You make a new snapshot volume name based on the existing logical volume you want to back up
You make a new snapshot volume name based on the existing logical volume you want to back up
 
</pre>
lvcreate -s -L500M -n docusnap /dev/tripserv_vol/docu
lvcreate -s -L500M -n docusnap /dev/fileserv_vol/docu
 
</pre>
# If the pv size displayed < the disk size
# If the pv size displayed < the disk size
check with pvscan / pvdisplay and with lvmdiskscan. pvdisplay shows the metadata on the disk, lvmdiskscan looks at what the OS has to say.
check with pvscan / pvdisplay and with lvmdiskscan. pvdisplay shows the metadata on the disk, lvmdiskscan looks at what the OS has to say.
If size mismatch upgrade to lvm2 from testing (not Sarge, see "installing packages from testing on stable machines using apt.txt") and run
If size mismatch upgrade to lvm2 from testing (not Sarge, see "installing packages from testing on stable machines using apt.txt") and run
<pre>
pvresize /dev/md0
pvresize /dev/md0
 
</pre>
tripserv:/etc# pvscan
<pre>
fileserv:/etc# pvscan
pvscan -- reading all physical volumes (this may take a while...)
pvscan -- reading all physical volumes (this may take a while...)
pvscan -- ACTIVE  PV "/dev/hdg1" of VG "tripserv_vol" [38.16 GB / 7.93 GB free]
pvscan -- ACTIVE  PV "/dev/hdg1" of VG "fileserv_vol" [38.16 GB / 7.93 GB free]
pvscan -- ACTIVE  PV "/dev/hdh1" of VG "tripserv_vol" [38.16 GB / 8.01 GB free]
pvscan -- ACTIVE  PV "/dev/hdh1" of VG "fileserv_vol" [38.16 GB / 8.01 GB free]
pvscan -- ACTIVE  PV "/dev/hde1" of VG "tripserv_vol" [55.91 GB / 0 free]
pvscan -- ACTIVE  PV "/dev/hde1" of VG "fileserv_vol" [55.91 GB / 0 free]
pvscan -- ACTIVE  PV "/dev/hdf1" of VG "tripserv_vol" [55.91 GB / 3.37 GB free]
pvscan -- ACTIVE  PV "/dev/hdf1" of VG "fileserv_vol" [55.91 GB / 3.37 GB free]
pvscan -- total: 4 [188.16 GB] / in use: 4 [188.16 GB] / in no VG: 0 [0]
pvscan -- total: 4 [188.16 GB] / in use: 4 [188.16 GB] / in no VG: 0 [0]


tripserv:/etc# fdisk /dev/hde
fileserv:/etc# fdisk /dev/hde


The number of cylinders for this disk is set to 116336.
The number of cylinders for this disk is set to 116336.
Line 129: Line 204:


You have new mail in /var/spool/mail/root
You have new mail in /var/spool/mail/root
tripserv:/etc# fdisk /dev/hdb
fileserv:/etc# fdisk /dev/hdb


The number of cylinders for this disk is set to 116336.
The number of cylinders for this disk is set to 116336.
Line 148: Line 223:
Command (m for help): q
Command (m for help): q


tripserv:/etc#
fileserv:/etc#


tripserv:/etc# dmesg | grep hde
fileserv:/etc# dmesg | grep hde
     ide2: BM-DMA at 0xa000-0xa007, BIOS settings: hde:pio, hdf:pio
     ide2: BM-DMA at 0xa000-0xa007, BIOS settings: hde:pio, hdf:pio
hde: MAXTOR 6L060J3, ATA DISK drive
hde: MAXTOR 6L060J3, ATA DISK drive
hde: 117266688 sectors (60041 MB) w/1819KiB Cache, CHS=116336/16/63, UDMA(100)
hde: 117266688 sectors (60041 MB) w/1819KiB Cache, CHS=116336/16/63, UDMA(100)
  hde: hde1
  hde: hde1
tripserv:/etc# dmesg | grep hdb
fileserv:/etc# dmesg | grep hdb
     ide0: BM-DMA at 0xf000-0xf007, BIOS settings: hda:DMA, hdb:DMA
     ide0: BM-DMA at 0xf000-0xf007, BIOS settings: hda:DMA, hdb:DMA
hdb: MAXTOR 6L060J3, ATA DISK drive
hdb: MAXTOR 6L060J3, ATA DISK drive
Line 162: Line 237:
  hdb: hdb1
  hdb: hdb1
  hdb: hdb1
  hdb: hdb1
</pre>
=== depreciated ===
<pre>
mke2fs -j -Lfslabel /dev/fileserv_vol/volumename
</pre>
* -j = journaling filesystem
* -L = labelname
* for snapshot volumes first unmount the drive you want to snapshot to then use
<pre>
lvcreate -L50M -s -n volumename /dev/fileserv_vol/journaleddevicename </pre>
* mount it directly no need to mke2fs it
then in /etc/fstab
for journaled volumes:
<pre>
/dev/fileserv_vol/code          /export/home/code              ext3 defaults  0      0
</pre>
for non-journaled:
<pre>
/dev/fileserv_vol/sfx          /export/home/sfx                ext2 defaults  0      0
</pre>
for snapshots:
<pre>
/dev/fileserv_vol/codesnap /export/home/codesnap ext3 ro 0 0
</pre>
mount -a

Latest revision as of 15:06, 13 May 2019

LVM management:

vgscan # scans the devices and adds them to lvmtab.d directory

<Before fdisking the disk!>

pvcreate /dev/hde
	 /dev/hdf
	 /dev/hdg
	 /dev/hdh	# initialize a disk or partition for use by LVM

NB if creating on /dev/md0 (raid devices) ensure that

md_component_detection = 1 

in /etc/lvm/lvm.conf

Preparing the Volume group (physical disks)

vgcreate fileserv_vol -s 64M /dev/hde /dev/hdf /dev/hdg /dev/hdh 	# creates the volume group fileserv_vol

Creating the Logical Volumes

lvcreate -i3 -I4 -L100M -nvolumename fileserv_vol

creates the logical volume where

  • -i = Gives the number of stripes. This is equal to the number of physical volumes to scatter the logical volume.
  • -I = Gives the number of kilobytes for the granularity of the stripes.

StripeSize must be 2^n (n = 2 to 9)

  • -L = size
  • -n = name of logical volumename
  • fileserv_vol = volumegroupname

or

lvcreate -n volumename -l 100%FREE fileserv_vol

to use all of the disk

Format the logical volume / partition for use

mke2fs -t ext4 -Lfslabel /dev/fileserv_vol/volumename

Mount in fstab

/etc/fstab entry looks like

/dev/mapper/fileserv_vol-volumename /some/mountpoint         ext4    defaults        0       2

test mount with

mount -a

Extending and reducing for LVM2

unmount the volume
e2fsck -f /dev/vg/lvname
resize2fs /dev/vg/lvname sizeM/G
lvresize /dev/vg/lvname -L sizeM/G

just in case and to test:

resize2fs /dev/vg/lvname
e2fsck -f /dev/vg/lvname

then check using lvscan

Reducing

unmount /dev/fileserv_vol/volumename
e2fsck -f /dev/fileserv_vol/volumename
resize2fs /dev/fileserv_vol/volumename 150G

will make the filesystem 150G large

lvreduce /dev/fileserv_vol/volumename -L 150G

will make the logical volume 150G large. If you use -15G you subtract 15G from the current disk size. The resize2fs tool doesn't support this

Extending

unmount /dev/fileserv_vol/volumename
e2fsck -f /dev/fileserv_vol/volumename
lvextend /dev/fileserv_vol/volumename -L +100G

-L +100G increases the size of the extent by 100G. This works because in the next step you don't have to specify the size of the new volume.

resize2fs /dev/fileserv_vol/volumename

Resizing a root LV

NB. If you want to resize an LVM root partition, start up using the Debian CD untill you get to the partitioner. Then open a second terminal and log in through that. If the lv's are not available (and e2fsck doesn't work, there's nothing in /dev/fileserv_vol/ etc), do

vgscan
lvchange -a y /dev/fileserv_vol/volumename

which activates it.

Expanding HDs on a VM

Renaming a VG (if it's got the root on there)

start up the debian rescue and open a shell:

vgchange -a n oldvgname
vgrename oldvgname newvgname
vgscan
lvscan
vgchange -a y newvgname

Then you need to put the newvgname into /etc/fstab and /boot/grub/menu.lst before rebooting NB. Use nano to edit, vi / vim / emacs are probably not available!

Depreciated! LVM1

extending, reducing and removing NB This all only works for LVM1 to extend:

(only lvm1)

unmount /dev/fileserv_vol/volumename
e2fsadm -L+15G /dev/fileserv_vol/volumename

will make the volumename 15G larger

OR

unmount /dev/fileserv_vol/volumename
lvextend /dev/fileserv_vol/volumename -L+100M (to enlarge by 100MB)

check the drive and resize2fs the drive to make it larger, then fsck to check integrity

e2fsck -fv /dev/fileserv_vol/volumename
resize2fs /dev/fileserv_vol/volumename
e2fsck -fv /dev/fileserv_vol/volumename

to reduce:

umount /dev/fileserv_vol/volumename
resize2fs /dev/fileserv_vol/volumename 20971520 (new size of volume in blocks)
lvreduce /dev/fileserv_vol/volumename -L-10G
e2fsck -fv /dev/fileserv_vol/volumename
mount /dev/fileserv_vol/volumename

Note: you can find the proper size in blocks by doing an lvreduce then e2fsck. It will give the block size in the error message, after which you can lvextend it back to where it was, e2fsck it and then resize2fs it with the correct paramaters.

NB if you lose the files but everything /looks/ fine, they could well be in the lost+found directory...

After these operations the computer needs rebooting!

to remove:

lvremove /dev/fileserv_vol/volumename

Snapshots

You make a new snapshot volume name based on the existing logical volume you want to back up

lvcreate -s -L500M -n docusnap /dev/fileserv_vol/docu

  1. If the pv size displayed < the disk size

check with pvscan / pvdisplay and with lvmdiskscan. pvdisplay shows the metadata on the disk, lvmdiskscan looks at what the OS has to say.

If size mismatch upgrade to lvm2 from testing (not Sarge, see "installing packages from testing on stable machines using apt.txt") and run

pvresize /dev/md0
fileserv:/etc# pvscan
pvscan -- reading all physical volumes (this may take a while...)
pvscan -- ACTIVE   PV "/dev/hdg1" of VG "fileserv_vol" [38.16 GB / 7.93 GB free]
pvscan -- ACTIVE   PV "/dev/hdh1" of VG "fileserv_vol" [38.16 GB / 8.01 GB free]
pvscan -- ACTIVE   PV "/dev/hde1" of VG "fileserv_vol" [55.91 GB / 0 free]
pvscan -- ACTIVE   PV "/dev/hdf1" of VG "fileserv_vol" [55.91 GB / 3.37 GB free]
pvscan -- total: 4 [188.16 GB] / in use: 4 [188.16 GB] / in no VG: 0 [0]

fileserv:/etc# fdisk /dev/hde

The number of cylinders for this disk is set to 116336.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/hde: 16 heads, 63 sectors, 116336 cylinders
Units = cylinders of 1008 * 512 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/hde1             1    116336  58633312+  8e  Linux LVM

Command (m for help): q

You have new mail in /var/spool/mail/root
fileserv:/etc# fdisk /dev/hdb

The number of cylinders for this disk is set to 116336.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/hdb: 16 heads, 63 sectors, 116336 cylinders
Units = cylinders of 1008 * 512 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/hdb1             1    116336  58633312+  8e  Linux LVM

Command (m for help): q

fileserv:/etc#

fileserv:/etc# dmesg | grep hde
    ide2: BM-DMA at 0xa000-0xa007, BIOS settings: hde:pio, hdf:pio
hde: MAXTOR 6L060J3, ATA DISK drive
hde: 117266688 sectors (60041 MB) w/1819KiB Cache, CHS=116336/16/63, UDMA(100)
 hde: hde1
fileserv:/etc# dmesg | grep hdb
    ide0: BM-DMA at 0xf000-0xf007, BIOS settings: hda:DMA, hdb:DMA
hdb: MAXTOR 6L060J3, ATA DISK drive
hdb: 117266688 sectors (60041 MB) w/1819KiB Cache, CHS=116336/16/63, UDMA(33)
 hdb: unknown partition table
 hdb: hdb1
 hdb: hdb1

depreciated

mke2fs -j -Lfslabel /dev/fileserv_vol/volumename
  • -j = journaling filesystem
  • -L = labelname
  • for snapshot volumes first unmount the drive you want to snapshot to then use
lvcreate -L50M -s -n volumename /dev/fileserv_vol/journaleddevicename 
  • mount it directly no need to mke2fs it

then in /etc/fstab

for journaled volumes:

/dev/fileserv_vol/code          /export/home/code               ext3 defaults   0       0

for non-journaled:

/dev/fileserv_vol/sfx           /export/home/sfx                ext2 defaults   0       0

for snapshots:

/dev/fileserv_vol/codesnap	/export/home/codesnap		ext3 ro		0	0

mount -a