LVM: Difference between revisions

From Edgar BV Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
<pre>
= 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


== Preparing the Volume group (physical disks)  ==
<pre>
vgcreate tripserv_vol -s 64M /dev/hde /dev/hdf /dev/hdg /dev/hdh # creates the volume group tripserv_vol
vgcreate tripserv_vol -s 64M /dev/hde /dev/hdf /dev/hdg /dev/hdh # creates the volume group tripserv_vol
</pre>
== Creating the Logical Volumes ==
<pre>
lvcreate -i3 -I4 -L100M -nvolumename tripserv_vol
<pre>
creates the logical volume where


lvcreate -i3 -I4 -L100M -nvolumename tripserv_vol # create 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)
              StripeSize must be 2^n (n = 2 to 9)


# -L = size
* -L = size


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


# tripserv_vol = volumegroupname
* tripserv_vol = volumegroupname


mke2fs -j -Lfslabel /dev/tripserv_vol/volumename #formats the partition for use
== Format the logical volume / partition for use ==
mke2fs -j -Lfslabel /dev/tripserv_vol/volumename


# -j = journaling filesystem
* -j = journaling filesystem
# -L = labelname
* -L = labelname


# for snapshot volumes first unmount the drive you want to snapshot to then use  
* for snapshot volumes first unmount the drive you want to snapshot to then use  
lvcreate -L50M -s -n volumename /dev/tripserv_vol/journaleddevicename
<pre>
# mount it directly no need to mke2fs it
lvcreate -L50M -s -n volumename /dev/tripserv_vol/journaleddevicename </pre>
* mount it directly no need to mke2fs it


then in /etc/fstab
then in /etc/fstab


for journaled volumes:
for journaled volumes:
 
<pre>
/dev/tripserv_vol/code          /export/home/code              ext3 defaults  0      0
/dev/tripserv_vol/code          /export/home/code              ext3 defaults  0      0
 
</pre>
for non-journaled:
for non-journaled:
 
<pre>
/dev/tripserv_vol/sfx          /export/home/sfx                ext2 defaults  0      0
/dev/tripserv_vol/sfx          /export/home/sfx                ext2 defaults  0      0
 
</pre>
for snapshots:
for snapshots:
 
<pre>
/dev/tripserv_vol/codesnap /export/home/codesnap ext3 ro 0 0
/dev/tripserv_vol/codesnap /export/home/codesnap ext3 ro 0 0
 
</pre>
mount -a
mount -a


# Extending and reducing for LVM2
= Extending and reducing for LVM2 =


#Reducing
== Reducing ==
<pre?
unmount /dev/tripserv_vol/volumename
unmount /dev/tripserv_vol/volumename
e2fsck -f /dev/tripserv_vol/volumename
e2fsck -f /dev/tripserv_vol/volumename
Line 64: Line 77:
lvreduce /dev/tripserv_vol/volumename -L 150G
lvreduce /dev/tripserv_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
# 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
</pre>


#Extending
== Extending ==
<pre>
unmount /dev/tripserv_vol/volumename
unmount /dev/tripserv_vol/volumename
e2fsck -f /dev/tripserv_vol/volumename
e2fsck -f /dev/tripserv_vol/volumename
Line 71: Line 86:
# -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.
# -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/tripserv_vol/volumename
resize2fs /dev/tripserv_vol/volumename
<pre>


== 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/tripserv_vol/ etc), do
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/tripserv_vol/ etc), do


<pre>
vgscan
lvchange -a y /dev/tripserv_vol/volumename
lvchange -a y /dev/tripserv_vol/volumename
 
</pre>
which activates it.
which activates it.


