Increasing CentOS 7 partition issue

General support questions
Post Reply
raduoctavian
Posts: 5
Joined: 2021/04/13 08:38:35

Increasing CentOS 7 partition issue

Post by raduoctavian » 2021/04/13 09:00:40

Hello everyone,

I'm having trouble when trying to resize (increase) my CentOS partition. I have read many other topics and open topics on this matter but I'm afraid my situation may be a bit peculiar thus I did not manage to solve this on my own.

As an overview: I have a single SSD that is being shared by a Win10 and a CentOS 7. Win10 was created first. I then realized that I need more space for my CentOS however I cannot seem to be able to increase my partition. Some info below:

[raduoctavian@localhost ~]$ df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs tmpfs 3.8G 570M 3.2G 15% /dev/shm
tmpfs tmpfs 3.8G 10M 3.8G 1% /run
tmpfs tmpfs 3.8G 0 3.8G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 43G 29G 15G 67% /
/dev/sda5 xfs 1014M 227M 788M 23% /boot
/dev/sda1 vfat 96M 37M 60M 39% /boot/efi
tmpfs tmpfs 768M 52K 768M 1% /run/user/1000
[raduoctavian@localhost ~]$ sudo fdisk -l /dev/sda
[sudo] password for raduoctavian:
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/sda: 512.1 GB, 512110190592 bytes, 1000215216 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: gpt
Disk identifier: F6251BB0-D9A6-46E3-A819-51E316BF7270


# Start End Size Type Name
1 2048 206847 100M EFI System EFI System Partition
2 206848 239615 16M Microsoft reser Microsoft reserved partition
3 239616 841493207 401.1G Microsoft basic Basic data partition
4 841494528 896788479 26.4G Linux LVM Basic data partition
5 896790528 898887679 1G Microsoft basic
6 898887680 999190527 47.8G Linux LVM
7 999190528 1000212479 499M Windows recover


So what I would want is to add #4 (26.4 GB) to my CentOS.

I suspect that due to the fact that both W10 and CentOS create all the secondary necessary partitions I am now having issues using this space. I'm adding a screenshot from gparted as well as it explains the situation better.

Thank you!
Radu
Attachments
Screenshot from 2021-04-13 11-59-56.png
Screenshot from 2021-04-13 11-59-56.png (77.78 KiB) Viewed 1021 times

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

Re: Increasing CentOS 7 partition issue

Post by TrevorH » 2021/04/13 10:03:10

What is the output from file -s /dev/sda4 ?

It may be as simple as using [/tt]pvcreate /dev/sda4[/tt] to turn that partition into an LVM PV and then using the vgextend command to add that new PV to the existing Volume Group and, once that's done, use lvresize -r on the filesystem you want to resize. Read the man pages for each of those commands before you start so you know what they do and what extra parameters you need to add to them to make them work.
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

raduoctavian
Posts: 5
Joined: 2021/04/13 08:38:35

Re: Increasing CentOS 7 partition issue

Post by raduoctavian » 2021/04/13 10:32:20

Hello Trevor,

Thanks for looking into this!
TrevorH wrote:
2021/04/13 10:03:10
What is the output from file -s /dev/sda4 ?

[raduoctavian@localhost ~]$ sudo file -s /dev/sda4
/dev/sda4: LVM2 PV (Linux Logical Volume Manager), UUID: QHgVcV-Cpc2-sg0j-JADi-U5fW-J4cR-EqjiKn, size: 28310503424


It may be as simple as using [/tt]pvcreate /dev/sda4[/tt] to turn that partition into an LVM PV and then using the vgextend command to add that new PV to the existing Volume Group and, once that's done, use lvresize -r on the filesystem you want to resize. Read the man pages for each of those commands before you start so you know what they do and what extra parameters you need to add to them to make them work.
[root@localhost ~]# pvcreate /dev/sda4
Physical volume "/dev/sda4" successfully created.

Is it safe to proceed with the remaining steps you've mentioned?

