LVM

From Edgar BV Wiki
Revision as of 15:06, 13 May 2019 by Red (talk | contribs) (→‎Resizing a root LV)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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