-
Notifications
You must be signed in to change notification settings - Fork 0
/
managing_lv.txt
275 lines (182 loc) · 7.23 KB
/
managing_lv.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
Ch.7 - Managing Logical Volumes
LVMs makes managing disk space easier.
Hierarchy:
-Physical Devices --> Physical Volumes(PVs) --> Volume Groups(VGs) --> Logical Volumes(LVs)
Creating LVM storage requires several steps.
1.Determine which physical devices to use.
2.Initialize your device(s) as a physical volume(s) so that they are recognized as belonging to LVM.
3.Combine the physical volume(s) into a volume group.
(This creates a pool of disk space out of which logical volumes can be allocated.)
*Logical volumes created from the available space in a volume group can be formatted with a file system, activated as swap space, and mounted or activated persistently.)
----------------------------------------------------
Creating Logical Volumes
Steps:
1.Prepare the physical device
Use parted, gdisk, or fdisk to create a new partition for use with LVM.
Always set the partition type to Linux LVM on LVM partitions
Ex:
-[root@host ~]# parted -s /dev/vdb mkpart primary 1MiB 769MiB
-[root@host ~]# parted -s /dev/vdb mkpart primary 770MiB 1026MiB
-[root@host ~]# parted -s /dev/vdb set 1 lvm on
-[root@host ~]# parted -s /dev/vdb set 2 lvm on
**A physical device only needs to be prepared if there are none prepared already and a new physical volume is
required to create or extend a volume group.
2.Create a physical volume
Ex:
- pvcreate /dev/vdb2 /dev/vdb1
(This labels the devices /dev/vdb2 and /dev/vdb1 as PVs, ready for allocation into a volume group.)
*A PV only needs to be created if there are no PVs free to create or extend a VG.
3.Create a volume group
Ex:
- vgcreate vg01 /dev/vdb2 /dev/vdb1
**vg01 is the vg_name
(This creates a VG called vg01 that is the combined size, in PE units, of the two PVs /dev/vdb2 and /dev/vdb1.)
4.Create a logical volume
Ex:
- lvcreate -n lv01 -L 700M vg01
(This creates an LV called lv01, 700 MiB in size, in the VG vg01.)
Notes:
**lv01 is the lv_name
**the -n option to set the LV name,
**the -L option to set the LV size in bytes or the -l option to set the LV size in extents,
**the name of the volume group hosting this logical volume.(vg01)
5.Add the file system and make it available across reboots
Ex:
a. mkfs -t xfs /dev/vg01/lv01
b. mkdir /mnt/data
c. /dev/vg01/lv01 /mnt/data xfs defaults 1 2
(add this entry to /etc/fstab file)
d. mount /mnt/data
(to mount the file system that you just added in /etc/fstab)
e. systemctl daemon-reload
-------------------------------------------------
Removing a Logical Volume
Important!!!
**Back up or move your data before you remove the logical volume otherwise you may destroy any data stored on the LV.
1.Prepare the file system
Ex:
- umount /mnt/data
2.Remove the LV
Ex:
- lvremove /dev/vg01/lv01
(Use lvremove DEVICE_NAME to remove a logical volume that is no longer needed.)
3.Remove the VG
Ex:
- vgremove vg01
(Use vgremove VG_NAME to remove a volume group that is no longer needed.)
4.Remove the PV
Ex:
- pvremove /dev/vdb2 /dev/vdb1
(Use pvremove to remove physical volumes that are no longer needed.)
------------------------------------------------------
Reviewing LVM Status Information
1.Physical Volumes
Ex:
- pvdisplay /dev/vdb1
(Use pvdisplay to display information about physical volumes.)
2.Volume Groups
Ex:
- vgdisplay vg01
(Use vgdisplay to display information about volume groups.)
3.Logical Volumes
Ex:
- lvdisplay /dev/vg01/lv01
(Use lvdisplay to display information about logical volumes.)
-----------------------------------------------------
Extending and Reducing a Volume Group
1.Extend a volume group (VG) using pvcreate and vgextend,
and use vgdisplay to verify the results.
Ex:
a. pvcreate
b. vgextend
c. vgdisplay
2.Reduce a VG using pvmove and vgreduce.
Ex:
a. pvmove
b. vgreduce
3.Extend a logical volume (LV) using lvextend.
Ex:
- lvextend
4.Resize XFS file systems with xfs_growfs.
Ex:
- xfs_growfs
5.Resize ext4 file systems with resize2fs.
Ex:
- resize2fs
Extending a Volume Group:
Steps:
1.Prepare the physical device and create the physical
volume.
Ex:
a.parted -s /dev/vdb mkpart primary 1027MiB 1539MiB
b.parted -s /dev/vdb set 3 lvm on
c.pvcreate /dev/vdb3
2.Extend the volume group.
Ex:
- vgextend vg01 /dev/vdb3
3.Verify that the new space is available.
Ex:
- vgdisplay vg01
**Use vgdisplay to confirm the additional physical extents are available.
Inspect the Free PE / Size in the output. It should not be zero.
**************************************
Reducing a Volume Group
Steps:
1.Move the physical extents.
Ex:
- pvmove /dev/vdb3
**This command moves the PEs from /dev/vdb3 to other PVs with free PEs in the same VG.
**Before using pvmove, back up data stored on all logical volumes in the volume group.
2.Reduce the volume group.
Ex:
- vgreduce vg01 /dev/vdb3
**This removes the /dev/vdb3 PV from the vg01 VG and it can now be added to another VG.
Alternatively, pvremove can be used to permanently stop using the device as a PV.
-------------------------------------
Extending a Logical Volume and XFS File System
Extending a Logical Volume
1.Verify that the volume group has space available.
Ex:
- vgdisplay vg01
Notes:
Inspect the Free PE/Size in the output. Confirm that the volume group has sufficient
free space for the LV extension. If insufficient space is available, then extend the
volume group appropriately.
2.Extend the logical volume.
Ex:
- lvextend -L +300M /dev/vg01/lv01
**This increases the size of the logical volume lv01 by 300 MiB.
**As with lvcreate, different methods exist to specify the size: the -l option expects the
number of physical extents as the argument. The -L option expects sizes in bytes, mebibytes,
gibibytes, and similar.
3.Extend the file system.
Ex:
- xfs_growfs /mnt/data
**Use xfs_growfs mountpoint to expand the file system to occupy the extended LV.
Notes:
An alternative to running the two steps consecutively is to include the -r option with the
lvextend command. This resizes the file system after the LV is extended, using fsadm(8).
Ex:
- lvextend -r -L +300M /dev/vg01/lv01
4.Verify the new size of the mounted file system.
Ex:
- df -h /mountpoint
------------------------------------------------------
Extending a Logical Volume and ext4 File System
See steps 1 and 2 as above.
3.Extend the file system.
Ex:
- resize2fs /dev/vg01/lv01
**Use resize2fs /dev/vgname/lvname to expand the file system to occupy the new extended LV.
------------------------------------------------------
Extend a Logical Volume and Swap Space
1.Verify the volume group has space available.
**Use vgdisplay vgname to verify that a sufficient number of free physical extents are available.
2.Deactivate the swap space.
**Use swapoff -v /dev/vgname/lvname to deactivate the swap space on the logical volume.
3.Extend the logical volume.
**lvextend -l +extents /dev/vgname/lvname extends the logical volume /dev/vgname/lvname by the extents value.
4.Format the logical volume as swap space.
**mkswap /dev/vgname/lvname formats the entire logical volume as swap space.
5.Activate the swap space.
**Use swapon -va /dev/vgname/lvname to activate the swap space on the logical volume.