1

We disabled older swap space (disk) that already mounted in /dev/mapper/centos-swap to increase size of the root(/). Then we create new swap file in /dev/sda3:

# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   60G  0 disk 
├─sda1            8:1    0  500M  0 part /boot
├─sda2            8:2    0 19.5G  0 part 
│ └─centos-root 253:0    0 19.5G  0 lvm  /
└─sda3            8:3    0    8G  0 part [SWAP]
sr0              11:0    1 1024M  0 rom  

And now system loaded swap space successfully:

# free -h
              total        used        free      shared  buff/cache   available
Mem:           7.6G        1.2G        5.6G         11M        863M        6.2G
Swap:          8.0G          0B        8.0G

But when we reboot the system, OS reports an error that cannot find centos-swap file:

...    
+ cat /proc/cmdline
Kernel command line: BOOT_IMAGE=/vmlinuz-3.10.0-229.14.1.el7.x86_64 root=/dev/mapper/centos-root ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap crashkernel=auto rhgb quiet LANG=en_US.UTF-8
...
[  131.037146] ***** dracut-initqueue[278]: Failed to find logical volume "centos/swap"
[  192.680201] ***** dracut-initqueue[278]: Warning: Could not boot.
[  192.683555] ***** dracut-initqueue[278]: Warning: /dev/centos/swap does not exist
[  192.694602] ***** systemd[1]: Starting Dracut Emergency Shell...
...

Then OS runs as emergency mode and OS waits unitl we type exit from Dracut Emergency Shell.

How can I set swap space without any problem in booting?

1
  • swaps should not be put in LVM as that would decrease performance. And if you don't have an SSD it'll be better to use zram
    – phuclv
    Commented May 19, 2018 at 7:53

1 Answer 1

0

Solution:

In default installation of CentOS 7 swap, root and boot partitions created in the sda. When we disabled swap using swapoff default parameters in boot that already created in /proc/cmdline could not updated.

We install grub-customizer (or any other grub editor) and remove pre-defined swap rules. For example:

BOOT_IMAGE=/vmlinuz-3.10.0-229.14.1.el7.x86_64 root=/dev/mapper/centos-root ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap crashkernel=auto rhgb quiet LANG=en_US.UTF-8

changed to:

BOOT_IMAGE=/vmlinuz-3.10.0-229.14.1.el7.x86_64 root=/dev/mapper/centos-root ro rd.lvm.lv=centos/root crashkernel=auto rhgb quiet LANG=en_US.UTF-8

Now swap is enabled and error in boot not appears.

1
  • Better option is to properly update '/etc/fstab' and rebuild initramfs with 'dracut' Commented May 5, 2020 at 20:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .