feed-image  ISSN 1836-5930



Receive Your Complimentary Guide to Linux NOW!


A Newbie's Getting Started Guide to Linux

Linux from Scratch - Create Your Own Linux System - Free eBook

The GNU/Linux Advanced Administration

A Complete Beginner's Manual for Ubuntu 10.04 (Lucid Lynx)




Poll

Do you care about your privacy when using a FACEBOOK?
 

linuxconfig.org
is hosted by:



Partner Linux Sites
TuxMachines
DebianAdmin
Monsterb
LinuxBloggers
AdamsInfo
LinuxScrew
FreeSoftwareLinux
All For Linux

Linux lvm - Logical Volume Manager
Article Index
1. This is what we are going to do
2. Create Partitions
3. Create physical volumes
4. Create Virtual Group
5. Create Logical Volumes
6. Create File system on logical volumes
7. Edit /etc/fstab
7.1. Mount logical volumes
8. Extend logical volume
9. Remove logical volume

This article describes a basic logic behind a Linux logical volume manager by showing real examples of configuration and usage. Although Debian Linux will be used for this tutorial, you can also apply the same command line syntax with other Linux distributions such as Red Hat, Mandriva, SuSe Linux and others.

1. This is what we are going to do

Logical Volume Manager

2. Create Partitions

For this Linux lvm example you need an unpartitioned hard disk /dev/sdb. First you need to create physical volumes. To do this you need partitions or a whole disk. It is possible to run pvcreate command on /dev/sdb, but I prefer to use partitions and from partitions I later create physical volumes.

Logical Volume Manager List Partitions with fdisk
Use your preferred partitioning tool to create partitions. In this example I have used cfdisk.

Create partitions with cfdiskLogical Volume Manager List Partitions with fdisk


Partitions are ready to use.

3. Create physical volumes

Use the pvcreate command to create physical volumes.

# pvcreate /dev/sdb1
# pvcreate /dev/sdb2

The pvdisplay command displays all physical volumes on your system.

# pvdisplay 

Alternatively the following command should be used:

# pvdisplay /dev/sdb1 

Create physical volumes with pvcreate

4. Create Virtual Group

At this stage you need to create a virtual group which will serve as a container for your physical volumes. To create a virtual group with the name "mynew_vg" which will include /dev/sdb1 partition, you can issue the following command:

# vgcreate mynew_vg /dev/sdb1 

To include both partitions at once you can use this command:

# vgcreate mynew_vg /dev/sdb1 /dev/sdb2 

Create Virtual Group

Feel free to add new physical volumes to a virtual group by using the vgextend command.

# vgextend mynew_vg /dev/sdb2 

virtual group extend

5. Create Logical Volumes

From your big cake (virtual group) you can cut pieces (logical volumes) which will be treated as a partitions for your linux system. To create a logical volume, named "vol01", with a size of 400 MB from the virtual group "mynew_vg" use the following command:

  • create a logical volume of size 400 MB -L 400
  • create a logical volume of size 4 GB -L 4G
# lvcreate -L 400 -n vol01 mynew_vg

lvm lvcreate

With a following example you will create a logical volume with a size of 1GB and with the name vol02:

# lvcreate -L 1000 -n vol02 mynew_vg

 

lvcreate

Note the free size in virtual group.

lvcrete free space

6. Create File system on logical volumes

The logical volume is almost ready to use. All you need to do is to create a filesystem.:

# mkfs.ext3 -m 0 /dev/mynew_vg/vol01 

the -m option specifies the percentage reserved for the super-user, set this to 0 if you wish not to waste any space, the default is 5%. create file system on the logical volumes

7. Edit /etc/fstab

Add an entry for your newly created logical volume into /etc/fstab
edit /etc/fstab to include logical volumes

7.1. Mount logical volumes

Before you mount do not forget to create a mount point.

# mkdir /home/foobar 

mount logical volumes

8. Extend logical volume

The biggest advantage of logical volume manager is that you can extend your logical volumes any time you are running out of the space. To increase the size of a logical volume by another 800 MB you can run this command:

# lvextend -L +800 /dev/mynew_vg/vol01 

Extend logical volume
The command above does not actually increase the physical size of volume, to do that you need to:

