Using LVM2

by Mike on December 7, 2008

in Hardware

When you create an LVM all of the commands have the -v option to provide additional information.  In fact, each v you enter provides greater depth in the information so that for the most information available is when you have 4, -vvvv.

The first thing to do is evaluate the disks that you have available and determine the current settings.  Use fdisk -l to list the drive partitions and their settings.

# fdisk -l

Disk /dev/hda: 20.8 GB, 20847697920 bytes
255 heads, 63 sectors/track, 2534 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          64      514048+  83  Linux
/dev/hda2              65         829     6144862+  83  Linux
/dev/hda3             830        1211     3068415   83  Linux
/dev/hda4            1212        2534    10626997+   5  Extended
/dev/hda5            1212        1338     1020096   8e  Linux LVM
/dev/hda6            1339        1465     1020096   82  Linux swap / Solaris

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

Create a Linear Logical Volume on hdd

# 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

Command (m for help): t
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.

# partprobe

Create Logical Volumes

# pvcreate /dev/hdd2
Physical volume “/dev/hdd2″ successfully created
# vgcreate vg1 /dev/hdd2
Volume group “vg1″ successfully created
# 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.

Previous post:

Next post: