Creating Logical Volumes on Ubuntu 8.04
Server Training - Server Management

The logical volume management is an abstract layer that allows the administrator to manipulate the volumes that are created. This manipulation includes resizing the volumes when needed. The LVM recognizes and manages volumes spanning several drives. In addition physical devices can be added to the LVM.

Advantages of LVM
1. Multiple Drive Capability
You have the ability to create a LVM from multiple drives. Or you can add a drive and then expand the LVM to include the newly added drive. In the illustration you see that partitions from three separate drives; sda,sdb and sdc are used to create the volume group.

2. Re-sizable Volumes
Logical volumes can be extended or contracted to fit the needs of the user.

3. Disk Striping
Data can be striped across a number of drives to increase throughput.

4. Volume Mirroring

Volumes can be mirrored to provide redundancy much like a RAID 1.

5. Data Relocation
Data can be relocated on a new drive while the system is running.

6. Volume Snapshots
Volume snapshots provides a way to capture an image of the logical volume.

Notice that in the illustration, the foundation for Logical Volume Management is the creation of partitions on separate disks that can become physical volumes. These physical volumes are "glued" together to form a volume group. The volume group then can be divided into logical volumes and mounted on the file system.

logicla volume management

The LVM2 is the new version of LVM in the CentOS/RHEL 5 version but must be installed in Ubuntu, even Ubuntu 8.04. The LVM2 provides more efficient use of metadata storage and redundancy, stronger recovery formatting, and atomic changes to the metadata.

Perform these tasks at your own risk...back up your data...!

Install LVM2 on Ubuntu
sudo apt-get install lvm2

Create a Linear Logical Volume on hdd

Note it you are following our virtual machine for a practice server you may have created a SCSI drive so the second drive is actually called sdb so you need to replace /dev/hdd with /dev/sdb. The first thing you need to do is create partitions on the hard drive so that you have partitions to work on to create physical volumes for the logical volume management. Note: the example shows small drive partitions, this is simply for the sake of practice and obviously you would make much larger partitions on a production server. It is always a good idea to practice these skills before you are on a production server.

# fdisk /dev/hdd

The number of cylinders for this disk is set to 3736.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

(e.g., DOS FDISK, OS/2 FDISK)


Command (m for help): p


Disk /dev/hdd: 30.7 GB, 30735581184 bytes

255 heads, 63 sectors/track, 3736 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes


Device Boot Start End Blocks Id System

/dev/hdd1 * 1 127 1020096 8e Linux LVM


Command (m for help): n

Command action

e extended

p primary partition (1-4)

p

Partition number (1-4): 2

First cylinder (128-3736, default 128):

Using default value 128

Last cylinder or +size or +sizeM or +sizeK (128-3736, default 3736): +500M

Partition number (1-4): 2

Hex code (type L to list codes): 8e

Changed system type of partition 2 to 8e (Linux LVM)


Command (m for help): w

The partition table has been altered!


Calling ioctl() to re-read partition table.


WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table.

The new table will be used at the next reboot.

Syncing disks.


This now means that you have an new partition /dev/hdd2 which is a LVM of 500 MB.


Once you create the LVM it is important to either restart or run partprobe so the new partition is recognized.

Create Logical Volumes


# partprobe
This will help recognize the new partitions.

# pvcreate /dev/hdd2

Physical volume "/dev/hdd2" successfully created
You must create physical volumes as the foundation to the creation of any Logical Volumes. Note: Drives are small and are on the same physical disk which you would not do on a production server. This is an example for practice.

# vgcreate vg1 /dev/hdd2

Volume group "vg1" successfully created
The volume group is made up of any partitions that you want to include and "glue" them together to create a voluem group.

# lvcreate -L 450M -n data vg1

Rounding up size to full physical extent 452.00 MB

Logical volume "data" created

# mke2fs -j /dev/vg1/data

mke2fs 1.39 (29-May-2006)

Filesystem label=

OS type: Linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)

115824 inodes, 462848 blocks

23142 blocks (5.00%) reserved for the super user

First data block=1

Maximum filesystem blocks=67633152

57 block groups

8192 blocks per group, 8192 fragments per group

2032 inodes per group

Superblock backups stored on blocks:

8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

 

Writing inode tables: done

Creating journal (8192 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 24 mounts or

180 days, whichever comes first. Use tune2fs -c or -i to override.

This sequence has created the logical volumes and has placed the file system on the logical volume.

Mount the Logical Volume on the File System

# mkdir /data

# mount /dev/vg1/data/ /data

If this all works fine then edit your /etc/fstab to enter the volume to be mounted at boot time.

 


Copyright CyberMontana Inc. and BeginLinux.com
All rights reserved. Cannot be reproduced without written permission. Box 1262 Trout Creek, MT 59874