# resize2fs  /dev/mynew_vg/vol01 

Look at the figure below to see what problems you may encounter when extending a volume:
Problem with extending a logical volume

9. Remove logical volume

The command lvremove can be used to remove logical volumes. Make sure that before you attempt to remove logical volumes your logical volume does not have any valuable data stored on it, moreover, make sure the volume is unmounted.

# lvdisplay 

display volume group

# lvremove /dev/mynew_vg/vol02 

remove logical volume


Get FREE complimentary Linux Guides

The GNU/Linux Advanced Administration
The GNU/Linux systems have reached an important level of maturity, allowing to integrate them in almost any kind of work environment, from a desktop PC to the sever facilities of a big company.

In this ebook "The GNU/Linux Operating System", the main contents are related with system administration. You will learn how to install and configure several computer services, and how to optimize and synchronize the resources using GNU/Linux.

The topics covered in this 500+ page eBook include Linux network, server and data administration, Linux kernel, security, clustering, configuration, tuning, optimization, migration and coexistence with non-Linux systems. A must read for any serious Linux system admin.

A Newbie's Getting Started Guide to Linux
Learn the basics of the Linux operating systems. Get to know what it is all about, and familiarize yourself with the practical side. Basically, if you're a complete Linux newbie and looking for a quick and easy guide to get you started this is it.

You've probably heard about Linux, the free, open-source operating system that's been pushing up against Microsoft. It's way cheaper, faster, safer, and has a far bigger active community than Windows, so why aren't you on it? Don't worry, Makeuseof.com understands. Like many things, venturing off into a completely unknown world can seem rather scary, and also be pretty difficult in the beginning. It's while adapting to the unknown, that one needs a guiding, and caring hand. This guide will tell you all you need to know in 20 illustrated pages, helping you to take your first steps. Let your curiosity take you hostage and start discovering Linux today, with this manual as your guide! Don't let Makeuseof.com keep you any longer, and download the Newbie's Initiation to Linux. With this free guide you will also receive daily updates on new cool websites and programs in your email for free courtesy of MakeUseOf.

Linux from Scratch
Linux from Scratch describes the process of creating your own Linux system from scratch from an already installed Linux distribution, using nothing but the source code of software that you need.

This 318 page eBook provides readers with the background and instruction to design and build custom Linux systems. This eBook highlights the Linux from Scratch project and the benefits of using this system. Users can dictate all aspects of their system, including directory layout, script setup, and security. The resulting system will be compiled completely from the source code, and the user will be able to specify where, why, and how programs are installed. This eBook allows readers to fully customize Linux systems to their own needs and allows users more control over their system.

A Complete Beginner's Manual for Ubuntu 10.04 (Lucid Lynx)
Getting Started with Ubuntu 10.04 (Lucid Lynx) is a comprehensive beginners guide for the Ubuntu operating system; it features comprehensive guides, How Tos and information on anything you need to know after first installing Ubuntu.

Designed to be as user-friendly and easy to follow as possible, it should provide the first point of reference to any Ubuntu newcomer with lots of information. The manual has step by step instructions and includes lots of screenshots to show you how to do tasks. It also includes a Troubleshooting section to help you solve common Ubuntu problems quickly. Download this 160+ page manual today.

