2

I have a question regarding managing free or "unallocated" space in an LVM setup on CentOS.

What i need to do is make /var bigger, to accommodate some additional VM's that i am creating.

  1. I would need to claim some of that free space << this is where I need the help
  2. create the physical volume using pvcreate
  3. extend the volume group using vgextend
  4. extend the logical volume using lvextend
  5. then grow the filesystem using xfs_grow

I have a 1TB disk in my server. Of that 1TB disk, there is 721GB of unallocated space (see image attached)

These are the filesystems on the server:

Filesystem                            Size  Used Avail Use% Mounted on
/dev/mapper/scientific_physical-root   71G   17G   54G  25% /
devtmpfs                              9.7G     0  9.7G   0% /dev
tmpfs                                 9.8G  576K  9.8G   1% /dev/shm
tmpfs                                 9.8G  9.4M  9.8G   1% /run
tmpfs                                 9.8G     0  9.8G   0% /sys/fs/cgroup
/dev/mapper/scientific_physical-home  121G   12G  110G  10% /home
/dev/mapper/scientific_physical-var    63G   51G   13G  80% /var
/dev/sda1                             497M  215M  282M  44% /boot
tmpfs                                 2.0G   20K  2.0G   1% /run/user/1000
tmpfs                                 2.0G   24K  2.0G   1% /run/user/0

These are the LV's on the system:

  LV   VG                  Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home scientific_physical -wi-ao---- 120.66g                                                    
  root scientific_physical -wi-ao----  70.30g                                                    
  swap scientific_physical -wi-ao----   2.93g                                                    
  var  scientific_physical -wi-ao----  63.00g 

These are the physical volumes:

  PV         VG                  Fmt  Attr PSize   PFree
  /dev/sda2  scientific_physical lvm2 a--  213.41g    0 
  /dev/sda3  scientific_physical lvm2 a--   46.56g 3.09g

This is my volume group:

  VG                  #PV #LV #SN Attr   VSize   VFree
  scientific_physical   2   4   0 wz--n- 259.98g 3.09g

[root@physical ~]# fdisk -l /dev/sda

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes, 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0004cb56

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048   448595967   223784960   8e  Linux LVM
/dev/sda3       448598016   546254265    48828125   83  Linux

Image of Disk Utility

Edit #1:

here is the output from fdisk /dev/sda. I don't have a complete understanding of the Start /End /Blocks, but being that as it is, I still don't see the free space that should be available

[root@physical ~]# fdisk /dev/sda 
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes, 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0004cb56

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048   448595967   223784960   8e  Linux LVM
/dev/sda3       448598016   546254265    48828125   83  Linux

Edit #2

OK so now I can see the space is there in parted! Wonderful and thank you!! Now my question is, what would I have to do to actually grab some of this space to use it? I am assuming whatever I grab, in my exact scenario would now be called /dev/sda4. Would you be able to guide me on claiming 100GB from this free space?

Thanks so much!

[root@physical ~]# parted /dev/sda
(parted) print free                                                       
Model: ATA ST31000340NS (scsi)
Disk /dev/sda: 1000GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  525MB   524MB   primary  xfs          boot
 2      525MB   230GB   229GB   primary               lvm
        230GB   230GB   1049kB           Free Space
 3      230GB   280GB   50.0GB  primary
        280GB   1000GB  721GB            Free Space
0

There are a couple of ways to do this. You could resize partition 3, the run pvresize on /dev/sda3. The extend /dev/scientific_physical/var with lvresize with the -r option. That would grow the lvol and resize the fs all in one command. You could also create another partition. Then pvcreate /dev/sda4, vgextend scientific_physical with the new partition, then lvresize.

You could also see if there are actually any extents used on /dev/sda3. If not, do a vgreduce, then resize sda2, pvresize, lvresize. To do that you will need to reboot after the resize of sda2. A partprobe will complain that the disk is in use.

  • thank you for your answer. Could you possible tell me how I can see the free unallocated space though? if I log in through gnome, and run disks, I can see the free space as mentioned above. However, i cannot see this free space via CLI anywhere. It's as if it doesn't exist, or is lost space, until i verify via GUI. But I am practicing this on my setup lab, as the servers at work do not have GUI. – Jay Jay Mar 10 '17 at 2:46
  • You can see the free space with a partitioning tool, such as fdisk. For example, you can run fdisk /dev/sda then press "p" to print the partition table. I believe it's "q" to exit, and "m" for the help screen. Don't press "w"! – Emmanuel Rosa Mar 10 '17 at 4:10
  • View the disk with parted. ex. sudo parted /dev/sda, Then type 'print free' – feeble Mar 10 '17 at 12:54
  • Thanks for your help. Please see output in edit #2 above. OK so now I can see the space is there in parted! Wonderful and thank you!! Now my question is, what would I have to do to actually grab some of this space to use it? I am assuming whatever I grab, in my exact scenario would now be called /dev/sda4. Would you be able to guide me on claiming 100GB from this free space? – Jay Jay Mar 11 '17 at 1:00
  • Here's one way. Run fdisk /dev/sda Then type "c" to create a partition. Then choose primary partition 4. The type can be 83 and simply accept the suggested start and end offsets. Than will create sda4 with the remaining space. Then type "w" to save your changes to the partition table and "q" to quit. – Emmanuel Rosa Mar 11 '17 at 14:13

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.