LVM

From Edgar BV Wiki
Revision as of 10:52, 4 August 2008 by Red (talk | contribs)
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

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

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 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

mke2fs -j -Lfslabel /dev/tripserv_vol/volumename	#formats the partition for use

# -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/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
unmount /dev/tripserv_vol/volumename
e2fsck -f /dev/tripserv_vol/volumename
resize2fs /dev/tripserv_vol/volumename 150G
# will make the filesystem 150G large
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

#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

# Depreciated! 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

# 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