LOGICAL VOLUME MANAGER in Linux


AIM
                        To perform a Logical volume operations on the disk.


PROCEDURE

Step1: Start

Step2: Open a new terminal from system tools.

Step3: To display a menu.
·        fdisk /dev/hda
·        click n for new partition
·        click l for logical partition

Step4: To mention the size give +5 = 0 occupying 5 cylinders.

Step5: Again click n for new partition and l for logical partitions.


Step6: Give size as +5M.
            Here we are giving 2 partitions.

Step7: Change partition’s system ID type t.
·        Partition number(1–11) : 11
·        Hex code(type L to list codes) : L
·        Code for LVM : 8e
·        code(type L to list codes) : 8e

Step8: For second partition
·        click t
·        partition number(1–11) : 11
·        code(type L to list codes) : 8e
·        changed system type of partition 11 to 8e (Linux LVM)

Step9: To add a new partition table with rebooting give partprobe.

Step10: For listing
·        fdisk –l
·        pvcreate/dev/hdc10 /dev/hdc11
·        pvdisplay to display
·        now we created 2 physical volumes.
Step11: To merge.
·        vgcreate /dev/vgo/hda10 /dev/hda11
Here volume geop will create
·        vgdisplay
Lvcreate –l +25mb –n/dev/vgo /lvm2
·        lvdisplay
     Logical volume LVM2 created
Step 12: To format and use the size
·        mkfs –t ext3 /dev/vgo1/lvm2
·        mount /dev/vgo1/lvm2/mnt
·        df
·        vgdisplay

Step 13:  To increase the space.
    Lvextend –L 38mb /dev/vgo1/lvm2

 OUTPUT

CREATING TWO PARTITIONS

