Jaime Frutos Morales's blog

19/01/2010

How to create logical volumes in GNU/Linux with LVM

Filed under: Linux, SysAdmin — acidborg @ 17:58

This is a quick introduction to LVM configuration in GNU/Linux systems. LVM is a logical volume manager for the Linux kernel. I won’t explain the theory behind this technology in this post because it is well documented in Wikipedia. This post tries to be just a starting point for newcomers and a reminder for the rest.

1. Change partition label

Partitions which are going to be used by LVM must be labelled “Linux LVM”. To check partition table: fdisk -l

Device Boot Start End Blocks Id System
/dev/sda1 * 1 1550 20480000 83 Linux
/dev/sda2 1551 1806 2047984 82 Linux swap
/dev/sda3 1531 140013 274458624 83 Linux

To change a partition label: fdisk /dev/disk (sequence in this example: fdisk /dev/sda and then t, 3, 8e, w ) .

Device Boot Start End Blocks Id System
/dev/sda1 * 1 1275 10240000 83 Linux
/dev/sda2 1276 1530 2047984 82 Linux swap
/dev/sda3 1531 140013 274458624 8e Linux LVM

Restart to apply the changes to the partition table( shutdown -r now ) or use partprobe ( partprobe /dev/sda )

2. Creating physical volumes (PVs)

Physical volumes (which can be either hard disks, hard disk partitions or LUNs of an external storage device) are the basic units of storage for LVM. To create PVs, use pvcreate [partition,hd or lun] . For example, to create a PV from /dev/sda3: pvcreate /dev/sda3

3. Creating a volume groups (VG)

Once PVs are created, at least one volume group (VG) must be defined to use this PVs. A Volume Group is formed by one or more PVs and it abstracts the location of the storage space. To create a VG use: vgcreate vg_name PV1 [PV2 ... PVn]. Following the previous example, to create a VG which includes the PV /dev/sda3 use: vgcreate vg1 /dev/sda3 .

4. Creating logical volumes (LVs)

Once we have defined a VG, we can divide its storage space into logical volumes (LVs), which are partitions of a VG. To create a LV, use: lvcreate -Lsize -n lv_name vg_name. In our example, to create a LV of 50GB, we use this command: lvcreate -L50G -n lv1 vg1

5. Format LVs

We have already created all the infrastructure needed by LVM, but we have to format the LVs in order to use them. For example, to give EXT3 format to our recently created LV, we use the following command: mkfs.ext3 /dev/vg1/lv1

6. Mount LVs

The last thing to do before reading or writing to our brand new LVs is mounting it, so use mount to do it. For example: mkdir /mnt/test && mount -t ext3 /dev/vg1/lv1 /mnt/test

Advertisements

1 Comment

  1. […] original here: How to create logical volumes in GNU/Linux with LVM « Jaime Frutos … Share and […]

    Pingback by How to create logical volumes in GNU/Linux with LVM « Jaime Frutos … | Drakz Free Online Service — 20/01/2010 @ 03:11


RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Create a free website or blog at WordPress.com.

%d bloggers like this: