0

I'm running a CentOS 7 guest on a VirtualBox 6 on Windows. The result of the free command is as follows:

$ free -h
              total        used        free      shared  buff/cache   available
Mem:            15G        2.4G         11G        162M        1.5G         12G
Swap:          1.2G          0B        1.2G

showing that the swap partition has 1.2 GB. I need to extend it to at least 2GB. So, with the guest stopped, I added a new volume of 1.2 GB and, after having rebooted, I did as follows:

$ sudo pvcreate /dev/sdb
$ sudo vgextend centos /dev/sdb
$ sudo lvextend -L+1G /dev/centos/swap

Now, the lvdisplay command shows the new created volume, as follows:

$ sudo lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                1OT4R8-69eL-vczL-zydM-XrwS-jA47-YfikMS
  LV Write Access        read/write
  LV Creation host, time localhost, 2019-12-30 22:01:35 +0100
  LV Status              available
  # open                 2
  LV Size                <2.20 GiB
  Current LE             563
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                hGDGPf-iPMB-TUtM-nqRv-aDNd-D3mw-W15H8Z
  LV Write Access        read/write
  LV Creation host, time localhost, 2019-12-30 22:01:35 +0100
  LV Status              available
  # open                 1
  LV Size                <76.43 GiB
  Current LE             19565
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

The fstab file looks as follows:

dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=4ef0416f-1617-40da-99d2-83896d808eed /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0

showing that the swap is allocated on the /dev/mapper/centos-swap partition. Here is the out put of the fstab command:

Disk /dev/mapper/centos-root: 82.1 GB, 82061557760 bytes, 160276480 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 /dev/mapper/centos-swap: 2361 MB, 2361393152 bytes, 4612096 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

But after reboot the swapon command doesn't seem to reflect the extension:

$ sudo swapon -s
Filename                                Type            Size    Used    Priority
/dev/dm-1                               partition       1257468 0       -2

For some reason, the swap doesn't seem to be on the /dev/mapper/centos-swap partition but on /dev/dm-1, which doesn't even exist. And the free command still shows the same result like in the beggining:

$ free -h
              total        used        free      shared  buff/cache   available
Mem:            15G        2.4G         11G        155M        1.5G         12G
Swap:          1.2G          0B        1.2G

and the /proc/swaps:

$ cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/dm-1                               partition       1257468 0       -2

What am I missing here ?

Seymour

Seymour Glass
  • 81
  • 2
  • 15

1 Answers1

0

I'm answering my own question. The issue is simply solved by running the following command:

sudo mkswap /dev/mapper/centos-swap

After that, the free command shows the new increased swap space and the /proc/swaps file also reflect that.

I found the solution by chance, while surfing for another topic. It seems that, as a matter of fact, after having created the physical volume and after having extended the virtual group and the logical volume, it's not enough to declare the new swap with swapon command, but it also requires to effectively "make" the swap using the mkswap command.

Don't ask me why, this is the way it works :-).

Seymour Glass
  • 81
  • 2
  • 15