Skip to main content

Logical Volume Linux


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

 









Comments

Popular posts from this blog

Password Expiry notification for the users in zimbra 8.x within 7 Days for the email users

This Script will run as cron tab daily basis and it will alert the users for whom password is going to expire within 7 days. It will also alert admin for the users for whom password expired. Kindly replace the domain.com with your own domain name and the  /opt/zimbra/postfix-2.10.3.2z/sbin/sendmail  path to the actual path of postfix #!/bin/bash #Script for zimbra password expiry email notification. # Meant to be performed as daily cronjob run as zimbra user.  # redirect output to a file to get a 'log file' of sorts. # Time taken of script; echo "$SECONDS Started on: $(date)" # Set variables: # First notification in days, then last warning: FIRST="7" LAST="3" # pass expiry in days, we are assuming passwd exiry is 150 Days POLICY="150" # Sent from: FROM="admin@domain.com" # Get all users - it should run once only. USERS=$(ionice -c3 /opt/zimbra/bin/zmprov -l gaa domain.com) #Todays date, in seconds: DATE

How to Create a Delegated Admin Account in Zimbra 8.x

How to Create a Delegated Admin Account in Zimbra 8.x. Create a File as shown below with the contents .  Replace the domain.com and helpdesk Email id with your domain and helpdesk (Delegated Admin ) Name. #vi admindelegate #!/bin/bash # $1 domain.com # $2 helpdesk zmprov ma $2 zimbraIsDelegatedAdminAccount TRUE zmprov ma $2 zimbraAdminConsoleUIComponents cartBlancheUI zimbraAdminConsoleUIComponents domainListView zimbraAdminConsoleUIComponents accountListView zimbraAdminConsoleUIComponents DLListView zmprov ma $2 zimbraDomainAdminMaxMailQuota 0 zmprov grantRight domain $1 usr $2 +createAccount zmprov grantRight domain $1 usr $2 +createAlias zmprov grantRight domain $1 usr $2 +createCalendarResource zmprov grantRight domain $1 usr $2 +createDistributionList zmprov grantRight domain $1 usr $2 +deleteAlias zmprov grantRight domain $1 usr $2 +listDomain zmprov grantRight domain $1 usr $2 +domainAdminRights zmprov grantRight domain $1 usr $2 +configureQuota zmprov g

sendmail complete cofiguration with pop3 and squirrelmail

Sendmail Introduction Sendmail implements a general purpose internetwork mail routing facility. This document explain how to install sendmail and run an email server which will send and receive mail using the SMTP protocol. An IMAP or POP3 server is required to retrieve mail using Eudora or MS Outlook. Sendmail does not offer POP3 or IMAP services. Installation Prerequisites You should have a basic knowledge of UNIX and DNS. The server should allow incoming connections to the SMTP service which will be listening on TCP port 25. The server should have a fully qualified hostname (FQDN) such as mail.example.net. The hostname should resolve to an A record. It should not be a CNAME. The MX record for the domain for which you wish to receive mail should point to the hostname of your server. There should a PTR record for the IP address of your server. Mail from your server may be rejected if there is no reverse DNS. Installing sendmail Download the sendmail