📜 ⬆️ ⬇️

Hibernation on PROXMOX2

What is it for


Hibernation (sleep mode) is a system shutdown mode in which its current state, including the state of RAM, is saved to non-volatile storage.

This mode, when used in conjunction with Proxmox, significantly speeds up the main shutdown process — the host system without having to shut down the guest virtual systems. It is especially convenient when terminal servers on Windows are deployed as a guest system. After all, if the system is normally shut down, a request to save the edited document appears in users' windows, and if the user also turns off the light along with his computer and monitor, the user is not present, the forced termination of the system will cause the pre-infarction state to lose the data edited by the employee. This is where the hibernation of the host nodes will save and after the restoration of power supply, users can continue to work from the same place!
Of course, something like this would have to be configured by the UPS server. Switching to hibernation mode is convenient to designate as an event when the UPS battery is discharged, and thanks to the speed of transition to this mode, you can seriously reduce the requirements for the capacity of its batteries.

How it works


Proxmox 2.2 runs on debian 6 and almost everything described below applies to it to one degree or another.

Activating the hibernation mode requires a dedicated disk that will be visible to GRUB directly when booting or a separate swap partition on the system disk. With the swap logical volume created automatically when installed inside LVM, I could not start the hibernation. At the same time, proxmox does not allow creating the necessary disk structure for this mode during the installation process. This is probably due to the concept of maximum ease of deploying a system that even a housewife can handle.
')
The simplest solution is to simply add another hard disk to the server and assign it as storage for the hibernation mode, but we will consider a more complex option with finding free space on the same disk where proxmox was delivered.

Initial data


When installing, proxmox fully utilizes 1 of the disks destroying all the information on it and creating a certain partition structure:

# parted /dev/sda print free Model: ATA WDC WD3200AAKS-7 (scsi) Disk /dev/sda: 320GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 32.3kB 1049kB 1016kB Free Space 1 1049kB 537MB 536MB primary ext3 boot 2 537MB 320GB 320GB primary lvm 320GB 320GB 352kB Free Space 


Thus, we learned that the physical disk space not occupied by partitions is only 352kB, which is clearly not enough for the swap partition to which the system will keep the state of the occupied RAM when hibernating. Such a partition must have a size not less than the size of the RAM node.

We assume that the size we need is 32 GB.

Now let's see what logical volumes our physical volume is located in the second section.
  # lvs 

see
  LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert data pve -wi-ao-- 203.09g root pve -wi-ao-- 74.50g swap pve -wi-ao-- 4.00g 


Carrier preparation


Let us find out how much free space is already inside the physical volume LVM2.
 # pvs 

We look at the value of PFree
  PV VG Fmt Attr PSize PFree /dev/sda2 pve lvm2 a-- 297.59g 16.00g 

This means that we can immediately reduce the partition on the physical disk by 16.00 GB, but our task is to get 32 ​​GB, so we will look for additional data.
We will select the space we need from the data logical volume. To do this, we will reduce the size of / dev / pve / data to 16 GB.
This process is carried out in 2 stages. First, the file system size is reduced, and then the size of the logical volume itself is reduced. Since the procedure is potentially not secure, the unmounting of the file system will be performed for the period of resizing, respectively, all virtual machines located in / var / lib / vz should be stopped for this time.
 # lvresize /dev/pve/data -r -L-16Gb Do you want to unmount "/var/lib/vz"? [Y|n] 

Answer y

Now re-run
  # pvs PV VG Fmt Attr PSize PFree /dev/sda2 pve lvm2 a-- 297.59g 32.00g 

We see that the amount of free space inside the physical volume has increased to 32 GB.

Now we can safely reduce its size to the size of the available free space + 1 GB for safety:

Calculate the total size of the physical volume 297-32 + 1 = 266
 # pvresize /dev/sda2 --setphysicalvolumesize 266Gb 

Again, let's see what we have
  # pvs PV VG Fmt Attr PSize PFree /dev/sda2 pve lvm2 a-- 266.00g 412.00m 

The size of the LVM physical volume has decreased by:
297.59 - 266 + 0.412 = 32.002 GB
But despite this, the size of the partition containing the LVM structure on the hard disk remained unchanged:
  # parted /dev/sda print free Number Start End Size Type File system Flags 32.3kB 1049kB 1016kB Free Space 1 1049kB 537MB 536MB primary ext3 boot 2 537MB 320GB 320GB primary lvm 320GB 320GB 352kB Free Space 

This does not suit us, since it is necessary to get free space for a new partition in the partition table of the physical disk.

At the moment, it was not possible to detect ready-made utilities capable of changing partitions containing the lvm2 structure, so we simply delete and re-create the partition on the hard disk with the beginning as the original one, but smaller. This is a potentially rather dangerous procedure.

Calculate the parameters of the 2nd section, which we want to get as a result. It should be less than the current 32 GB
320 - 32 = 288 GB
Thus, the 2nd section will have parameters:

Type primary
Start 537MB
End 288Gb

Remove section 2 by ignoring warnings.
 # parted /dev/sda rm 2 

Create a partition that is smaller but smaller than it was
 # parted /dev/sda mkpart primary 537MB 288GB 

Assign the lvm flag to the section
 # parted /dev/sda set 2 lvm on 

See the result
 # parted /dev/sda print free 

We see that the physical disk has free space for the future partition.
  Number Start End Size Type File system Flags 32.3kB 1049kB 1016kB Free Space 1 1049kB 537MB 536MB primary ext3 boot 2 537MB 288GB 287GB primary lvm 288GB 320GB 32.1GB Free Space 


Create a section of type swap. Its parameters are:

Type primary
fs linux-swap
Begin 288GB
End 320GB

Perform:
 # parted /dev/sda mkpart primary linux-swap 288GB 320GB # mkswap /dev/sda3 


The preparatory work is finished and now you can proceed directly to the setup of hibernation

Hibernate activation


Component installation
 # apt-get update # apt-get install pm-utils 

Adding parameters to grub and fstab
 # echo 'GRUB_CMDLINE_LINUX_DEFAULT="resume=/dev/sda3"' >> /etc/default/grub # echo '/dev/sda3 none swap sw 0 0' >> /etc/fstab 

We connect the new partition as a paging file to the system
 # swapon /dev/sda3 

Update the bootloader
 # update-grub 

You can start testing directly the hibernation mode. But before that, it is highly advisable to reboot the server, if there is such an opportunity, as there have been quite serious changes in the structure of the media!
 # reboot 

Perform full hibernation with system power off
 # pm-hibernate 


Now it remains to assign the execution of this command at the event of a battery discharge on the UPS, but this is another story that I hope will describe in the next article.

All of the above is tested on freshly installed proxmox 2.2

Source: https://habr.com/ru/post/159113/


All Articles