大网数据广告活动
服务器运维问答

How to create a swap for Azure Ubuntu VM?

· 52CE 我爱测

I have read quite a few posts on this, but I am still unsure about the correct approach, assuming: I have a default Ubuntu 14.04 LTS VM created by and running on Azure, which doesn't come with a swap I would like to create a swap…

问题原文

原帖链接 · bitinn · CC BY-SA 3.0

I have read quite a few posts on this, but I am still unsure about the correct approach, assuming:

  1. I have a default Ubuntu 14.04 LTS VM created by and running on Azure, which doesn't come with a swap

  2. I would like to create a swap using existing VM storage, instead of create a new disk using additional storage

Posts I have read:

Many solutions were discussed but I can't seem to find one that will persists across server reboots (probably due to cloud-init has it's own idea about image partitioning), can someone advise me on the best practice?

社区高分解答

原帖链接 · Bruno Faria · CC BY-SA 3.0

Assuming that you have Linux Agent installed. All you have to do is to enable swap under /etc/waagent.conf. These are the relevant lines:

ResourceDisk.Format=y                   # Format if unformatted. If 'n', resour$
ResourceDisk.Filesystem=ext4            # Typically ext3 or ext4. FreeBSD image$
ResourceDisk.MountPoint=/mnt/resource   #
ResourceDisk.EnableSwap=y               # Create and use swapfile on resource d$
ResourceDisk.SwapSizeMB=2048            # Size of the swapfile.

It will automatically use the resource disk (which comes with every VM) to create the swap. There's no need to create a disk for it.

Update: You also need to execute the steps below in order to create the swapfile:

umount /mnt
service walinuxagent restart

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-05-31)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。