1 | <?xml version="1.0" encoding="UTF-8"?>
|
---|
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 |
|
---|
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>
|
---|
34 | Management of disks with lvm is accomplished using the following concepts:
|
---|
35 | </para>
|
---|
36 |
|
---|
37 | <variablelist>
|
---|
38 | <varlistentry>
|
---|
39 | <term>physical volumes</term>
|
---|
40 | <listitem>
|
---|
41 | <para>
|
---|
42 | These are physical disks or partitions such as
|
---|
43 | /dev/sda3 or /dev/sdb.
|
---|
44 | </para>
|
---|
45 | </listitem>
|
---|
46 | </varlistentry>
|
---|
47 |
|
---|
48 | <varlistentry>
|
---|
49 | <term>volume groups</term>
|
---|
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>
|
---|
58 | </varlistentry>
|
---|
59 |
|
---|
60 | <varlistentry>
|
---|
61 | <term>logical volumes</term>
|
---|
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>
|
---|
70 |
|
---|
71 | </varlistentry>
|
---|
72 | </variablelist>
|
---|
73 |
|
---|
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>
|
---|
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)
|
---|
87 | /dev/sdb2 LVM remainder 8e (LVM)</literal></screen>
|
---|
88 |
|
---|
89 | <para>
|
---|
90 | First initialize the physical volumes:
|
---|
91 | </para>
|
---|
92 |
|
---|
93 | <screen><userinput>pvcreate /dev/sda4 /dev/sdb2</userinput></screen>
|
---|
94 |
|
---|
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>
|
---|
102 |
|
---|
103 | <para>
|
---|
104 | Next create a volume group named lfs-lvm:
|
---|
105 | </para>
|
---|
106 |
|
---|
107 | <screen><userinput>vgcreate lfs-lvm /dev/sda4 /dev/sdb2</userinput></screen>
|
---|
108 |
|
---|
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>
|
---|
116 |
|
---|
117 | <screen><userinput>lvcreate --name mysql --size 2500G lfs-lvm
|
---|
118 | lvcreate --name home --size 500G lfs-lvm</userinput></screen>
|
---|
119 |
|
---|
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>
|
---|
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 |
|
---|
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 |
|
---|
141 | <para revision="sysv">
|
---|
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.
|
---|
146 | </para>
|
---|
147 |
|
---|
148 | <para>
|
---|
149 | A LVM logical volume can host a root filesystem, but requires the use
|
---|
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 <ulink role='man'
|
---|
160 | url='&man;systemd.mount.5'>systemd.mount(5)</ulink>) as in the following
|
---|
161 | example, which mounts the <filename class="directory">/home</filename>
|
---|
162 | directory automatically at boot:
|
---|
163 | </para>
|
---|
164 |
|
---|
165 | <screen role="root" revision="systemd"><userinput>cat > /etc/systemd/system/home.mount << EOF
|
---|
166 | <literal>[Unit]
|
---|
167 | Description=Mount the lvm volume /dev/lfs-lvm/home to /home
|
---|
168 |
|
---|
169 | [Mount]
|
---|
170 | What=/dev/lfs-lvm/home
|
---|
171 | Where=/home
|
---|
172 | Type=ext4
|
---|
173 | Options=default
|
---|
174 |
|
---|
175 | [Install]
|
---|
176 | WantedBy=multi-user.target</literal>
|
---|
177 | EOF</userinput></screen>
|
---|
178 |
|
---|
179 | <note revision="systemd">
|
---|
180 | <para>
|
---|
181 | The name of the unit must be the name of the mount point with the
|
---|
182 | `/' character replaced by `-', omitting the leading one.
|
---|
183 | </para>
|
---|
184 | </note>
|
---|
185 |
|
---|
186 | <para revision="systemd">
|
---|
187 | Next the unit must be enabled with:
|
---|
188 | </para>
|
---|
189 |
|
---|
190 | <screen role="root" revision="systemd"><userinput>systemctl enable home.mount</userinput></screen>
|
---|
191 |
|
---|
192 | <para>
|
---|
193 | For more information about LVM, see the <ulink
|
---|
194 | url="https://tldp.org/HOWTO/LVM-HOWTO/">LVM HOWTO</ulink> and
|
---|
195 | the lvm man pages. A good in-depth
|
---|
196 | <ulink url="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/logical_volume_manager_administration/index">
|
---|
197 | guide</ulink> is available from RedHat<superscript>®</superscript>,
|
---|
198 | although it makes sometimes reference to proprietary tools.
|
---|
199 | </para>
|
---|
200 |
|
---|
201 | </sect1>
|
---|