Skip to main content

How To Create Linux LVM In 3 Minutes

What’s LVM? Why using Linux Logical Volume Manager or LVM?


These questions are not the scope here. But in brief, the most attractive feature of Logical Volume Manager is to make disk management easier in Linux! Basically, LVM allows users to dynamically extend or shrink Linux “partition” or file system in online mode! The LVM can resize volume groups (VG) online by adding new physical volumes (PV) or rejecting those existing PVs attached to VG.


A visualized concept diagram of the Linux Logical Volume Manager or LVM

In this 3-minutes Linux LVM guide, let’s assume that


■The LVM is not currently configured or in used. Having say that, this is the LVM tutorial if you’re going to setup LVM from the ground up on a production Linux server with a new SATA / SCSI hard disk.

■Without a luxury server hardware, I tested this LVM tutorial on PC with the secondary hard disk dedicated for LVM setup. So, the Linux dev file of secondary IDE hard disk will be /dev/hdb (or /dev/sdb for SCSI hard disk).

■This guide is fully tested in Red Hat Enterprise Linux 4 with Logical Volume Manager 2 (LVM2) run-time environment (LVM version 2.00.31 2004-12-12, Library version 1.00.19-ioctl 2004-07-03, Driver version 4.1.0)!

How to setup Linux LVM in 3 minutes at command line?

1.Login with root user ID and try to avoid using sudo command for simplicity reason.


2.Using the whole secondary hard disk for LVM partition:

fdisk /dev/hdb


At the Linux fdisk command prompt,


1.press n to create a new disk partition,

2.press p to create a primary disk partition,

3.press 1 to denote it as 1st disk partition,

4.press ENTER twice to accept the default of 1st and last cylinder – to convert the whole secondary hard disk to a single disk partition,

5.press t (will automatically select the only partition – partition 1) to change the default Linux partition type (0×83) to LVM partition type (0×8e),

6.press L to list all the currently supported partition type,

7.press 8e (as per the L listing) to change partition 1 to 8e, i.e. Linux LVM partition type,

8.press p to display the secondary hard disk partition setup. Please take note that the first partition is denoted as /dev/hdb1 in Linux,

9.press w to write the partition table and exit fdisk upon completion.


3.Next, this LVM command will create a LVM physical volume (PV) on a regular hard disk or partition:

pvcreate /dev/hdb1


4.Now, another LVM command to create a LVM volume group (VG) called vg0 with a physical extent size (PE size) of 16MB:

vgcreate -s 16M vg0 /dev/hdb1

Be properly planning ahead of PE size before creating a volume group with vgcreate -s option!

5.Create a 400MB logical volume (LV) called lvol0 on volume group vg0:

lvcreate -L 400M -n lvol0 vg0

This lvcreate command will create a softlink /dev/vg0/lvol0 point to a correspondence block device file called /dev/mapper/vg0-lvol0.

6.The Linux LVM setup is almost done. Now is the time to format logical volume lvol0 to create a Red Hat Linux supported file system, i.e. EXT3 file system, with 1% reserved block count:

mkfs -t ext3 -m 1 -v /dev/vg0/lvol0


7.Create a mount point before mountin the new EXT3 file system:

mkdir /mnt/vfs


8.The last step of this LVM tutorial – mount the new EXT3 file system created on logical volume lvol0 of LVM to /mnt/vfs mount point:

mount -t ext3 /dev/vg0/lvol0 /mnt/vfs


To confirm the LVM setup has been completed successfully, the df -h command should display these similar message:

/dev/mapper/vg0-lvol0 388M 11M 374M 3% /mnt/vfs

Some of the useful LVM commands reference:

vgdisplay vg0

To check or display volume group setting, such as physical size (PE Size), volume group name (VG name), maximum logical volumes (Max LV), maximum physical volume (Max PV), etc.

 
pvscan

To check or list all physical volumes (PV) created for volume group (VG) in the current system.

vgextend

To dynamically adding more physical volume (PV), i.e. through new hard disk or disk partition, to an existing volume group (VG) in online mode. You’ll have to manually execute vgextend after pvcreate command that create LVM physical volume (PV).

Comments

Post a Comment

Popular posts from this blog

Typical Oracle RAC configurations

All configurations are based on the following building blocks: Hardware Server nodes Storage Networking Software Operating system Cluster software Oracle RAC (application) Application architecture Oracle9i RAC on RAW devices is based on a shared disk architecture. Figure 2-1 shows a two-node cluster. The lower solid line is the primary Oracle interconnect, the middle dashed line is the secondary Oracle interconnect. For high availability, both these networks should be defined in the HACMP as "private". HACMP/ESCRM provides Oracle9i RAC with the infrastructure for concurrent access to disks. Although HACMP provides concurrent access and a disk locking mechanism, this mechanism is not used. Oracle, instead, provides its own locking mechanism for concurrent data access, integrity, and consistency. Volume groups are varied on all the nodes, thus ensuring short failover time. This type of concurrent access can only be provided for RAW ...

Configuring the virtual path devices

We recommend that you start with a "fresh" disk configuration, so it is a good idea to delete all previously configured FC adapters and their child (disk) devices. On node1, we checked which disks are still defined: {node1:root}/-> lspvhdisk0 0022be2ab1cd11ac rootvg activehdisk1 0022be2a3d02ead0 Nonehdisk2 0022be2a4cbbafd8 Nonehdisk3 none NoneThese are the internal SCSI disk drives {node1:root}/-> lscfg grep disk+ hdisk3 U1.9-P2/Z2-A8 16 Bit LVD SCSI Disk Drive (36400 MB)+ hdisk2 U1.9-P2/Z1-A8 16 Bit LVD SCSI Disk Drive (36400 MB)+ hdisk1 U1.9-P1/Z2-A8 16 Bit LVD SCSI Disk Drive (36400 MB)+ hdisk0 U1.9-P1/Z1-A8 16 Bit LVD SCSI Disk Drive (36400 MB)In order to include the ESS disks, run the configuration manager on each node: {node1:root}/-> cfgmgr -vSince ESS was configured with two host paths for each node (node1a and node1b), this results in two hdisks on the nodes. Actually, those two logical hdisks represent the same physical disk, accessed via the two ...

Endian Firewall

With perilous threats from crackers and script kiddes lurking in the network, IT administrators could do no better than placing a firewall protection. Firewall prevents unwanted access to departmental systems while preventing local systems from attacking systems on the other network. It ensures that the traffic entering and leaving the secured LAN is accessing the correct applications on the correct computers. We had already done with the top free Windows firewall. However, there is cool open source firewall to take advantage of. Open source firewall not only offers better customization options, but also reduces the cost of ownership. After a comprehensive search we assorted the top 10 open source firewall. 1. Endian Firewall This is an open source firewall based on the IPCop Linux Firewall. It is one of the most widely used open source firewall with comprehensive features. It is almost an opensource Universal threat Management (UTM) device with a Statefull firewall, VPN, Webpro...