[7e1df8f9] | 1 | <?xml version="1.0" encoding="ISO-8859-1"?>
|
---|
| 2 | <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
---|
| 3 | "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
|
---|
| 4 | <!ENTITY % general-entities SYSTEM "../../general.ent">
|
---|
| 5 | %general-entities;
|
---|
| 6 | ]>
|
---|
| 7 |
|
---|
| 8 | <sect1 id="aboutlvm">
|
---|
| 9 | <?dbhtml filename="aboutlvm.html"?>
|
---|
| 10 |
|
---|
| 11 | <sect1info>
|
---|
| 12 | <date>$Date$</date>
|
---|
| 13 | </sect1info>
|
---|
| 14 |
|
---|
| 15 | <title>About Logical Volume Management (LVM)</title>
|
---|
| 16 |
|
---|
[29244b7] | 17 | <para>
|
---|
| 18 | LVM manages disk drives. It allows multiple drives and partitions
|
---|
| 19 | to be combined into larger <emphasis>volume groups</emphasis>, assists in
|
---|
| 20 | making backups through a <emphasis>snapshot</emphasis>, and allows for
|
---|
| 21 | dynamic volume resizing. It can also provide mirroring similar to
|
---|
| 22 | a RAID 1 array.
|
---|
| 23 | </para>
|
---|
| 24 |
|
---|
| 25 | <para>
|
---|
| 26 | A complete discussion of LVM is beyond the scope of this introduction,
|
---|
| 27 | but basic concepts are presented below.
|
---|
| 28 | </para>
|
---|
| 29 |
|
---|
| 30 | <para>
|
---|
| 31 | To run any of the commands presented here, the <xref linkend='lvm2'/>
|
---|
| 32 | package must be installed. All commands must be run as the <systemitem
|
---|
| 33 | class="username">root</systemitem> user.
|
---|
| 34 | </para>
|
---|
| 35 |
|
---|
| 36 | <para>
|
---|
[8558044] | 37 | Management of disks with lvm is accomplished using the following concepts:
|
---|
[29244b7] | 38 | </para>
|
---|
[7e1df8f9] | 39 |
|
---|
| 40 | <variablelist>
|
---|
| 41 | <varlistentry>
|
---|
| 42 | <term>physical volumes</term>
|
---|
[29244b7] | 43 | <listitem>
|
---|
| 44 | <para>
|
---|
| 45 | These are physical disks or partitions such as
|
---|
| 46 | /dev/sda3 or /dev/sdb.
|
---|
| 47 | </para>
|
---|
| 48 | </listitem>
|
---|
[7e1df8f9] | 49 | </varlistentry>
|
---|
| 50 |
|
---|
| 51 | <varlistentry>
|
---|
| 52 | <term>volume groups</term>
|
---|
[29244b7] | 53 | <listitem>
|
---|
| 54 | <para>
|
---|
| 55 | These are named groups of physical volumes that
|
---|
| 56 | can be manipulated by the administrator. The number of physical
|
---|
| 57 | volumes that make up a volume group is arbitrary. Physical volumes
|
---|
| 58 | can be dynamically added or removed from a volume group.
|
---|
| 59 | </para>
|
---|
| 60 | </listitem>
|
---|
[7e1df8f9] | 61 | </varlistentry>
|
---|
| 62 |
|
---|
| 63 | <varlistentry>
|
---|
| 64 | <term>logical volumes</term>
|
---|
[29244b7] | 65 | <listitem>
|
---|
| 66 | <para>
|
---|
| 67 | Volume groups may be subdivided into logical volumes. Each logical
|
---|
| 68 | volume can then be individually formatted as if it were a regular
|
---|
| 69 | Linux partition. Logical volumes may be dynamically resized by
|
---|
| 70 | the administrator according to need.
|
---|
| 71 | </para>
|
---|
| 72 | </listitem>
|
---|
[7e1df8f9] | 73 |
|
---|
| 74 | </varlistentry>
|
---|
[0d7900a] | 75 | </variablelist>
|
---|
[7e1df8f9] | 76 |
|
---|
[29244b7] | 77 | <para>
|
---|
| 78 | To give a concrete example, suppose that you have two 2 TB disks. Also
|
---|
| 79 | suppose a really large amount of space is required for a very large
|
---|
| 80 | database, mounted on <filename class='directory'>/srv/mysql</filename>.
|
---|
| 81 | This is what the initial set of partitions would look like:
|
---|
| 82 | </para>
|
---|
[7e1df8f9] | 83 |
|
---|
| 84 | <screen><literal>Partition Use Size Partition Type
|
---|
| 85 | /dev/sda1 /boot 100MB 83 (Linux)
|
---|
| 86 | /dev/sda2 / 10GB 83 (Linux)
|
---|
| 87 | /dev/sda3 swap 2GB 82 (Swap)
|
---|
| 88 | /dev/sda4 LVM remainder 8e (LVM)
|
---|
| 89 | /dev/sdb1 swap 2GB 82 (Swap)
|
---|
[0d7900a] | 90 | /dev/sdb2 LVM remainder 8e (LVM)</literal></screen>
|
---|
[7e1df8f9] | 91 |
|
---|
[29244b7] | 92 | <para>
|
---|
| 93 | First initialize the physical volumes:
|
---|
| 94 | </para>
|
---|
[7e1df8f9] | 95 |
|
---|
| 96 | <screen><userinput>pvcreate /dev/sda4 /dev/sdb2</userinput></screen>
|
---|
| 97 |
|
---|
[29244b7] | 98 | <note>
|
---|
| 99 | <para>
|
---|
| 100 | A full disk can be used as part of a physical volume, but
|
---|
| 101 | beware that the <command>pvcreate</command> command will destroy any
|
---|
| 102 | partition information on that disk.
|
---|
| 103 | </para>
|
---|
| 104 | </note>
|
---|
[20598a7] | 105 |
|
---|
[29244b7] | 106 | <para>
|
---|
| 107 | Next create a volume group named lfs-lvm:
|
---|
| 108 | </para>
|
---|
[7e1df8f9] | 109 |
|
---|
| 110 | <screen><userinput>vgcreate lfs-lvm /dev/sda4 /dev/sdb2</userinput></screen>
|
---|
| 111 |
|
---|
[29244b7] | 112 | <para>
|
---|
| 113 | The status of the volume group can be checked by running the command
|
---|
| 114 | <command>vgscan</command>. Now create the logical volumes. Since there
|
---|
| 115 | is about 3900 GB available, leave about 900 GB free for expansion. Note
|
---|
| 116 | that the logical volume named <emphasis>mysql</emphasis> is larger than
|
---|
| 117 | any physical disk.
|
---|
| 118 | </para>
|
---|
[7e1df8f9] | 119 |
|
---|
| 120 | <screen><userinput>lvcreate --name mysql --size 2500G lfs-lvm
|
---|
| 121 | lvcreate --name home --size 500G lfs-lvm</userinput></screen>
|
---|
| 122 |
|
---|
[29244b7] | 123 | <para>
|
---|
| 124 | Finally the logical volumes can be formatted and mounted. In this
|
---|
| 125 | example, the jfs file system (<xref linkend='jfsutils'/>) is used for
|
---|
| 126 | demonstration purposes.
|
---|
| 127 | </para>
|
---|
[7e1df8f9] | 128 |
|
---|
| 129 | <screen><userinput>mkfs -t ext4 /dev/lfs-lvm/home
|
---|
| 130 | mkfs -t jfs /dev/lfs-lvm/mysql
|
---|
| 131 | mount /dev/lfs-lvm/home /home
|
---|
| 132 | mkdir -p /srv/mysql
|
---|
| 133 | mount /dev/lfs-lvm/mysql /srv/mysql</userinput></screen>
|
---|
| 134 |
|
---|
[dd071443] | 135 | <para>
|
---|
| 136 | It may be needed to activate those logical volumes, for them to
|
---|
| 137 | appear in <filename class="directory">/dev</filename>. They can all
|
---|
| 138 | be activated at the same time by issuing, as the
|
---|
| 139 | <systemitem class="username">root</systemitem> user:
|
---|
| 140 | </para>
|
---|
| 141 |
|
---|
| 142 | <screen role="root"><userinput>vgchange -a y</userinput></screen>
|
---|
| 143 |
|
---|
[55dc313] | 144 | <para revision="sysv">
|
---|
[dd071443] | 145 | The LFS boot scripts automatically make these logical volumes available to
|
---|
| 146 | the system in the <command>udev</command> script. Edit the
|
---|
| 147 | <filename>/etc/fstab</filename> file as required to automatically mount
|
---|
| 148 | them.
|
---|
[29244b7] | 149 | </para>
|
---|
| 150 |
|
---|
| 151 | <para>
|
---|
| 152 | A LVM logical volume can host a root filesystem, but requires the use
|
---|
[55dc313] | 153 | of an initramfs (initial RAM file system). The initramfs proposed in
|
---|
| 154 | <xref linkend="initramfs"/> allows to pass the lvm volume in
|
---|
| 155 | the <parameter>root=</parameter> switch of the kernel command line.
|
---|
| 156 | </para>
|
---|
| 157 |
|
---|
| 158 | <para revision="systemd">
|
---|
| 159 | If not using an initramfs, there is a race condition in <application>
|
---|
| 160 | systemd</application> preventing mounting logical volumes through
|
---|
| 161 | <filename>/etc/fstab</filename>. You must create a <quote>mount</quote>
|
---|
| 162 | unit (see systemd.mount(5)) as in the following example, which mounts
|
---|
| 163 | the <filename class="directory">/home</filename> directory automatically
|
---|
| 164 | at boot:
|
---|
[29244b7] | 165 | </para>
|
---|
| 166 |
|
---|
[55dc313] | 167 | <screen role="root" revision="systemd"><userinput>cat > /etc/systemd/system/home.mount << EOF
|
---|
| 168 | <literal>[Unit]
|
---|
| 169 | Description=Mount the lvm volume /dev/lfs-lvm/home to /home
|
---|
| 170 |
|
---|
| 171 | [Mount]
|
---|
| 172 | What=/dev/lfs-lvm/home
|
---|
| 173 | Where=/home
|
---|
| 174 | Type=ext4
|
---|
| 175 | Options=default
|
---|
| 176 |
|
---|
| 177 | [Install]
|
---|
| 178 | WantedBy=multi-user.target</literal>
|
---|
| 179 | EOF</userinput></screen>
|
---|
| 180 |
|
---|
| 181 | <note revision="systemd">
|
---|
| 182 | <para>
|
---|
| 183 | The name of the unit must be the name of the mount point with the
|
---|
| 184 | `/' character replaced by `-', omitting the leading one.
|
---|
| 185 | </para>
|
---|
| 186 | </note>
|
---|
| 187 |
|
---|
| 188 | <para revision="systemd">
|
---|
| 189 | Next the unit must be enabled with:
|
---|
| 190 | </para>
|
---|
| 191 |
|
---|
| 192 | <screen role="root" revision="systemd"><userinput>systemctl enable home.mount</userinput></screen>
|
---|
| 193 |
|
---|
[29244b7] | 194 | <para>
|
---|
[dd071443] | 195 | For more information about LVM, see the <ulink
|
---|
[29244b7] | 196 | url="http://www.tldp.org/HOWTO/LVM-HOWTO/">LVM HOWTO</ulink> and
|
---|
[dd071443] | 197 | the lvm man pages. A good in-depth
|
---|
| 198 | <ulink url="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/logical_volume_manager_administration/index">
|
---|
| 199 | guide</ulink> is available from RedHat<superscript>®</superscript>,
|
---|
| 200 | although it makes sometimes reference to proprietary tools.
|
---|
[29244b7] | 201 | </para>
|
---|
[7e1df8f9] | 202 |
|
---|
| 203 | </sect1>
|
---|