LVM: Difference between revisions
(9 intermediate revisions by the same user not shown) | |||
Line 19: | Line 19: | ||
== Preparing the Volume group (physical disks) == | == Preparing the Volume group (physical disks) == | ||
<pre> | <pre> | ||
vgcreate | vgcreate fileserv_vol -s 64M /dev/hde /dev/hdf /dev/hdg /dev/hdh # creates the volume group fileserv_vol | ||
</pre> | </pre> | ||
== Creating the Logical Volumes == | == Creating the Logical Volumes == | ||
<pre> | <pre> | ||
lvcreate -i3 -I4 -L100M -nvolumename | lvcreate -i3 -I4 -L100M -nvolumename fileserv_vol | ||
</pre> | </pre> | ||
creates the logical volume where | 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. | * -I = Gives the number of kilobytes for the granularity of the stripes. | ||
Line 38: | Line 38: | ||
* -n = name of logical volumename | * -n = name of logical volumename | ||
* | * fileserv_vol = volumegroupname | ||
or | |||
<pre> | |||
lvcreate -n volumename -l 100%FREE fileserv_vol | |||
</pre> | |||
to use all of the disk | |||
== Format the logical volume / partition for use == | == Format the logical volume / partition for use == | ||
mke2fs - | <pre> | ||
mke2fs -t ext4 -Lfslabel /dev/fileserv_vol/volumename | |||
</pre> | |||
== Mount in fstab == | |||
/etc/fstab entry looks like | |||
<pre> | <pre> | ||
/dev/mapper/fileserv_vol-volumename /some/mountpoint ext4 defaults 0 2 | |||
</pre> | |||
test mount with | |||
<pre> | <pre> | ||
mount -a | |||
</pre> | </pre> | ||
for | |||
= Extending and reducing for LVM2 = | |||
<pre> | <pre> | ||
/dev/ | unmount the volume | ||
e2fsck -f /dev/vg/lvname | |||
resize2fs /dev/vg/lvname sizeM/G | |||
lvresize /dev/vg/lvname -L sizeM/G | |||
</pre> | </pre> | ||
just in case and to test: | |||
<pre> | <pre> | ||
/dev/ | resize2fs /dev/vg/lvname | ||
e2fsck -f /dev/vg/lvname | |||
</pre> | </pre> | ||
then check using lvscan | |||
== Reducing == | == Reducing == | ||
<pre> | <pre> | ||
unmount /dev/ | unmount /dev/fileserv_vol/volumename | ||
e2fsck -f /dev/ | e2fsck -f /dev/fileserv_vol/volumename | ||
resize2fs /dev/ | resize2fs /dev/fileserv_vol/volumename 150G | ||
</pre> | </pre> | ||
will make the filesystem 150G large | will make the filesystem 150G large | ||
<pre> | <pre> | ||
lvreduce /dev/ | lvreduce /dev/fileserv_vol/volumename -L 150G | ||
</pre> | </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 | 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 | ||
Line 83: | Line 90: | ||
== Extending == | == Extending == | ||
<pre> | <pre> | ||
unmount /dev/ | unmount /dev/fileserv_vol/volumename | ||
e2fsck -f /dev/ | e2fsck -f /dev/fileserv_vol/volumename | ||
lvextend /dev/ | 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> | <pre> | ||
resize2fs /dev/fileserv_vol/volumename | |||
</pre> | |||
== Resizing a root LV == | == 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/ | 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 | ||
<pre> | <pre> | ||
vgscan | vgscan | ||
lvchange -a y /dev/ | lvchange -a y /dev/fileserv_vol/volumename | ||
</pre> | </pre> | ||
which activates it. | which activates it. | ||
[https://wiki.edgarbv.com/index.php/VMWare_ESXi#Expanding_HDs_on_a_VM Expanding HDs on a VM] | |||
= Renaming a VG (if it's got the root on there) = | = Renaming a VG (if it's got the root on there) = | ||
Line 117: | Line 128: | ||
(only lvm1) | (only lvm1) | ||
<pre> | <pre> | ||
unmount /dev/ | unmount /dev/fileserv_vol/volumename | ||
e2fsadm -L+15G /dev/ | e2fsadm -L+15G /dev/fileserv_vol/volumename | ||
</pre> | </pre> | ||
will make the volumename 15G larger | will make the volumename 15G larger | ||
Line 124: | Line 135: | ||
OR | OR | ||
<pre> | <pre> | ||
unmount /dev/ | unmount /dev/fileserv_vol/volumename | ||
lvextend /dev/ | lvextend /dev/fileserv_vol/volumename -L+100M (to enlarge by 100MB) | ||
</pre> | </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> | <pre> | ||
e2fsck -fv /dev/ | e2fsck -fv /dev/fileserv_vol/volumename | ||
resize2fs /dev/ | resize2fs /dev/fileserv_vol/volumename | ||
e2fsck -fv /dev/ | e2fsck -fv /dev/fileserv_vol/volumename | ||
</pre> | </pre> | ||
to reduce: | to reduce: | ||
<pre> | <pre> | ||
umount /dev/ | umount /dev/fileserv_vol/volumename | ||
resize2fs /dev/ | resize2fs /dev/fileserv_vol/volumename 20971520 (new size of volume in blocks) | ||
lvreduce /dev/ | lvreduce /dev/fileserv_vol/volumename -L-10G | ||
e2fsck -fv /dev/ | e2fsck -fv /dev/fileserv_vol/volumename | ||
mount /dev/ | mount /dev/fileserv_vol/volumename | ||
</pre> | </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 149: | Line 160: | ||
to remove: | to remove: | ||
<pre> | <pre> | ||
lvremove /dev/ | lvremove /dev/fileserv_vol/volumename | ||
</pre> | </pre> | ||
== Snapshots == | == Snapshots == | ||
Line 155: | Line 166: | ||
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> | </pre> | ||
lvcreate -s -L500M -n docusnap /dev/ | lvcreate -s -L500M -n docusnap /dev/fileserv_vol/docu | ||
</pre> | </pre> | ||
# If the pv size displayed < the disk size | # If the pv size displayed < the disk size | ||
Line 165: | Line 176: | ||
</pre> | </pre> | ||
<pre> | <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 " | pvscan -- ACTIVE PV "/dev/hdg1" of VG "fileserv_vol" [38.16 GB / 7.93 GB free] | ||
pvscan -- ACTIVE PV "/dev/hdh1" of VG " | pvscan -- ACTIVE PV "/dev/hdh1" of VG "fileserv_vol" [38.16 GB / 8.01 GB free] | ||
pvscan -- ACTIVE PV "/dev/hde1" of VG " | pvscan -- ACTIVE PV "/dev/hde1" of VG "fileserv_vol" [55.91 GB / 0 free] | ||
pvscan -- ACTIVE PV "/dev/hdf1" of VG " | 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] | ||
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 193: | Line 204: | ||
You have new mail in /var/spool/mail/root | 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. | The number of cylinders for this disk is set to 116336. | ||
Line 212: | Line 223: | ||
Command (m for help): q | Command (m for help): q | ||
fileserv:/etc# | |||
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 | ||
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 227: | Line 238: | ||
hdb: hdb1 | hdb: hdb1 | ||
</pre> | </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.
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
- 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