Sunday, 30 December 2012

LVM - Extending Linux Disk Space (Expanding disk size by adding new disk)

Why need to extend a disk? 
In the event of disk full or running out of space, you will consider to do the following. 

How should I proceed? 
1. Run a before-and-after command in order to justify changes being made.
On the  running-out-of-disk-space server, issue the command below to see output. 
# fdisk -l

Output:
[root@bacula bacula]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x00010027

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        6528    51915776   8e  Linux LVM

Disk /dev/mapper/vg_baculaserver-lv_root: 51.0 GB, 51044679680 bytes
255 heads, 63 sectors/track, 6205 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


Disk /dev/mapper/vg_baculaserver-lv_swap: 2113 MB, 2113929216 bytes
255 heads, 63 sectors/track, 257 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


Note: Again, above command is just for your information, no action required. You can see originally we have 50GB disk space. We're about to add another 50GB.



2. Adding new VM disk on the running-out-of-disk-space server at VM for 50GB.




3. After adding, it's recommend to restart the server to refresh changes made. 
# reboot
# fdisk -l

Output:
 [root@bacula ~]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x00010027

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        6528    51915776   8e  Linux LVM

Disk /dev/sdb: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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


Disk /dev/mapper/vg_baculaserver-lv_root: 51.0 GB, 51044679680 bytes
255 heads, 63 sectors/track, 6205 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


Disk /dev/mapper/vg_baculaserver-lv_swap: 2113 MB, 2113929216 bytes
255 heads, 63 sectors/track, 257 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


Note: There is new physical volume appeared which listed under /dev/sdb


4. Now, configure the physical volume
# fdisk /dev/sdb
[root@bacula ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xd164aa6a.
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): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-6527, default 1): <enter>
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527): <enter>
Using default value 6527

Command (m for help):

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@bacula ~]#


 

5.  Run again fdisk -l to see the changes made
Note: What we expecting is to see /dev/sdb is listed under boot disk
#fdisk -l
[root@bacula ~]# fdisk -l
Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x00010027

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        6528    51915776   8e  Linux LVM

Disk /dev/sdb: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0xd164aa6a

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb              1        6527    52428096   83  Linux (Note:If earlier partition number that you hit is '2', then it become /dev/sdb2)


Disk /dev/mapper/vg_baculaserver-lv_root: 51.0 GB, 51044679680 bytes
255 heads, 63 sectors/track, 6205 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

Disk /dev/mapper/vg_baculaserver-lv_swap: 2113 MB, 2113929216 bytes
255 heads, 63 sectors/track, 257 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


Note: /dev/sdb disk has created device boot named as /dev/sdb1,which means new physical device created.






6. Format the physical volume on /dev/sdb1
#mke2fs -j /dev/sdb1
[root@bacula ~]# mke2fs -j /dev/sdb1
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
3276800 inodes, 13107024 blocks
655351 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
400 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424

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

This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@bacula ~]#


 
 

7. To add /dev/sdb1 to /dev/sda2  (/dev/sda1 needs to have a different tool to combine with /dev/sdb1 to become a single partition)
i) List what Physical Volumes has now. To differentiate before and after. 
# pvdisplay
[root@bacula ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               vg_baculaserver
  PV Size               49.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              12674
  Free PE               0
  Allocated PE          12674
  PV UUID               Ihe0af-Stl3-CVFg-C1ZO-hsBK-hfqp-Ks90Ks


Note: You only see /dev/sda2, where is /dev/sdb1?


ii) Add /dev/sdb1 into pvdisplay and show pvdisplay
#pvcreate /dev/sdb1
[root@bacula ~]# pvcreate /dev/sdb1
  Writing physical volume data to disk "/dev/sdb1"
  Physical volume "/dev/sdb1" successfully created
[root@bacula ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               vg_baculaserver
  PV Size               49.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              12674
  Free PE               0
  Allocated PE          12674
  PV UUID               Ihe0af-Stl3-CVFg-C1ZO-hsBK-hfqp-Ks90Ks

  "/dev/sdb1" is a new physical volume of "50.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name
  PV Size               50.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               xkqJFU-coVt-zPJq-ncqQ-muaa-c0bv-KV4HrL

 

 Note: /dev/sdb1 is already added after issuing command pvdisplay. 7 (i) doesn't have it.

iii)  To Group /dev/sdb2 and /dev/sdb1 and issue a display to see result
# vgextend /dev/vg_baculaserver /dev/sdb1
[root@bacula ~]# vgextend /dev/vg_baculaserver /dev/sdb1
  Volume group "vg_baculaserver" successfully extended