Comments (23)
  • avinash

    Hi,
    My fdisk -l output is

    root@fstl-laptop:/home/fstl# fdisk -l

    Disk /dev/sda: 160.0 GB, 160041885696 bytes
    255 heads, 63 sectors/track, 19457 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Disk identifier: 0x000752dd

    Device Boot Start End Blocks Id System
    /dev/sda1 * 1 18731 150456726 83 Linux
    /dev/sda2 18732 19457 5831595 5 Extended
    /dev/sda5 18732 19457 5831563+ 82 Linux swap / Solaris


    can i create lvm on my machine?

  • avinash

    Let me ask you a question first ! What are you trying to achieve by creating LVM? Since you have a hard drive in your computer you are always able to create LVM

  • avinash  - lvm

    In the above mentioned above fdisk -l output...is it possible to extend the partitions so that i can do lvm?
    or else when i reinstall the os and make four partitions and if two partitions are full of data then we can give more memory to those partitions by using lvm is it right?

    Thank u
    avinash

  • lubos  - can give more memory to those partitions by using

    There is no simple process of extending a non-lvm partition. It depends on the filesystem you use.

    >
    or else when i reinstall the os and make four partitions and if two partitions are full of data then we can give more memory to those partitions by using lvm is it right?

    If your partitions full of data are logical volumes you can extend them by add yet another partition from the same or different drive to a logical group.

    I'm not sure if I understood your question correctly.

  • avinash  - lvm

    Thank u for responding.

    ok i got the answer.

    Thank u again
    avinash

  • LinuxLion

    Hi All,
    Its awesome article. it will help everyone whos starting lvm.

    Can anyone update the link / in the same page about advance lvm?

    It will help everyone (freshers & Exp) who needs LVM.

  • Srinivasulu

    It is wonderful article for the beginners.

  • Vivek  - Wonderful Article

    hi,

    it's very useful article for beginners like me..
    thanks..

  • ramesh  - Nice articel

    Hi,

    It's really very super.. Nice article, very use full for me..

  • shoaib  - how to remove lvm

    I have created lvm partitin using parted
    ->mkpart logical ext2 4200 4700
    set 9 lvm on
    my question is how to remove lvm
    secondly
    what is and in /etc/fstab & what value should be

  • Ashita Shah  - how to identify if the logical volume is striped o

    we have lvcreate command that helps to create striped volume like below
    #lvm lvcreate vg02 --stripes 3 --stripesize 128k --name lv01 --size 250M

    But in case I need to check whether the logical volume is striped how can this be done?
    lvdisplay does not give any such info.

  • polgas  - where do i get the space

    suppose i used all available space in my hard drive. and i want to grow one logical volume, where do i get the extra space? do i need to reduce logvol01 so i can increase logvol02?

  • lubos  - where do i get the space - LVM

    Hi polgas,

    You can always hook-in another hard drive and add it to an yet existing volume group and then extend your logvol02.

    do not forget to do backup before you do something until it is not too late :-))

  • Lee  - maybe a typo ?

    Hi,

    What's the point of creating physical partions 1.8 and 3.2 GB? Why not just use the whole disk? What's the strategy behind partitioning the way you did?

    Thanks

  • Lubos  - What's the point of creating physical partions 1.8

    Good question. This is just a illustration on what can be done with LVM.

    Of course you can create one single partition and include it into one group. The point is that one of the partitions can be from completely different hard drive and yet when included in the same volume group it is treated as a single disk.

    hope this helps..

  • Manu Ignatius  - Thankyou very much

    Thankyou very much for this article. i was very tired searching to fix my hdd by adding some space and this helped me a lot. thanks

  • Greggercode  - resize2fs

    I dont understand why resize2fs could not increase the filesystem space Online.

    I have tested this command several time and it work perfectly fine for me .

  • Frank  - LvChange ??

    Hi,

    I think you forgot to issue lvchange -a y ....
    Without it I was not able to create the file system.

    Thanks for you piece on LVM

    Cheers

    Frank

  • Rakesh Sardesai  - One Mistake u have made.

    The partiton ID of linux LVM partition should be 8e.So mention the same in above document also.

  • lubos  - lvcreate - missing

    Hi guys,

    thanks for your comments. I have had recently transfered all articles from old system and I lost this lvcreate part somewhere on the way.

    Missing part retrieved from a backup and add to the article.

    thank you

  • Adhika  - lvcreate

    you forget the lvcreate.
    and Brady is right, it supposed to appear after vgcreate step.

    in this article, it supposed to be:
    lvcreate -L 1G -n vol01 mynew_vg

    anyway, thanks a lot for the article. helps me to understand. Especially for the wonderful picture to explain how it is supposed to look.

    Keep up the good work.

  • brady  - lvcreate

    you left out the lvcreate step. it should appear after the vgcreate step, no?

  • pankaj  - thanx

    hiiii this web site is very much helpful for me in compliting my project report on the topic of Logical Volume Management in LINUX...
    Thanx

Write comment
NOTE: To unsubscribe enter your email, select "do not dotify" with title: UNSUBSCRIBE and Send.
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
Security
Please input the anti-spam code that you can read in the image.