Traditional uses of LVM have included databases and company file servers, but even home users may want large partitions for music or video collections, or for storing online backups. LVM and RAID 1 can also be convenient ways to gain redundancy without sacrificing flexibility.
This article looks first at a basic file server, then explains some variations on that theme, including adding redundancy with RAID 1 and some things to consider when using LVM for desktop machines.
LVM Basics
To use LVM, you must understand several elements. First are the regular physical hard drives attached to the computer. The disk space on these devices is chopped up into partitions. Finally, a filesystem is written directly to a partition. By comparison, in LVM, Volume Groups (VGs) are split up into logical volumes (LVs), where the filesystems ultimately reside (Figure 1).Each VG is made up of a pool of Physical Volumes (PVs). You can extend (or reduce) the size of a Volume Group by adding or removing as many PVs as you wish, provided there are enough PVs remaining to store the contents of all the allocated LVs. As long as there is available space in the VG, you can also grow and shrink the size of your LVs at will (although most filesystems don't like to shrink).
Figure 1. An example LVM layout (Click to view larger image)
Example: A Basic File Server
A simple, practical example of LVM use is a traditional file server, which provides centralized backup, storage space for media files, and shared file space for several family members' computers. Flexibility is a key requirement; who knows what storage challenges next year's technology will bring?For example, suppose your requirements are:
400G - Large media file storage
50G - Online backups of two laptops and three desktops (10G each)
10G - Shared files
Ultimately, these requirements may increase a great deal over the
next year or two, but exactly how much and which partition will grow the
most are still unknown.Disk Hardware
Traditionally, a file server uses SCSI disks, but today SATA disks offer an attractive combination of speed and low cost. At the time of this writing, 250 GB SATA drives are commonly available for around $100; for a terabyte, the cost is around $400.SATA drives are not named like ATA drives (hda, hdb), but like SCSI (sda, sdb). Once the system has booted with SATA support, it has four physical devices to work with:
/dev/sda 251.0 GB
/dev/sdb 251.0 GB
/dev/sdc 251.0 GB
/dev/sdd 251.0 GB
Next, partition these for use with LVM. You can do this with fdisk
by specifying the "Linux LVM" partition type 8e. The finished product looks like this:# fdisk -l /dev/sdd
Disk /dev/sdd: 251.0 GB, 251000193024 bytes
255 heads, 63 sectors/track, 30515 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Start End Blocks Id System
/dev/sdd1 1 30515 245111706 8e Linux LVM
Notice the partition type is 8e
, or "Linux LVM."Creating a Virtual Volume
Initialize each of the disks using thepvcreate
command:# pvcreate /dev/sda /dev/sdb /dev/sdc /dev/sdd
This sets up all the partitions on these drives for use under LVM,
allowing creation of volume groups. To examine available PVs, use the pvdisplay
command. This system will use a single-volume group named datavg
:# vgcreate datavg /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1
Use vgdisplay
to see the newly created datavg
VG with the four drives stitched together. Now create the logical volumes within them:# lvcreate --name medialv --size 400G
# lvcreate --name backuplv --size 50G
# lvcreate --name sharelv --size 10G
Without LVM, you might allocate all available disk space to the
partitions you're creating, but with LVM, it is worthwhile to be
conservative, allocating only half the available space to the current
requirements. As a general rule, it's easier to grow a filesystem than
to shrink it, so it's a good strategy to allocate exactly what you need
today, and leave the remaining space unallocated until your needs become
clearer. This method also gives you the option of creating new volumes
when new needs arise (such as a separate encrypted file share for
sensitive data). To examine these volumes, use the lvdisplay
command.Now you have several nicely named logical volumes at your disposal:
/dev/datavg/backuplv (also /dev/mapper/datavg-backuplv)
/dev/datavg/medialv (also /dev/mapper/datavg-medialv)
/dev/datavg/sharelv (also /dev/mapper/datavg-sharelv)
Không có nhận xét nào:
Đăng nhận xét