Expending lvm to take up whole device space

General support questions
Post Reply
xkxtnt
Posts: 4
Joined: 2017/12/15 20:46:16

Expending lvm to take up whole device space

Post by xkxtnt » 2017/12/15 20:55:01

Hi,
I installed CentOS on VMWare and later decided to increase the size of one of the virtual disk. But I am not sure how to expanding the existing partition/volume to take up the additional space.

Code: Select all

[root@centos ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0               2:0    1    4K  0 disk
sda               8:0    0   50G  0 disk
├─sda1            8:1    0  500M  0 part /boot
├─sda2            8:2    0    5G  0 part [SWAP]
└─sda3            8:3    0 44.5G  0 part
  └─centos-root 253:0    0 44.5G  0 lvm  /
sdb               8:16   0  500G  0 disk
└─sdb1            8:17   0  100G  0 part
  └─vg1-data    253:1    0  100G  0 lvm  /localdata
sdc               8:32   0   64G  0 disk
sr0              11:0    1 1024M  0 rom
So I want to expand the /localdata lvm to take up the entire 500G in sdb.

I believe the sdb is set up using GPT. I had googled on this top quite a bit and most thing I found would apply to MBR only.

Code: Select all

[root@centos ~]# fdisk /dev/sdb -l
Disk /dev/sdb: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1   209715199   104857599+  ee  GPT

Thanks in advance for any advices!

xkxTnT

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Expending lvm to take up whole device space

Post by TrevorH » 2017/12/15 21:07:17

The safe way to do this is to create a new partition, tag it as type 0x8e (LVM) and save and reboot to pick up the change. Now you can pvcreate the new partition and add it to the existing vg1_data volume group and then lvextend the LV using the -r switch to resize the fileystem at the same time. Done.

The risky way is to delete the existing partition and redefine it on the exact same starting sector number with a new ending sector number. Save and reboot again and then pvresize /dev/sdb1.

However I'm a bit concerned over your fdisk output which shows conflicting information - first it says it has "Disk label type: dos" which is not GPT but then the partition type says it is. To be safe I'd check with parted and possibly also with gdisk (from EPEL) which understands GPT better than fdisk.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

xkxtnt
Posts: 4
Joined: 2017/12/15 20:46:16

Re: Expending lvm to take up whole device space

Post by xkxtnt » 2017/12/15 22:08:32

You are right about the fdisk output that shows conflicting information - exact reason why I was hesitant to following some instruction online to do it.

I got some warning when I used parted to print the partition info for /dev/sdb. The warning says "The backup GPT table is not at the end of the disk, as it should be. This might mean that another operating system believes the disk is smaller. Fix, by moving the backup to the end (and removing the old backup)? Fix/Ignore/Cancel?"
The partition won't get recognize if I cancel, see the output below

Code: Select all

[root@brainspace ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Error: The backup GPT table is not at the end of the disk, as it should be.  This might
mean that another operating system believes the disk is smaller.  Fix, by moving the
backup to the end (and removing the old backup)?
Fix/Ignore/Cancel? C
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 537GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
But if I ignore it, it will identify the partition as gpt.

Code: Select all

[root@brainspace ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Error: The backup GPT table is not at the end of the disk, as it should be.  This might
mean that another operating system believes the disk is smaller.  Fix, by moving the
backup to the end (and removing the old backup)?
Fix/Ignore/Cancel? I
Warning: Not all of the space available to /dev/sdb appears to be used, you can fix the
GPT to use all of the space (an extra 838860800 blocks) or continue with the current
setting?
Fix/Ignore? I
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 537GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End    Size   File system  Name     Flags
 1      1049kB  107GB  107GB               primary  lvm
Wondering if I can just have parted fix it automatically?

I should also have pointed out that there is currently no data in /localdata, so if it is easier delete the whole partition sdb1 (and vg1-data) and start over, I'd be happy to do that. Just need some hand holding on that too since I am fairly naive to CentOS.

Thanks,
xkxTnT

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Expending lvm to take up whole device space

Post by TrevorH » 2017/12/15 22:54:48

Oh, if there's no data on it then start over, much easier. Off the top of my head you'd want

lvchange -an /dev/mapper/vg1-data
lvremove /dev/mapper/vg1-data
vgremove vg1
pvremove /dev/sdb1

then use your favourite partitioning tool to delete what's there now, fix any problems and rewrite it all as one big partition - /dev/sdb1. That may want a reboot but probably won't as the device should have been made inactive by the previous commands. Then

pvcreate /dev/sdb1
vgcreate vg1 /dev/sdb1
lvcreate -n data -l 100%FREE vg1

Then create a filesystem on it with mkfs, pick ext4 or xfs, whichever you prefer.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

xkxtnt
Posts: 4
Joined: 2017/12/15 20:46:16

Re: Expending lvm to take up whole device space

Post by xkxtnt » 2017/12/16 01:26:42

Hi Trevor,
Just want to thank again for all your help! It is making the process a lot easy! I followed the instruction, but not sure if I get to where I need to go.

lvchange -an /dev/mapper/vg1-data
-------- Did that. I have to comment out line in /etc/fstab first, and then unmount /localdata
lvremove /dev/mapper/vg1-data
-------- Did that.
vgremove vg1
-------- Did that.
pvremove /dev/sdb1
-------- Did that.

then use your favourite partitioning tool to delete what's there now, fix any problems and rewrite it all as one big partition - /dev/sdb1. That may want a reboot but probably won't as the device should have been made inactive by the previous commands. Then
------- Did that. I used parted to delete the partition, and create one big partition with this

Code: Select all

mkart primary xfs 0GB 537GB
------- Now this is what it looks like

Code: Select all

[root@ch-rel-bap-p01 ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 537GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End    Size   File system  Name     Flags
 1      1049kB  537GB  537GB               primary
pvcreate /dev/sdb1
---- did that.
vgcreate vg1 /dev/sdb1
--- did that
lvcreate -n data -l 100%FREE vg1
--- did that

You said the next step is to create a filesystem on it with mkfs. but the file system seems to have been created already when I run lsblk -f

Code: Select all

[root@ch-rel-bap-p01 localdata]# lsblk -f
NAME            FSTYPE      LABEL UUID                                   MOUNTPOINT
fd0
sda
├─sda1          xfs               6c0b9289-06c6-408e-896e-bbe99c746967   /boot
├─sda2          swap              9c698bbd-692f-4837-a9b6-7b2f76e8f7d6   [SWAP]
└─sda3          LVM2_member       GnytsI-WhF3-i0Y7-oV69-YclU-wYmd-UFCF0V
  └─centos-root xfs               148ed65f-7910-4e70-a0ef-8ae46245f1c0   /
sdb
└─sdb1          LVM2_member       UvYPOK-j86v-iaJZ-wJgJ-FYsY-XjZN-2E9dSS
  └─vg1-data    xfs               aa5cdf0e-ca89-451a-827c-7d819173d15d
sdc
sr0
Do I still need to create the filesystem with mkfs. I got an warning when I tried. Not sure when the file system was created, maybe with "mkart primary xfs 0GB 537GB?"

Code: Select all

[root@ch-rel-bap-p01 localdata]# mkfs -t xfs /dev/vg1/data
mkfs.xfs: /dev/vg1/data appears to contain an existing filesystem (xfs).
mkfs.xfs: Use the -f option to force overwrite.
Now I just needed to mount /localdata to /dev/mapper/vg1-data, can I just uncomment this line in /etc/fstab?

Code: Select all

/dev/mapper/vg1-data   /localdata               xfs     defaults 0 0
I tried that, but then it shows 100GB only, not the 500 GB. I must be missing something there. Do I have to run mount?

Code: Select all

[root@ch-rel-bap-p01 ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0               2:0    1    4K  0 disk
sda               8:0    0   50G  0 disk
├─sda1            8:1    0  500M  0 part /boot
├─sda2            8:2    0    5G  0 part [SWAP]
└─sda3            8:3    0 44.5G  0 part
  └─centos-root 253:0    0 44.5G  0 lvm  /
sdb               8:16   0  500G  0 disk
└─sdb1            8:17   0  500G  0 part
  └─vg1-data    253:1    0  500G  0 lvm  /localdata
sdc               8:32   0   64G  0 disk
sr0              11:0    1 1024M  0 rom
[root@ch-rel-bap-p01 ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        45G  1.4G   44G   3% /
devtmpfs                devtmpfs   16G     0   16G   0% /dev
tmpfs                   tmpfs      16G     0   16G   0% /dev/shm
tmpfs                   tmpfs      16G  8.5M   16G   1% /run
tmpfs                   tmpfs      16G     0   16G   0% /sys/fs/cgroup
/dev/mapper/vg1-data    xfs       100G   33M  100G   1% /localdata
/dev/sda1               xfs       497M  260M  238M  53% /boot
tmpfs                   tmpfs     3.2G     0  3.2G   0% /run/user/0

I think I am almost there... Thanks again Trevor!

xkxTnT

xkxtnt
Posts: 4
Joined: 2017/12/15 20:46:16

Re: Expending lvm to take up whole device space

Post by xkxtnt » 2017/12/17 05:54:48

I was able to get what I needed with

Code: Select all

xfs_growfs /dev/mapper/vg1-data
Thanks Trevor for all your help!

Post Reply