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