Mount point changes and Non-standard SWAP disk creation on Linux VMs in Azure

@20aman    Feb 05, 2022

When you try to modify the SWAP disk or work with the temporary disk and want to change the mount point and related configurations. For example, you may want to change the default mount point of "/mnt" to "/mnt/resources". The issue we have seen is that the changes work but only till you restart. Once you restart the VM then the configurations are reverted and the issue still persists. You always want to restart the VM to verify that the configurations stay as per your requirements after the reboot.

When searching online the official documentation takes you here: Swap file is not re-created after a Linux VM restarts. Make sure you have reviewed that and have tried the steps in that link.

General Relevant Linux Commands

Below commands are very helpful when troubleshooting this type of issues to check various configurations:

  1. df -Th - This allows you to check the drives i.e. mapped formatted and partitioned drives. This command displays information about total space and available space on a file system formatted in a table.
  2. free -h - This command allows you to check the memory and swap space. It shows you total, used, shared, cache, and available memory.
  3. swapon -s - This command is used to check the swap status.
  4. cat /etc/fstab - This shows you the content of the fstab in the "/etc" directory. This is the Linux system's filesystem table. This is a configuration table designed to ease the burden of mounting and unmounting file systems to a machine.
  5. fdisk -l - This is for format disk. It is a dialog-driven command in Linux used for creating and manipulating disk partition table. "-l" option is used to list all disk partitions.
  6. lsblk - This command lists information about all available or the specified block devices.

Use these commands to view the current state of your VM disks and to validate the settings.

The working fix

If your issue still persists then try the steps below.

Step 1 - Create the directory where you want to mount the temp (or ephemeral) disk

mkdir /mnt/resource

Step 2 - Create the configuration file for custom ephemeral disk mount in the cloud configuration daemon folder.

touch /etc/cloud/cloud.cfg.d/00-custom-ephemeral-mount.cfg

Step 3 - Update the contents of the file by using the below command.

echo "mounts:
- ["ephemeral0", "/mnt/resource"]" >> /etc/cloud/cloud.cfg.d/00-custom-ephemeral-mount.cfg

Step 4 - Edit the /etc/waagent.conf file and change the mount point over there using "string editing" tool command. Waagent is the Azure Agent configuration file.

sed -i 's/ResourceDisk.Format=n/ResourceDisk.Format=y/g' /etc/waagent.conf

Step 5 - Per the application/database requirements allocate the swap size in /etc/waagent.conf file. Search and update the below line as per your requirements

ResourceDisk.SwapSizeMB=x
#Replace x with your required Swap size in MBs e.g. ResourceDisk.SwapSizeMB= 2048MB

Step 6 - Reboot the server and validate the settings.

This should fix your settings. Let us know if it did or not. Share other tips that helped in your scenario in the comments below.





Comments powered by Disqus