Cheers!
Radu

raduoctavian
Posts: 5
Joined: 2021/04/13 08:38:35

Re: Increasing CentOS 7 partition issue

Post by raduoctavian » 2021/04/13 12:35:48

TrevorH wrote:
2021/04/13 10:03:10
What is the output from file -s /dev/sda4 ?

It may be as simple as using [/tt]pvcreate /dev/sda4[/tt] to turn that partition into an LVM PV and then using the vgextend command to add that new PV to the existing Volume Group and, once that's done, use lvresize -r on the filesystem you want to resize. Read the man pages for each of those commands before you start so you know what they do and what extra parameters you need to add to them to make them work.
Hi again Trevor!

Ok so I definitely did something but I have little experience with LVM so please let me know how I did:

[raduoctavian@localhost ~]$ sudo file -s /dev/sda4
[sudo] password for raduoctavian:
/dev/sda4: LVM2 PV (Linux Logical Volume Manager), UUID: QHgVcV-Cpc2-sg0j-JADi-U5fW-J4cR-EqjiKn, size: 28310503424
[root@localhost ~]# pvcreate /dev/sda4
Physical volume "/dev/sda4" successfully created.
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 47.82 GiB
PE Size 4.00 MiB
Total PE 12243
Alloc PE / Size 12242 / 47.82 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID QYC0Xe-8ZTL-kMQJ-OsET-BN7C-mUkp-S0aD1j


[root@localhost ~]# vgextend centos /dev/sda4
Volume group "centos" successfully extended
[root@localhost ~]# lvresize -L +26.37G /dev/centos/root
Rounding size to boundary between physical extents: 26.37 GiB.
Insufficient free space: 6751 extents needed, but only 6750 available
[root@localhost ~]# lvresize -L +26.36G /dev/centos/root
Rounding size to boundary between physical extents: 26.36 GiB.
Size of logical volume centos/root changed from <42.94 GiB (10992 extents) to 69.30 GiB (17741 extents).
Logical volume centos/root successfully resized.


[root@localhost ~]# resize2fs /dev/centos/root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/centos/root
Couldn't find valid filesystem superblock.

