Skip to content

Commit 9d8ff99

Browse files
authored
public repo edit
1 parent 36b42bd commit 9d8ff99

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

articles/virtual-machines/linux/optimization.md

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,38 @@ By default when you create a VM, Azure provides you with an OS disk (**/dev/sda*
4242
## Linux Swap Partition
4343
If your Azure VM is from an Ubuntu or CoreOS image, then you can use CustomData to send a cloud-config to cloud-init. If you [uploaded a custom Linux image](upload-vhd.md?toc=%2fazure%2fvirtual-machines%2flinux%2ftoc.json) that uses cloud-init, you also configure swap partitions using cloud-init.
4444

45-
For all images that are being provisioned and supported by cloud-init, which can all be found [here](https://docs.microsoft.com/en-us/azure/virtual-machines/linux/using-cloud-init). You cannot use the **/etc/waagent.conf** to manage swap.
45+
You can't use the **/etc/waagent.conf** file to manage swap for all images that are provisioned and supported by cloud-init. For the full list of images, see [Using cloud-init](using-cloud-init.md).
4646

47-
The easiest method when using cloud-init is to follow the steps below:
47+
The easiest way to manage swap for these images is to complete these steps:
4848

49-
Create a file called **create_swapfile.sh** under **/var/lib/cloud/scripts/per-boot** folder.
50-
**$ sudo touch /var/lib/cloud/scripts/per-boot/create_swapfile.sh**
49+
1. In the **/var/lib/cloud/scripts/per-boot** folder, create a file called **create_swapfile.sh**:
5150

52-
Add the following lines to the file:
53-
**$ sudo vi /var/lib/cloud/scripts/per-boot/create_swapfile.sh**
51+
**$ sudo touch /var/lib/cloud/scripts/per-boot/create_swapfile.sh**
5452

55-
```
56-
#!/bin/sh
57-
if [ ! -f '/mnt/swapfile' ]; then
58-
fallocate --length 2GiB /mnt/swapfile
59-
chmod 600 /mnt/swapfile
60-
mkswap /mnt/swapfile
61-
swapon /mnt/swapfile
62-
swapon -a ; fi
63-
```
64-
**NOTE**: You can change the value according to your need and also based on the available space in your resource disk which is different based on the VM size being used.
53+
1. Add the following lines to the file:
54+
55+
**$ sudo vi /var/lib/cloud/scripts/per-boot/create_swapfile.sh**
56+
57+
```
58+
#!/bin/sh
59+
if [ ! -f '/mnt/swapfile' ]; then
60+
fallocate --length 2GiB /mnt/swapfile
61+
chmod 600 /mnt/swapfile
62+
mkswap /mnt/swapfile
63+
swapon /mnt/swapfile
64+
swapon -a ; fi
65+
```
66+
67+
> [!NOTE]
68+
> You can change the value according to your need and based on the available space in your resource disk, which varies based on the VM size being used.
69+
70+
1. Make the file executable:
71+
72+
**$ sudo chmod +x /var/lib/cloud/scripts/per-boot/create_swapfile.sh**
6573

66-
Make the file executable by using:
67-
**$ sudo chmod +x /var/lib/cloud/scripts/per-boot/create_swapfile.sh**
74+
1. To create the swapfile, execute the script right after the last step:
6875

69-
You can execute the script right after the last step for the swapfile to be created right away:
70-
**$ sudo /var/lib/cloud/scripts/per-boot/./create_swapfile.sh**
76+
**$ sudo /var/lib/cloud/scripts/per-boot/./create_swapfile.sh**
7177

7278
For images without cloud-init support, VM images deployed from the Azure Marketplace have a VM Linux Agent integrated with the OS. This agent allows the VM to interact with various Azure services. Assuming you have deployed a standard image from the Azure Marketplace, you would need to do the following to correctly configure your Linux swap file settings:
7379

0 commit comments

Comments
 (0)