Changes

Jump to: navigation, search

Logical Volume Management

1,466 bytes added, 13:41, 13 February 2014
no edit summary
** <code>vgs</code> - display compact information about all volume groups
** <code>vgdisplay</code> - display verbose information about all volume groups
** <code>vgcreate</code> - creates a new volume group. Usually, only one volume group is used per system, but additional ones can be created in special circumstances. You must specify at least one PV to create a LVVG.** <code>vgextend</code> - adds additional PVs to an LVa VG.** <code>vgreduce</code> - removes PVs from an LVa VG.** <code>vgremove</code> - destroys an LVa VG.
* LV management
** <code>lvs</code> - display compact information about all logical volumes
{{Admon/note|Using LVM in Fedora's Rescue Mode|The Fedora installation DVD has a "rescue mode" which may be used to fix problems on a previously-installed system -- useful if (for example) you have deleted or messed up a file that is necessary to successfully boot the system. In rescue mode, only a single LVM command is available: <code>lvm</code>. To use any of the lvm commands, you can type <code>lvm</code> followed by the name of the command you wish to execute. Alternately, typing <code>lvm</code> by itself will start the LVM shell, and you can then type any of the lvm commands directly. To use non-LVM commands, exit from the LVM shell.}}
== LVM Device Names ==[[Category:Linux]][[Category:Fedora]][[Category:OPS235]][[Category:OPS335]]
PVs are referenced by their normal block device name, such as /dev/sda1. VGs and LVs are referred to by names which are assigned when they are created.
Fedora's installation system, ''Anaconda'', will set up LVM by default. Anaconda will name the main volume group <code>lv_''hostname''</code>, where ''hostname'' is the host name assigned to the system during installation; LVs will be named <code>lv_''desc''</code> where ''desc'' is a description of the mountpoint (such as "root" for the LV containing the filesystem mounted as <code>/</code>, and "home" for the LV containing the filesystem mounted as <code>/home</code>). However, you can choose to use any names you want; it's a good idea to avoid names that could be confused with other devices (such as <code>sdb1</code> or <code>mouse0</code>).
LVs are found at two three points in the /dev/directory:
# <code>/dev/mapper/''vgname''-''lvname''</code>
# <code>/dev/''vgname''/''lvname''</code> # <code>/dev/dm- ''N'' - the names above are actually links to this device node. ''dm'' refers to the ''device mapper'', which is a symbolic link to the directory aboveunderlying technology that enables LVM.
{{Admon/note|LV names in Rescue Mode|Note that the LV symbolic links are not available in Fedora's rescue mode -- you must use the entry in <code>/dev/mapper</code>.}}
* as a virtual machine's storage device
Many LVM commands directly accept the LV name </code>(<code>vg_muskoka</code>) or the VG name and LV name separated by a slash (<code>vg_muskoka/lv_home</code>), but commands such as <code>mkfs</code> which are used with block devices require the full device name (<code>/dev/vg_muskoka/lv_home</code>)
== LVM and Booting ==
mount /dev/vg_muskoka/lv_archive /archive
# Edit /etc/fstab to have the filesystem file-system mounted automatically at boot time # (refer to [https://wiki.archlinux.org/index.php/fstab https://wiki.archlinux.org/index.php/fstab] for additional information) # Here is an example of issuing a command to add the mount point to the bottom of the /etc/fstab file:<br /><br />echo "/dev/vg_muskoka/lv_archive /archive ext3 defaults 1 2" >>/etc/fstab
Notice that the LV serves as a container for the filesystemfile-system, but otherwise the two are independent. If you increase the size of the logical volume, you must then increase the size of the filesystem file-system so that it fills the logical volume:
# Add 5G to the logical volume lv_home:
lvextend vg_muskoka/lv_home -r --size +5G
# Resize the filesystem to fill the LV --
# note that the filesystem can be mounted
# while this is performed:
resize2fs /dev/vg_muskoka/lv_main
When reducing the size of an LV-based filesystem, it's critical that you shrink the filesystem (the contents) before you shrink the LV (the container) -- otherwise you may lose data, and the filesystem will be damaged. Here is an example:
# Reduce the filesystem in lv_home by 5G
resize2fs /dev/vg_muskoka/lv_home -5G50G
# Shrink the LV:
lvreduce vg_muskoka/lv_home --size -5G
# or specify an absolute size of 50G<br /><br />Note: If you are experiencing problems mounting the reduced LV, it may be due to the difference in extent size<br /> between the LINV and the filesystem layer. To fix this problem,<br /> remove the LV, create, format the LV, and then resize only using the lvreduce command with the -r option.<br /> This automatically reduces the filesystem , and the LV.<br /> Refer to this example below"<br /><br />lvreduce -r vg_muskoka/lv_home --size 50G
{{Admon/important|Check your arguments!|lvreduce, and lvextend, and resize2fs can all both take absolute or relative size arguments. For example, <code>-5G</code> means "reduce the size by five gigabytes", but <code>5G</code> means "make the size five gigabytes". If you have a 100G LV, the command <code>lvresize vg_muskoka/lv_home --size -5G</code> would shrink it to 95G, but accidentally typing <code>lvresize vg_muskoka/lv_home --size 5G</code> would shrink it to 5G. This would cause data loss if you have previously resized the filesystem to 95G. Remember to check your commands carefully.}} {{Admon/important|Non-integer sizes|The LVM commands accept fractional sizes such as 1.5G, but resize2fs does not -- so you must use the next-smallest unit. For example, 1.5G corresponds to 1536M (1.5 * 1024M).}}
Remember the order in which the filesystem and LV size must be adjusted:
If a system is installed with all of the VG space in use, it will be necessary to add a PV or reduce the size of an LV in order to add any more LVs or to grow one of the existing LVs. '''It's therefore a much better idea to create small LVs initially, leaving some unused space in the VG which can be assigned as needed'''.
 
=== Adding a Physical Volume ===
 
To add a physical volume to the system:
# Add the disk (if not already attached) -- for this example, let's assume the disk is <code>/dev/sdb</code>
# Create a partition with <code>fdisk</code> - let's assume the partition is <code>/dev/sdb1</code>
# Mark the partition as usable by LVM: <code>pvcreate /dev/''sdb1''</code>
# Add the partition to your volume group: <code>vgextend vg_main /dev/''sdb1''</code>
13,420
edits

Navigation menu