[root@localhost ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=2813952 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=11255808, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=5496, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 11255808 to 18166784

[root@localhost ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs tmpfs 3.8G 416M 3.4G 11% /dev/shm
tmpfs tmpfs 3.8G 10M 3.8G 1% /run
tmpfs tmpfs 3.8G 0 3.8G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 70G 30G 41G 43% /
/dev/sda5 xfs 1014M 227M 788M 23% /boot
/dev/sda1 vfat 96M 37M 60M 39% /boot/efi
tmpfs tmpfs 768M 36K 768M 1% /run/user/1000

So I see the new size is increased. Is that ok as it is?

I'm asking because I see in gparted (or fdisk) that there are still two separate entities sda4 and sda6. I guess I was expecting the two of them to merge into 1.

Again I have little experience manipulating LVM so please bear with me with the silly questions.

Thanks again!
Radu

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

Re: Increasing CentOS 7 partition issue

Post by TrevorH » 2021/04/13 12:39:17

All looks good to me. You can't merge them since /dev/sda5 is sitting between the two partitions. The best you can do is to use a 2nd partition as a 2nd PV and use that as part of the same VG. In an ideal world you'd move everything around to consolidate the space into one lump but sometimes it's just too difficult or impossible to do without starting over.
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

raduoctavian
Posts: 5
Joined: 2021/04/13 08:38:35

Re: Increasing CentOS 7 partition issue

Post by raduoctavian » 2021/04/13 12:46:41

TrevorH wrote:
2021/04/13 12:39:17
All looks good to me. You can't merge them since /dev/sda5 is sitting between the two partitions. The best you can do is to use a 2nd partition as a 2nd PV and use that as part of the same VG. In an ideal world you'd move everything around to consolidate the space into one lump but sometimes it's just too difficult or impossible to do without starting over.
Indeed it sounds a bit too complicated (for now) as I'd need to look over many of the LVM concepts I've forgotten - not using them for quite some time. I'd probably manage somehow to ruin the CentOS partitions or both CentOS and W10 and that wouldn't be fun :)

For now it's great that CentOS has an increased size it can use - I wanted to virtualize other OS hence I needed more space than anticipated.

Once again Trevor I thank you very much for your time and help on this. I really appreciate it.

Cheers!
Radu

User avatar
jlehtone
Posts: 4523
Joined: 2007/12/11 08:17:33
Location: Finland

Re: Increasing CentOS 7 partition issue

Post by jlehtone » 2021/04/14 08:23:24

LVM is an abstraction layer. A mapping between logical sectors presented to OS and (more) physical locations (LVM extents) on storage medias.

Analogously:
If you take an SSD, it has physical sectors and shows logical block address (LBA) sectors. It can and will remap LBAs over its lifetime for wear-leveling. A HDD will remap (reallocate) LBA to reserve physical sector, if write to original physical sector fails. OS sees continuous LBAs no matter how the mapping changes.

RAID presents a volume (continuous sector addresses) even though the sectors might be (striped) on different physical disks. The RAID maps logical sector to physical sector.

You can have multiple levels of mappings:
Some filesystems allow fragmentation of file data. An apparently continuous file is on discontinuous filesystem blocks (filesystem maps) that might be on different LVM extents (LVM maps) on different physical disks (RAID maps) and within discontinuous physical sectors (disk maps) within those disks.


LVM adds flexibility. You can change its mappings on live system. You can span LV over multiple disks. You can move LV from one physical volume to another "online".

Note: the lvresize has option -r (--resizefs). It would call appropriate filesystem resize command for you.

There is no way to shrink XFS, except remove and create a smaller.


The default virtualization platform on CentOS 7 is libvirt/KVM. It does, by default, store the images of guest filesystems as files under /var. However, you can also use LV's as the images; the images don't have to use space in /var. Alas, you did allocate your VG already, so you can't test that option.

raduoctavian
Posts: 5
Joined: 2021/04/13 08:38:35

Re: Increasing CentOS 7 partition issue

Post by raduoctavian » 2021/04/14 08:56:39

jlehtone wrote:
2021/04/14 08:23:24
LVM is an abstraction layer. A mapping between logical sectors presented to OS and (more) physical locations (LVM extents) on storage medias.

Analogously:
If you take an SSD, it has physical sectors and shows logical block address (LBA) sectors. It can and will remap LBAs over its lifetime for wear-leveling. A HDD will remap (reallocate) LBA to reserve physical sector, if write to original physical sector fails. OS sees continuous LBAs no matter how the mapping changes.

RAID presents a volume (continuous sector addresses) even though the sectors might be (striped) on different physical disks. The RAID maps logical sector to physical sector.

You can have multiple levels of mappings:
Some filesystems allow fragmentation of file data. An apparently continuous file is on discontinuous filesystem blocks (filesystem maps) that might be on different LVM extents (LVM maps) on different physical disks (RAID maps) and within discontinuous physical sectors (disk maps) within those disks.


LVM adds flexibility. You can change its mappings on live system. You can span LV over multiple disks. You can move LV from one physical volume to another "online".

Note: the lvresize has option -r (--resizefs). It would call appropriate filesystem resize command for you.

There is no way to shrink XFS, except remove and create a smaller.


The default virtualization platform on CentOS 7 is libvirt/KVM. It does, by default, store the images of guest filesystems as files under /var. However, you can also use LV's as the images; the images don't have to use space in /var. Alas, you did allocate your VG already, so you can't test that option.
Hello and thank you, jlehtone!

Many of these concepts were (or still are) unfamiliar to me but it is great to learn about. As it happens with pretty much everything else the best way to get one's head around it is to face it, break it, and, consequently, learn from it.

I'll definitely use this in the future. For now, however, indeed the issue is solved and I thank you for the help.

Cheers!
Radu

Post Reply