Post

Nov 16
How to create a logical disk with LVM on RedHat Linux 6.x

‚Äč1. Check if you have a new disk free to use

fdisk -l /dev/<disk>

example

[root@rhel01 ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

2. Create the partition table

parted /dev/<disk>

example

[root@rhel01 ~]# parted /dev/sdb
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
New disk label type? msdos
(parted) mkpart
Partition type?  primary/extended? p
File system type?  [ext2]? ext3
Start? 1m
End? 8589m
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 8590MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  8589MB  8588MB  primary

(parted) set
Partition number? 1
Flag to Invert? lvm
New state?  [on]/off? on
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 8590MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  8589MB  8588MB  primary               lvm

(parted) q
Information: You may need to update /etc/fstab.

[root@rhel01 ~]#

3. Create the physical volume

pvcreate /dev/<disk#>

example

[root@rhel01 ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created

4. Verify that the physical volume has been created successfully

pvdisplay

[root@rhel01 ~]# pvdisplay
 ...

  "/dev/sdb1" is a new physical volume of "8.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name
  PV Size               8.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               g5wx0B-Nlyb-ERBY-x5cS-apUO-A82u-aSnA9U

5. Create the volume group

vgcreate <vgname> /dev/<disk#>

example

[root@rhel01 ~]# vgcreate vg_vgroup01 /dev/sdb1
  Volume group "vg_vgroup01" successfully created

6. Verify that the volume group has been created

vgdisplay

example

[root@rhel01 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_vgroup01
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               8.00 GiB
  PE Size               4.00 MiB
  Total PE              2047
  Alloc PE / Size       0 / 0
  Free  PE / Size       2047 / 8.00 GiB
  VG UUID               iAUQL8-5N0f-9cD7-Ypcp-T1Fe-g1NF-SJdc43

  ...

7. Create the logical volume

lvcreate -L <size> <vgname> -n <lvname>

example

[root@rhel01 ~]# lvcreate -L 1G vg_vgroup01 -n lvdata01
  Logical volume "lvdata01" created

8. Verify that the logical volume has been created

lvdisplay

example

[root@rhel01 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg_vgroup01/lvdata01
  LV Name                lvdata01
  VG Name                vg_vgroup01
  LV UUID                oYfSNM-x6kK-Kbij-0IqX-hXwf-9OGc-KPy2C8
  LV Write Access        read/write
  LV Creation host, time rhel01, 2013-10-12 13:30:53 +0200
  LV Status              available
  # open                 0
  LV Size                1.00 GiB
  Current LE             256
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

...

9. Format the new logical volume

ls -ld /dev/mapper/<vgname>-<lvname>

example

[root@rhel01 ~]# ls -ld /dev/mapper/vg_vgroup01-lvdata01
lrwxrwxrwx. 1 root root 7 Oct 12 13:30 /dev/mapper/vg_vgroup01-lvdata01 -> ../dm-2

Now, format the new logical volume

mkfs.ext3 /dev/mapper/<vgname>-<lvname>

example
[root@rhel01 ~]# mkfs.ext3 /dev/mapper/vg_vgroup01-lvdata01
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

10. Create the mount point

mkdir /<mountpoint>

example

[root@rhel01 ~]# mkdir /data01

11. Mount the logical volume to the mount point

mount /dev/mapper/<vgname>-<lvname> /<mountpoint>

example

[root@rhel01 ~]# mount /dev/mapper/vg_vgroup01-lvdata01 /data01
[root@rhel01 ~]#

12. Verify that the mount is successfull

df -h

example

[root@rhel01 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_rhel01-lv_root
                       18G  2.2G   15G  14% /
tmpfs                 495M     0  495M   0% /dev/shm
/dev/sda1             485M   33M  427M   8% /boot
/dev/mapper/vg_vgroup01-lvdata01
                     1008M   34M  924M   4% /data01

13. Modify the /etc/fstab to make sure the filesystem is mounted at every boot

vi /etc/fstab

Add the following lines

/dev/mapper/<vgname>-<lvname> /<mountpoint>                       ext3    defaults        1 1

example

/dev/mapper/vg_vgroup01-lvdata01 /data01                       ext3    defaults        1 1

View the file /etc/fstab to make sure new entry is correct

cat /etc/fstab

example

[root@rhel01 ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Sun Sep 29 20:02:41 2013
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_rhel01-lv_root /                       ext4    defaults        1 1
UUID=02031ece-d9b6-4774-90ab-346917c9cbfd /boot                   ext4    defaults        1 2
/dev/mapper/vg_rhel01-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/mapper/vg_vgroup01-lvdata01 /data01                       ext3    defaults        1 1

14. Reboot your system

shutdown -r now

You're done !

Jun 12
Welcome to my sharepoint blog!

You will find usefull information about Linux, Database and Netbackup that will help you in your administration daily task ;-)