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