[root@lab15-22 ~]# fdisk -l
Disk /dev/hdc: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/hdc1   *           1         397     3188871    6  FAT16
/dev/hdc2             398        4865    35889210    f  W95 Ext'd (LBA)
/dev/hdc5             398        2631    17944573+   7  HPFS/NTFS
/dev/hdc6            2632        2656      200781   83  Linux
/dev/hdc7            2657        3931    10241406   83  Linux
/dev/hdc8            3932        4313     3068383+  83  Linux
[root@lab15-22 ~]# fdisk /dev/hdc
The number of cylinders for this disk is set to 4865.
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): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (4314-4865, default 4314): 4314+5
Last cylinder or +size or +sizeM or +sizeK (4314-4865, default 4865): 4414
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (4415-4865, default 4415): 4415+5
Last cylinder or +size or +sizeM or +sizeK (4415-4865, default 4865): 4514
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (4515-4865, default 4515): 4515+5
Last cylinder or +size or +sizeM or +sizeK (4515-4865, default 4865): 4614
ASSIGNING HEX CODES FOR PARTITIONS
Command (m for help): t
Partition number (1-11): 11
Hex code (type L to list codes): l
 0  Empty           1e  Hidden W95 FAT1 80  Old Minix       be  Solaris boot  
 1  FAT12           24  NEC DOS         81  Minix / old Lin bf  Solaris       
 2  XENIX root      39  Plan 9          82  Linux swap / So c1  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  83  Linux           c4  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 5  Extended        41  PPC PReP Boot   85  Linux extended  c7  Syrinx        
 6  FAT16           42  SFS             86  NTFS volume set da  Non-FS data   
 7  HPFS/NTFS       4d  QNX4.x          87  NTFS volume set db  CP/M / CTOS / .
 8  AIX             4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility  
 9  AIX bootable    4f  QNX4.x 3rd part 8e  Linux LVM       df  BootIt        
 a  OS/2 Boot Manag 50  OnTrack DM      93  Amoeba          e1  DOS access    
 b  W95 FAT32       51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O       
 c  W95 FAT32 (LBA) 52  CP/M            9f  BSD/OS          e4  SpeedStor     
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs       
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a5  FreeBSD         ee  EFI GPT       
10  OPUS            55  EZ-Drive        a6  OpenBSD         ef  EFI (FAT-12/16/
11  Hidden FAT12    56  Golden Bow      a7  NeXTSTEP        f0  Linux/PA-RISC b
12  Compaq diagnost 5c  Priam Edisk     a8  Darwin UFS      f1  SpeedStor     
14  Hidden FAT16 <3 61  SpeedStor       a9  NetBSD          f4  SpeedStor     
16  Hidden FAT16    63  GNU HURD or Sys ab  Darwin boot     f2  DOS secondary 
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fd  Linux raid auto
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fe  LANstep       
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid ff  BBT           
1c  Hidden W95 FAT3 75  PC/IX         
Hex code (type L to list codes): 8e
Changed system type of partition 11 to 8e (Linux LVM)
Command (m for help): t
Partition number (1-11): 10
Hex code (type L to list codes): 8e
Changed system type of partition 10 to 8e (Linux LVM)
Command (m for help): t
Partition number (1-11): 9
Hex code (type L to list codes): 8e
Changed system type of partition 9 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.
[root@lab15-22 ~]# partprobe
[root@lab15-22 ~]# fdisk -l
Disk /dev/hdc: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hdc1   *           1         397     3188871    6  FAT16
/dev/hdc2             398        4865    35889210    f  W95 Ext'd (LBA)
/dev/hdc5             398        2631    17944573+   7  HPFS/NTFS
/dev/hdc6            2632        2656      200781   83  Linux
/dev/hdc7            2657        3931    10241406   83  Linux
/dev/hdc8            3932        4313     3068383+  83  Linux
/dev/hdc9            4314        4414      811251   8e  Linux LVM
/dev/hdc10           4415        4514      803218+  8e  Linux LVM
/dev/hdc11           4515        4614      803218+  8e  Linux LVM
MAKING TWO PARTITIONS TO PHYSICAL VOLUME
[root@lab15-22 ~]# pvcreate /dev/hdc10 /dev/hdc11
  Physical volume "/dev/hdc10" successfully created
  Can't initialize physical volume "/dev/hdc11" of volume group "vgo1" without -ff
[root@lab15-22 ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/hdc11
  VG Name               vgo1
  PV Size               2.69 GB / not usable 1.30 MB
  Allocatable           yes
  PE Size (KByte)       4096
  Total PE              688
  Free PE               688
  Allocated PE          0
  PV UUID               hw4FHq-ldVz-DDna-AsAh-y701-v4Rd-u8IaPv
  --- NEW Physical volume ---
  PV Name               /dev/hdc10
  VG Name              
  PV Size               784.39 MB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               nwV8Br-sXuO-OztP-rEQd-aF7C-L13p-KfaNBK
MERGING PHISICAL VOLUMES TO SINGLE VOLUMES
[root@lab15-22 ~]# vgcreate /dev/vgo1
 /dev/hdc10 /dev/hdc11
  Physical volume '/dev/hdc11' is already in volume group 'vgo1'
  Unable to add physical volume '/dev/hdc11' to volume group 'vgo4'.
[root@lab15-22 ~]# vgdisplay
  --- Volume group ---
  VG Name               vgo1
  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               2.69 GB
  PE Size               4.00 MB
  Total PE              688
  Alloc PE / Size       0 / 0  
  Free  PE / Size       688 / 2.69 GB
  VG UUID               qIx9QB-NtUS-6JtR-0e0r-uR21-q0Xv-WJdVVG
[root@lab15-22 ~]# lvcreate -L +25mb -n /dev/vgo1/lvm2
  Rounding up size to full physical extent 28.00 MB
  Logical volume "lvm2" created


FORMATING THE PARTITIONS
[root@lab15-22 ~]# mkfs -t ext3 /dev/vgo1/lvm2
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
7168 inodes, 28672 blocks
1433 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=29360128
4 block groups
8192 blocks per group, 8192 fragments per group
1792 inodes per group
Superblock backups stored on blocks:
        8193, 24577
Writing inode tables: done                           
Creating journal (1024 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.
MOUNTING
[root@lab15-22 ~]# mount /dev/vgo1/lvm2/mnt
mount: can't find /dev/vgo1/lvm2/mnt in /etc/fstab or /etc/mtab
[root@lab15-22 ~]# mount /dev/vgo1/lvm2 /mnt
[root@lab15-22 ~]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hdc7              9920592   3902072   5506452  42% /
/dev/hdc6               194442     10007    174396   6% /boot
tmpfs                   123788         0    123788   0% /dev/shm
/dev/hdc8              2972236     71668   2747152   3% /home
/dev/mapper/vgo1-lvm2
                         27761      1377     24951   6% /mnt
[root@lab15-22 ~]# vgdisplay
  --- Volume group ---
  VG Name               vgo1
  System ID            
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               2.69 GB
  PE Size               4.00 MB
  Total PE              688
  Alloc PE / Size       7 / 28.00 MB
  Free  PE / Size       681 / 2.66 GB
  VG UUID               qIx9QB-NtUS-6JtR-0e0r-uR21-q0Xv-WJdVVG
RESIZING THE PARTITION
[root@lab15-22 ~]# lvextend -L 38mb /dev/vgo1/lvm2
  Rounding up size to full physical extent 40.00 MB
  Extending logical volume lvm2 to 40.00 MB
  Logical volume lvm2 successfully resized
[root@lab15-22 ~]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hdc7              9920592   3902256   5506268  42% /
/dev/hdc6               194442     10007    174396   6% /boot
tmpfs                   123788         0    123788   0% /dev/shm
/dev/hdc8              2972236     71668   2747152   3% /home
/dev/mapper/vgo1-lvm2
                         27761      1377     24951   6% /mnt
UNMOUNTING
[root@lab15-22 ~]# umount /mnt
REMOVING THE LOGICAL VOLUME
[root@lab15-22 ~]# lvremove /dev/vgo1/lvm2
Do you really want to remove active logical volume "lvm2"? [y/n]: y
  Logical volume "lvm2" successfully removed
[root@lab15-22 ~]# lvdisplay
REMOVING THE VOLUME GROUP
[root@lab15-22 ~]# vgremove /dev/vgo1
  Volume group "vgo1" successfully removed
[root@lab15-22 ~]# vgdisplay
REMOVING THE PHYSICAL VOLUME
[root@lab15-22 ~]# pvremove /dev/hdc10 /dev/hdc11
  Labels on physical volume "/dev/hdc10" successfully wiped
  Labels on physical volume "/dev/hdc11" successfully wiped
[root@lab15-22 ~]# pvdisplay
REMOVING THE PARTITIONS
[root@lab15-22 ~]# fdisk /dev/hdc
The number of cylinders for this disk is set to 4865.
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): d
Partition number (1-11): 11
Command (m for help): d
Partition number (1-10): 10
Command (m for help): d
Partition number (1-9): 9
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.
[root@lab15-22 ~]# partprobe
[root@lab15-22 ~]# fdisk -l
Disk /dev/hdc: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/hdc1   *           1         397     3188871    6  FAT16
/dev/hdc2             398        4865    35889210    f  W95 Ext'd (LBA)
/dev/hdc5             398        2631    17944573+   7  HPFS/NTFS
/dev/hdc6            2632        2656      200781   83  Linux
/dev/hdc7            2657        3931    10241406   83  Linux
/dev/hdc8            3932        4313     3068383+  83  Linu

0 comments: