0

I have a CentOS machine with 1 hard drive and partition as follow:

[root@localhost var]# fdisk -l

Disk /dev/sda: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          19      152586   83  Linux
/dev/sda2              20         280     2096482+  82  Linux swap / Solaris
/dev/sda3             281        2610    18715725   8e  Linux LVM
[root@localhost var]# vgs
  VG      #PV #LV #SN Attr   VSize  VFree
  vg_root   1   3   0 wz--n- 17.84G    0
[root@localhost var]# pvs
  PV         VG      Fmt  Attr PSize  PFree
  /dev/sda3  vg_root lvm2 a--  17.84G    0
[root@localhost var]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg_root/lv_root
  VG Name                vg_root
  LV UUID                YFfzh2-03mH-zrHa-INJn-iqxZ-vYpo-XDyimP
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                8.91 GB
  Current LE             285
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Name                /dev/vg_root/lv_var_lib_mysql
  VG Name                vg_root
  LV UUID                xdoJuc-21WP-99ZW-5aOE-bINc-fgYF-qP50vw
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                5.94 GB
  Current LE             190
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

  --- Logical volume ---
  LV Name                /dev/vg_root/lv_zenoss_perf
  VG Name                vg_root
  LV UUID                ByUzF7-wYab-R9q5-3h4o-S3AI-L0HH-2Kn07p
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                3.00 GB
  Current LE             96
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

The /dev/sda is showing the total size of 214.7GB. How can I extend the size for each logical volume by 20GB?

Thank you,

  • I'd suggest you add a /dev/sda4 using the remaining space on the disk, then add that to your volume group. That way you don't need to touch the existing partitions. – derobert Dec 2 '16 at 18:35
  • Hi derobert, That's what I just did exactly. I follow this article howtoforge.com/… until the part pvcreate /dev/sda4. The machine returned this message "Device /dev/sda4 not found (or ignored by filtering)." Could you please kindly advise? Thanks. – hoanggeneral Dec 2 '16 at 18:59
  • @derobert hat's what I just did exactly. I follow this article [link] (howtoforge.com/…) until the part pvcreate /dev/sda4. The machine returned this message "Device /dev/sda4 not found (or ignored by filtering)." Could you please kindly advise? Thanks. – hoanggeneral Dec 2 '16 at 19:13
  • Did you create the partition (using fdisk or similar) and then (since the disk is in use) reboot? I'm guessing you didn't reboot, which is unfortunately required when the disk is already in use. – derobert Dec 2 '16 at 19:17
  • @derobert I used the fdisk utility.The restart did solve the issue. Thank you very much. – hoanggeneral Dec 2 '16 at 19:36
1

I used fdisk /dev/sda to create a new partition sda4

[root@localhost ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 26108.
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): 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
Selected partition 4
First cylinder (2611-26108, default 2611): 2611
Last cylinder or +size or +sizeM or +sizeK (2611-26108, default 26108): 26108

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e

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@localhost ~]# fdisk /dev/sda -l

Disk /dev/sda: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          19      152586   83  Linux
/dev/sda2              20         280     2096482+  82  Linux swap / Solaris
/dev/sda3             281        2610    18715725   8e  Linux LVM
/dev/sda4            2611       26108   188747685   83  Linux

Then restart the machine

Then I used the commend pvcreate /dev/sda4 to create the physical volume sda4. Then I extend the vg_root (virtual group) to cover the sda4 by issue the command vgextend vg_root /dev/sda4. Then I used the command lvextend and resize2fs to extend the size for the logical volume(s) as need.

Thank @derobert for help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.