Renaming a vg (if it's got the root on there)
= Renaming a VG (if it's got the root on there) =
start up the debian rescue and open a shell:
start up the debian rescue and open a shell:
 
<pre>
vgchange -a n oldvgname
vgchange -a n oldvgname
vgrename oldvgname newvgname
vgrename oldvgname newvgname
Line 86: Line 105:
lvscan
lvscan
vgchange -a y newvgname
vgchange -a y newvgname
 
</pre>
Then you need to put the newvgname into /etc/fstab and /boot/grub/menu.lst
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!
NB. Use nano to edit, vi / vim / emacs are probably not available!


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


(only lvm1)
(only lvm1)
<pre>
unmount /dev/tripserv_vol/volumename
unmount /dev/tripserv_vol/volumename
e2fsadm -L+15G /dev/tripserv_vol/volumename
e2fsadm -L+15G /dev/tripserv_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/tripserv_vol/volumename
lvextend /dev/tripserv_vol/volumename -L+100M (to enlarge by 100MB)
lvextend /dev/tripserv_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/tripserv_vol/volumename
resize2fs /dev/tripserv_vol/volumename
resize2fs /dev/tripserv_vol/volumename
e2fsck -fv /dev/tripserv_vol/volumename
e2fsck -fv /dev/tripserv_vol/volumename
 
</pre>
to reduce:
to reduce:
<pre>
umount /dev/tripserv_vol/volumename
umount /dev/tripserv_vol/volumename
resize2fs /dev/tripserv_vol/volumename 20971520 (new size of volume in blocks)
resize2fs /dev/tripserv_vol/volumename 20971520 (new size of volume in blocks)
Line 116: Line 138:
e2fsck -fv /dev/tripserv_vol/volumename
e2fsck -fv /dev/tripserv_vol/volumename
mount /dev/tripserv_vol/volumename
mount /dev/tripserv_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.


Line 124: Line 146:


to remove:
to remove:
 
<pre>
lvremove /dev/tripserv_vol/volumename
lvremove /dev/tripserv_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/tripserv_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>
<pre>
tripserv:/etc# pvscan
tripserv:/etc# pvscan
pvscan -- reading all physical volumes (this may take a while...)
pvscan -- reading all physical volumes (this may take a while...)

Revision as of 14:16, 15 April 2013

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 tripserv_vol -s 64M /dev/hde /dev/hdf /dev/hdg /dev/hdh 	# creates the volume group tripserv_vol

Creating the Logical Volumes

lvcreate -i3 -I4 -L100M -nvolumename tripserv_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 kilobytes for the granularity of the stripes.

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

* -L = size

* -n = name of logical volumename

* tripserv_vol = volumegroupname

== Format the logical volume / partition for use ==
mke2fs -j -Lfslabel /dev/tripserv_vol/volumename

* -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/tripserv_vol/journaleddevicename 
  • mount it directly no need to mke2fs it

then in /etc/fstab

for journaled volumes:

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

for non-journaled:

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

for snapshots:

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

mount -a

Extending and reducing for LVM2

Reducing

<pre? unmount /dev/tripserv_vol/volumename e2fsck -f /dev/tripserv_vol/volumename resize2fs /dev/tripserv_vol/volumename 150G

  1. will make the filesystem 150G large

lvreduce /dev/tripserv_vol/volumename -L 150G

  1. 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/tripserv_vol/volumename
e2fsck -f /dev/tripserv_vol/volumename
lvextend /dev/tripserv_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/tripserv_vol/volumename
<pre>

== 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/tripserv_vol/ etc), do

<pre>
vgscan
lvchange -a y /dev/tripserv_vol/volumename

which activates it.

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/tripserv_vol/volumename
e2fsadm -L+15G /dev/tripserv_vol/volumename

will make the volumename 15G larger

OR

unmount /dev/tripserv_vol/volumename
lvextend /dev/tripserv_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/tripserv_vol/volumename
resize2fs /dev/tripserv_vol/volumename
e2fsck -fv /dev/tripserv_vol/volumename

to reduce:

umount /dev/tripserv_vol/volumename
resize2fs /dev/tripserv_vol/volumename 20971520 (new size of volume in blocks)
lvreduce /dev/tripserv_vol/volumename -L-10G
e2fsck -fv /dev/tripserv_vol/volumename
mount /dev/tripserv_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/tripserv_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/tripserv_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
tripserv:/etc# pvscan
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/hdh1" of VG "tripserv_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/hdf1" of VG "tripserv_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]

tripserv:/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
tripserv:/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

tripserv:/etc#

tripserv:/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
tripserv:/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