Difference between revisions of "Adding a Disk and Extending a Logical Volume"

From Peter Pap's Technowiki
Jump to: navigation, search
(Created page with "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 a...")
 
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
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.   
 
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. Scan the scsi bus to find the new 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.  Extend the Logical Volume, in this example by 50Gb
 +
 
 +
  # lvextend -L +50Gb /dev/data/blah
 +
    Extending logical volume blah to 249.97 GiB
 +
    Logical volume splunk successfully resized
 +
 
 +
8. Resize the Logical Volume to start using the new space
 +
 
 +
  # resize2fs -p /dev/data/blah
 +
  resize2fs 1.41.12 (17-May-2010)
 +
  Filesystem at /dev/data/blah is mounted on /data; on-line resizing required
 +
  old desc_blocks = 13, new_desc_blocks = 16
 +
  Performing an on-line resize of /dev/data/blah to 65528832 (4k) blocks.
 +
  The filesystem on /dev/data/blah is now 65528832 blocks long.
 +
 
 +
9. Check to see it worked
 +
 
 +
  # 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  12
 +
    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      63993 / '''249.97 GiB'''
 +
    Free  PE / Size      12804 / 50.02 GiB
 +
    VG UUID              lEHcjJ-OEEf-pEbi-J00j-5de9-T3ZE-4QPv4H
 +
 
 +
    --- Logical volume ---
 +
    LV Name                /dev/data/splunk
 +
    VG Name                data
 +
    LV UUID                aiOIEx-2kK5-RVGr-SHWv-InhH-B69p-j65ziL
 +
    LV Write Access        read/write
 +
    LV Status              available
 +
    # open                1
 +
    LV Size                '''249.97 GiB'''
 +
    Current LE            63993
 +
    Segments              '''3'''
 +
    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 / 0
 +
 
 +
    PV Name              /dev/sdd1
 +
    PV UUID              bbUskE-8rDY-CdgP-0tQy-CVrJ-SBZI-kaQmUj
 +
    PV Status            allocatable
 +
    Total PE / Free PE    25599 / 12804
 +
 
 +
  # df -h
 +
  Filesystem            Size  Used Avail Use% Mounted on
 +
  /dev/mapper/vg1-root 1008M  209M  749M  22% /
 +
  tmpfs                1.9G    0  1.9G  0% /dev/shm
 +
  /dev/mapper/vg1-app    25G  5.0G  19G  22% /app
 +
  /dev/sda1            124M  31M  88M  26% /boot
 +
  /dev/mapper/vg1-home 1008M  114M  844M  12% /home
 +
  /dev/mapper/vg1-tmp  756M  17M  701M  3% /tmp
 +
  /dev/mapper/vg1-usr  1.5G  1.1G  389M  73% /usr
 +
  /dev/mapper/vg1-var  2.0G  412M  1.5G  22% /var
 +
  /dev/mapper/data
 +
                      '''247G'''  186G  49G  80% /data
 +
 
 +
You're done!

Latest revision as of 03:48, 22 January 2015

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. Extend the Logical Volume, in this example by 50Gb

 # lvextend -L +50Gb /dev/data/blah
   Extending logical volume blah to 249.97 GiB
   Logical volume splunk successfully resized

8. Resize the Logical Volume to start using the new space

 # resize2fs -p /dev/data/blah
 resize2fs 1.41.12 (17-May-2010)
 Filesystem at /dev/data/blah is mounted on /data; on-line resizing required
 old desc_blocks = 13, new_desc_blocks = 16
 Performing an on-line resize of /dev/data/blah to 65528832 (4k) blocks.
 The filesystem on /dev/data/blah is now 65528832 blocks long.

9. Check to see it worked

 # 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  12
   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       63993 / 249.97 GiB
   Free  PE / Size       12804 / 50.02 GiB
   VG UUID               lEHcjJ-OEEf-pEbi-J00j-5de9-T3ZE-4QPv4H
 
   --- Logical volume ---
   LV Name                /dev/data/splunk
   VG Name                data
   LV UUID                aiOIEx-2kK5-RVGr-SHWv-InhH-B69p-j65ziL
   LV Write Access        read/write
   LV Status              available
   # open                 1
   LV Size                249.97 GiB
   Current LE             63993
   Segments               3
   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 / 0
 
   PV Name               /dev/sdd1
   PV UUID               bbUskE-8rDY-CdgP-0tQy-CVrJ-SBZI-kaQmUj
   PV Status             allocatable
   Total PE / Free PE    25599 / 12804
 # df -h
 Filesystem            Size  Used Avail Use% Mounted on
 /dev/mapper/vg1-root 1008M  209M  749M  22% /
 tmpfs                 1.9G     0  1.9G   0% /dev/shm
 /dev/mapper/vg1-app    25G  5.0G   19G  22% /app
 /dev/sda1             124M   31M   88M  26% /boot
 /dev/mapper/vg1-home 1008M  114M  844M  12% /home
 /dev/mapper/vg1-tmp   756M   17M  701M   3% /tmp
 /dev/mapper/vg1-usr   1.5G  1.1G  389M  73% /usr
 /dev/mapper/vg1-var   2.0G  412M  1.5G  22% /var
 /dev/mapper/data
                     247G  186G   49G  80% /data

You're done!