[root@bacula ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_baculaserver
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               99.50 GiB
  PE Size               4.00 MiB
  Total PE              25473
  Alloc PE / Size       12674 / 49.51 GiB
  Free  PE / Size       12799 / 50.00 GiB
  VG UUID               hf53rJ-vpLK-1YHi-t13v-NjCQ-Ww1p-c0LJp7

[root@bacula ~]#


Note:  Now you can see under the VG Name, you can see only one partition which is vg_baculaserver. Previously was divided into 2 which were /dev/sda2 and dev/sdb1.VG size now has increased to 100Gb (99.5GB)

iv) Now you have create PV and VG. Lastly you need to create a logical volume
Before this, you need to display what are existing logical volume available
#lvdisplay 

[root@bacula ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg_baculaserver/lv_root
  LV Name                lv_root
  VG Name                vg_baculaserver
  LV UUID                ED1rOn-IasT-aDlz-olFn-h0t2-GJrB-G6pWn7
  LV Write Access        read/write
  LV Creation host, time bacula-server, 2012-12-06 20:53:48 +0800
  LV Status              available
  # open                 1
  LV Size                47.54 GiB
  Current LE             12170
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/vg_baculaserver/lv_swap
  LV Name                lv_swap
  VG Name                vg_baculaserver
  LV UUID                4kh0ak-ywH5-2FSR-TB2j-tROP-y7j6-6f3ZZj
  LV Write Access        read/write
  LV Creation host, time bacula-server, 2012-12-06 20:57:43 +0800
  LV Status              available
  # open                 1
  LV Size                1.97 GiB
  Current LE             504
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

[root@bacula ~]#


Note: LV size now is 47Gb (50GB) only. 

v) Issue command #lvextend -L+48GB /dev/vg_baculaserver/lv_root
[root@bacula ~]# lvextend -L+48GB /dev/vg_baculaserver/lv_root
  Extending logical volume lv_root to 95.54 GiB
  Logical volume lv_root successfully resized
[root@bacula ~]#


 Note: Note: Why it only extend 48GB but not 50GB? Due to system calculation concern, it can't be exactly 50GB but only lesser

Sample of error received if insert #lvextend -L+50GB /dev/vg_baculaserver/lv_root 

[root@bacula ~]# lvextend -L+50GB /dev/vg_baculaserver/lv_root
  Extending logical volume lv_root to 97.54 GiB
  Insufficient free space: 12800 extents needed, but only 12799 available


vi) Perform again lvdisplay to see result
 #lvdisplay

[root@bacula ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg_baculaserver/lv_root
  LV Name                lv_root
  VG Name                vg_baculaserver
  LV UUID                ED1rOn-IasT-aDlz-olFn-h0t2-GJrB-G6pWn7
  LV Write Access        read/write
  LV Creation host, time bacula-server, 2012-12-06 20:53:48 +0800
  LV Status              available
  # open                 1
  LV Size                95.54 GiB
  Current LE             24458
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/vg_baculaserver/lv_swap
  LV Name                lv_swap
  VG Name                vg_baculaserver
  LV UUID                4kh0ak-ywH5-2FSR-TB2j-tROP-y7j6-6f3ZZj
  LV Write Access        read/write
  LV Creation host, time bacula-server, 2012-12-06 20:57:43 +0800
  LV Status              available
  # open                 1
  LV Size                1.97 GiB
  Current LE             504
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

[root@bacula ~]#


 Note: LV size now has increased to 95.54Gb (100GB)

v)  Issue df -h to see usable size before and after applying resize. 
[root@bacula ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_baculaserver-lv_root
                       47G   12G   35G  25% /
tmpfs                 504M  188K  504M   1% /dev/shm
/dev/sda1             485M   32M  428M   7% /boot
\\\\192.168.130.1\\lms\\lms_backup
                      1.0T  594G  431G  58% /lmsbackup



[root@bacula ~]# resize2fs /dev/vg_baculaserver/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_baculaserver/lv_root is mounted on /; on-line resizing required
old desc_blocks = 3, new_desc_blocks = 6
Performing an on-line resize of /dev/vg_baculaserver/lv_root to 25044992 (4k) blocks.
The filesystem on /dev/vg_baculaserver/lv_root is now 25044992 blocks long.


[root@bacula ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_baculaserver-lv_root
                       95G   12G   82G  13% /
tmpfs                 504M  188K  504M   1% /dev/shm
/dev/sda1             485M   32M  428M   7% /boot
\\\\192.168.130.1\\lms\\lms_backup
                      1.0T  594G  431G  58% /lmsbackup
[root@bacula ~]#

 


Note: Usable size has been added. 

8. Completed. 

No comments:

Post a Comment