Adding a Disk and Extending a Logical Volume

From Peter Pap's Technowiki
Revision as of 03:42, 22 January 2015 by Ppapa (talk | contribs)

Jump to: navigation, search

So you have a logical volume that has run out of space and you need to add more. Either it's a VM and you've added another disk file or it's a physical server and you've added another disk.

1. Check the current disk devices with the following commands:

 # pvscan
   PV /dev/sdb1   VG data   lvm2 [100.00 GiB / 0    free]
   PV /dev/sdc1    VG data  lvm2 [100.00 GiB / 0    free]
   PV /dev/sda3   VG vg1    lvm2 [47.84 GiB / 17.59 GiB free]
   Total: 4 [247.83 GiB] / in use: 3 [247.83 GiB] / in no VG: 0 [0   ]
 
 # ls -al /dev/sd*
 brw-rw---- 1 root disk 8,  0 Jan 22 01:14 /dev/sda
 brw-rw---- 1 root disk 8,  1 Jan 22 01:14 /dev/sda1
 brw-rw---- 1 root disk 8,  2 Jan 22 01:14 /dev/sda2
 brw-rw---- 1 root disk 8,  3 Jan 22 01:14 /dev/sda3
 brw-rw---- 1 root disk 8, 16 Jan 22 01:14 /dev/sdb
 brw-rw---- 1 root disk 8, 17 Jan 22 01:14 /dev/sdb1
 brw-rw---- 1 root disk 8, 32 Jan 22 01:14 /dev/sdc
 brw-rw---- 1 root disk 8, 33 Jan 22 01:14 /dev/sdc1

2. Scan the scsi bus to find the new disk

List the host SCSI adapters

 # ls /sys/class/scsi_host/
 host0  host1  host2

Probe each host adapter

 # echo "- - -" > /sys/class/scsi_host/host0/scan
 # echo "- - -" > /sys/class/scsi_host/host1/scan
 # echo "- - -" > /sys/class/scsi_host/host2/scan

3. Check to see if the new device is there

 # ls -al /dev/sd*
 brw-rw---- 1 root disk 8,  0 Jan 22 01:14 /dev/sda
 brw-rw---- 1 root disk 8,  1 Jan 22 01:14 /dev/sda1
 brw-rw---- 1 root disk 8,  2 Jan 22 01:14 /dev/sda2
 brw-rw---- 1 root disk 8,  3 Jan 22 01:14 /dev/sda3
 brw-rw---- 1 root disk 8, 16 Jan 22 01:14 /dev/sdb
 brw-rw---- 1 root disk 8, 17 Jan 22 01:14 /dev/sdb1
 brw-rw---- 1 root disk 8, 32 Jan 22 01:14 /dev/sdc
 brw-rw---- 1 root disk 8, 33 Jan 22 01:14 /dev/sdc1
 brw-rw---- 1 root disk 8, 48 Jan 22 01:14 /dev/sdd

4. Add the disk to your machine as a primary partition

 # fdisk /dev/sdd
 Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
 Building a new DOS disklabel with disk identifier 0x663d32f6.
 Changes will remain in memory only, until you decide to write them.
 After that, of course, the previous content won't be recoverable.
 
 Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 
 WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
          switch off the mode (command 'c') and change display units to
          sectors (command 'u').
 
 Command (m for help): m
 Command action
    a   toggle a bootable flag
    b   edit bsd disklabel
    c   toggle the dos compatibility flag
    d   delete a partition
    l   list known partition types
    m   print this menu
    n   add a new partition
    o   create a new empty DOS partition table
    p   print the partition table
    q   quit without saving changes
    s   create a new empty Sun disklabel
    t   change a partition's system id
    u   change display/entry units
    v   verify the partition table
    w   write table to disk and exit
    x   extra functionality (experts only)
 
 Command (m for help): n
 Command action
    e   extended
    p   primary partition (1-4)
 p
 Partition number (1-4): 1
 First cylinder (1-13054, default 1):
 Using default value 1
 Last cylinder, +cylinders or +size{K,M,G} (1-13054, default 13054):
 Using default value 13054
 
 Command (m for help): w
 The partition table has been altered!
 
 Calling ioctl() to re-read partition table.
 Syncing disks.


5. Create a new physical LVM volume on our new disk.

 # pvcreate /dev/sdd1
   Physical volume "/dev/sdd1" successfully created
 
 You sould now have an additional device:
 # ls -al /dev/sd*
 brw-rw---- 1 root disk 8,  0 Jan 22 01:14 /dev/sda
 brw-rw---- 1 root disk 8,  1 Jan 22 01:14 /dev/sda1
 brw-rw---- 1 root disk 8,  2 Jan 22 01:14 /dev/sda2
 brw-rw---- 1 root disk 8,  3 Jan 22 01:14 /dev/sda3
 brw-rw---- 1 root disk 8, 16 Jan 22 01:14 /dev/sdb
 brw-rw---- 1 root disk 8, 17 Jan 22 01:14 /dev/sdb1
 brw-rw---- 1 root disk 8, 32 Jan 22 01:14 /dev/sdc
 brw-rw---- 1 root disk 8, 33 Jan 22 01:14 /dev/sdc1
 brw-rw---- 1 root disk 8, 48 Jan 22 01:14 /dev/sdd
 brw-rw---- 1 root disk 8, 49 Jan 22 01:14 /dev/sdd1

6. Extend the Volume Group, in this case called data

 # vgextend data /dev/sdd1
   Volume group "data" successfully extended

The new disk should now be added to the Volume Group:

 # vgdisplay -v data
     Using volume group(s) on command line
     Finding volume group "data"
   --- Volume group ---
   VG Name               data
   System ID
   Format                lvm2
   Metadata Areas        3
   Metadata Sequence No  11
   VG Access             read/write
   VG Status             resizable
   MAX LV                0
   Cur LV                1
   Open LV               1
   Max PV                0
   Cur PV                3
   Act PV                3
   VG Size               299.99 GiB
   PE Size               4.00 MiB
   Total PE              76797
   Alloc PE / Size       51193 / 199.97 GiB
   Free  PE / Size       25604 / 100.02 GiB
   VG UUID               lEHcjJ-OEEf-pEbi-J00j-5de9-T3ZE-4QPv4H
 
   --- Logical volume ---
   LV Name                /dev/data/blah
   VG Name                data
   LV UUID                aiOIEx-2kK5-RVGr-SHWv-InhH-B69p-j65ziL
   LV Write Access        read/write
   LV Status              available
   # open                 1
   LV Size                199.97 GiB
   Current LE             51193
   Segments               2
   Allocation             inherit
   Read ahead sectors     auto
   - currently set to     256
   Block device           253:1
 
   --- Physical volumes ---
   PV Name               /dev/sdb1
   PV UUID               C0KYU9-krfx-c7pw-pLWo-wf3l-EqiO-qBx3wi
   PV Status             allocatable
   Total PE / Free PE    25599 / 0
 
   PV Name               /dev/sdc1
   PV UUID               qIo3zt-TwBx-Ze6x-BZvy-aY7x-n1NP-IgimVk
   PV Status             allocatable
   Total PE / Free PE    25599 / 5
 
   PV Name               /dev/sdd1
   PV UUID               bbUskE-8rDY-CdgP-0tQy-CVrJ-SBZI-kaQmUj
   PV Status             allocatable
   Total PE / Free PE    25599 / 25599

7.