Skip to content

Commit 8e233ab

Browse files
authored
Merge pull request #220938 from claytonsiemens77/lint-test
Linter testing - CSIEMENS
2 parents aded8aa + f6e9083 commit 8e233ab

File tree

1 file changed

+113
-73
lines changed

1 file changed

+113
-73
lines changed

articles/virtual-machines/linux/suse-create-upload-vhd.md

Lines changed: 113 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.subservice: imaging
77
ms.collection: linux
88
ms.workload: infrastructure-services
99
ms.topic: how-to
10-
ms.date: 12/01/2020
10+
ms.date: 12/08/2022
1111
ms.author: srijangupta
1212
ms.reviewer: mattmcinnes
1313

@@ -16,108 +16,133 @@ ms.reviewer: mattmcinnes
1616

1717
**Applies to:** :heavy_check_mark: Linux VMs :heavy_check_mark: Flexible scale sets **Applies to:** :heavy_check_mark: Uniform scale sets
1818

19+
In some cases, you may want to use customized SUSE or openSUSE Leap Linux VMs in your Azure environment and be able to build these types of VMs through automation. This article demonstrates how to create and upload a custom Azure virtual hard disk (VHD) that contains a SUSE Linux operating system.
20+
21+
## Prerequisites
22+
1923
This article assumes that you have already installed a SUSE or openSUSE Leap Linux operating system to a virtual hard disk. Multiple tools exist to create .vhd files, for example a virtualization solution such as Hyper-V. For instructions, see [Install the Hyper-V Role and Configure a Virtual Machine](/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/hh846766(v=ws.11)).
2024

2125
## SLES / openSUSE Leap installation notes
22-
* Please see also [General Linux Installation Notes](create-upload-generic.md#general-linux-installation-notes) for more tips on preparing Linux for Azure.
23-
* The VHDX format is not supported in Azure, only **fixed VHD**. You can convert the disk to VHD format using Hyper-V Manager or the convert-vhd cmdlet.
24-
* When installing the Linux system it is recommended that you use standard partitions rather than LVM (often the default for many installations). This will avoid LVM name conflicts with cloned VMs, particularly if an OS disk ever needs to be attached to another VM for troubleshooting. [LVM](/previous-versions/azure/virtual-machines/linux/configure-lvm) or [RAID](/previous-versions/azure/virtual-machines/linux/configure-raid) may be used on data disks if preferred.
25-
* Do not configure a swap partition on the OS disk. The Linux agent can be configured to create a swap file on the temporary resource disk. More information about this can be found in the steps below.
26-
* All VHDs on Azure must have a virtual size aligned to 1MB. When converting from a raw disk to VHD you must ensure that the raw disk size is a multiple of 1MB before conversion. See [Linux Installation Notes](create-upload-generic.md#general-linux-installation-notes) for more information.
26+
27+
* For more tips on preparing Linux images for Azure, see [General Linux Installation Notes](create-upload-generic.md#general-linux-installation-notes)
28+
* The VHDX format isn't supported in Azure, only **fixed VHD**. You can convert the disk to VHD format using Hyper-V Manager or the convert-vhd cmdlet.
29+
* When installing the Linux operating system, use standard partitions rather than logical volume manager (LVM) managed partitions, which is often the default for many installations. Using standard partitions will avoid LVM name conflicts with cloned VMs, particularly if an OS disk ever needs to be attached to another VM for troubleshooting. [LVM](/previous-versions/azure/virtual-machines/linux/configure-lvm) or [RAID](/previous-versions/azure/virtual-machines/linux/configure-raid) may be used on data disks if preferred.
30+
* Don't configure a swap partition on the OS disk. The Linux agent can be configured to create a swap file on the temporary resource disk. More information about configuring swap space can be found in the steps below.
31+
* All VHDs on Azure must have a virtual size aligned to 1 MB. When converting from a raw disk to VHD, you must ensure that the raw disk size is a multiple of 1 MB before conversion. See [Linux Installation Notes](create-upload-generic.md#general-linux-installation-notes) for more information.
2732

2833
## Use SUSE Studio
29-
[SUSE Studio](https://studioexpress.opensuse.org/) can easily create and manage your SLES and openSUSE Leap images for Azure and Hyper-V. This is the recommended approach for customizing your own SLES and openSUSE Leap images.
34+
35+
[SUSE Studio](https://studioexpress.opensuse.org/) can easily create and manage your SLES and openSUSE Leap images for Azure and Hyper-V. SUSE Studio is the recommended approach for customizing your own SLES and openSUSE Leap images.
3036

3137
As an alternative to building your own VHD, SUSE also publishes BYOS (Bring Your Own Subscription) images for SLES at [VM Depot](https://www.microsoft.com/research/wp-content/uploads/2016/04/using-and-contributing-vms-to-vm-depot.pdf).
3238

3339
## Prepare SUSE Linux Enterprise Server for Azure
40+
3441
1. In the center pane of Hyper-V Manager, select the virtual machine.
3542
2. Click **Connect** to open the window for the virtual machine.
3643
3. Register your SUSE Linux Enterprise system to allow it to download updates and install packages.
3744
4. Update the system with the latest patches:
3845

3946
```console
40-
# sudo zypper update
47+
sudo zypper update
4148
```
4249
4350
5. Install Azure Linux Agent and cloud-init
4451

4552
```console
46-
# SUSEConnect -p sle-module-public-cloud/15.2/x86_64 (SLES 15 SP2)
47-
# sudo zypper refresh
48-
# sudo zypper install python-azure-agent
49-
# sudo zypper install cloud-init
53+
SUSEConnect -p sle-module-public-cloud/15.2/x86_64 (SLES 15 SP2)
54+
sudo zypper refresh
55+
sudo zypper install python-azure-agent
56+
sudo zypper install cloud-init
5057
```
5158

5259
6. Enable waagent & cloud-init to start on boot
5360

5461
```console
55-
# sudo chkconfig waagent on
56-
# systemctl enable cloud-init-local.service
57-
# systemctl enable cloud-init.service
58-
# systemctl enable cloud-config.service
59-
# systemctl enable cloud-final.service
60-
# systemctl daemon-reload
61-
# cloud-init clean
62+
sudo -i
63+
chkconfig waagent on
64+
systemctl enable cloud-init-local.service
65+
systemctl enable cloud-init.service
66+
systemctl enable cloud-config.service
67+
systemctl enable cloud-final.service
68+
systemctl daemon-reload
69+
cloud-init clean
70+
exit
6271
```
6372

6473
7. Update waagent and cloud-init configuration
6574

6675
```console
67-
# sed -i 's/Provisioning.UseCloudInit=n/Provisioning.UseCloudInit=y/g' /etc/waagent.conf
68-
# sed -i 's/Provisioning.Enabled=y/Provisioning.Enabled=n/g' /etc/waagent.conf
76+
sudo -i
77+
sed -i 's/Provisioning.UseCloudInit=n/Provisioning.UseCloudInit=y/g' /etc/waagent.conf
78+
sed -i 's/Provisioning.Enabled=y/Provisioning.Enabled=n/g' /etc/waagent.conf
6979

70-
# sudo sh -c 'printf "datasource:\n Azure:" > /etc/cloud/cloud.cfg.d/91-azure_datasource.cfg'
71-
# sudo sh -c 'printf "reporting:\n logging:\n type: log\n telemetry:\n type: hyperv" > /etc/cloud/cloud.cfg.d/10-azure-kvp.cfg'
80+
sh -c 'printf "datasource:\n Azure:" > /etc/cloud/cloud.cfg.d/91-azure_datasource.cfg'
81+
sh -c 'printf "reporting:\n logging:\n type: log\n telemetry:\n type: hyperv" > /etc/cloud/cloud.cfg.d/10-azure-kvp.cfg'
82+
exit
7283
```
7384

74-
8. Edit /etc/default/grub file to ensure console logs are sent to serial port and then update the main configuration file with grub2-mkconfig -o /boot/grub2/grub.cfg
85+
8. Edit the "/etc/default/grub" file to ensure console logs are sent to the serial port by adding the following line:
7586

7687
```config-grub
7788
console=ttyS0 earlyprintk=ttyS0
7889
```
79-
This will ensure all console messages are sent to the first serial port, which can assist Azure support with debugging issues.
80-
81-
9. Ensure /etc/fstab file reference the disk using its UUID (by-uuid)
82-
90+
91+
Next, apply this change by running the following command:
92+
93+
```console
94+
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
95+
```
96+
97+
This configuration will ensure all console messages are sent to the first serial port, which can assist Azure support with debugging issues.
98+
99+
9. Ensure the "/etc/fstab" file references the disk using its UUID (by-uuid)
100+
83101
10. Modify udev rules to avoid generating static rules for the Ethernet interface(s). These rules can cause problems when cloning a virtual machine in Microsoft Azure or Hyper-V:
84102

85103
```console
86-
# sudo ln -s /dev/null /etc/udev/rules.d/75-persistent-net-generator.rules
87-
# sudo rm -f /etc/udev/rules.d/70-persistent-net.rules
104+
sudo -i
105+
ln -s /dev/null /etc/udev/rules.d/75-persistent-net-generator.rules
106+
rm -f /etc/udev/rules.d/70-persistent-net.rules
107+
exit
88108
```
89-
90-
11. It is recommended to edit the file "/etc/sysconfig/network/dhcp" and change the `DHCLIENT_SET_HOSTNAME` parameter to the following:
109+
110+
11. It's recommended to edit the "/etc/sysconfig/network/dhcp" file and change the `DHCLIENT_SET_HOSTNAME` parameter to the following:
91111

92112
```config
93113
DHCLIENT_SET_HOSTNAME="no"
94114
```
95115

96-
12. In "/etc/sudoers", comment out or remove the following lines if they exist:
116+
12. In the "/etc/sudoers" file, comment out or remove the following lines if they exist:
97117

98118
```text
99119
Defaults targetpw # ask for the password of the target user i.e. root
100-
ALL ALL=(ALL) ALL # WARNING! Only use this together with 'Defaults targetpw'!
120+
ALL ALL=(ALL) ALL # WARNING! Only use this setting together with 'Defaults targetpw'!
101121
```
102122

103-
13. Ensure that the SSH server is installed and configured to start at boot time. This is usually the default.
123+
13. Ensure that the SSH server is installed and configured to start at boot time.
104124

105125
14. Swap configuration
106-
107-
Do not create swap space on the operating system disk.
108126

109-
Previously, the Azure Linux Agent was used automatically configure swap space by using the local resource disk that is attached to the virtual machine after the virtual machine is provisioned on Azure. However this is now handled by cloud-init, you **must not** use the Linux Agent to format the resource disk create the swap file, modify the following parameters in `/etc/waagent.conf` appropriately:
127+
Don't create swap space on the operating system disk.
128+
129+
Previously, the Azure Linux Agent was used to automatically configure swap space by using the local resource disk that is attached to the virtual machine after the virtual machine is provisioned on Azure. However this step is now handled by cloud-init, you **must not** use the Linux Agent to format the resource disk or create the swap file. Use these commands to modify `/etc/waagent.conf` appropriately:
110130

111131
```console
112-
# sed -i 's/ResourceDisk.Format=y/ResourceDisk.Format=n/g' /etc/waagent.conf
113-
# sed -i 's/ResourceDisk.EnableSwap=y/ResourceDisk.EnableSwap=n/g' /etc/waagent.conf
132+
sudo -i
133+
sed -i 's/ResourceDisk.Format=y/ResourceDisk.Format=n/g' /etc/waagent.conf
134+
sed -i 's/ResourceDisk.EnableSwap=y/ResourceDisk.EnableSwap=n/g' /etc/waagent.conf
135+
exit
114136
```
115137

116-
If you want mount, format and create swap you can either:
117-
* Pass this in as a cloud-init config every time you create a VM.
118-
* Use a cloud-init directive baked into the image that will do this every time the VM is created:
138+
For more information on the waagent.conf configuration options, see the [Linux agent configuration](/azure/virtual-machines/extensions/agent-linux#configuration) documentation.
139+
140+
If you want to mount, format and create a swap partition you can either:
141+
* Pass this configuration in as a cloud-init config every time you create a VM.
142+
* Use a cloud-init directive baked into the image that configures swap space every time the VM is created:
119143

120144
```console
145+
sudo -i
121146
echo 'DefaultEnvironment="CLOUD_CFG=/etc/cloud/cloud.cfg.d/00-azure-swap.cfg"' >> /etc/systemd/system.conf
122147
cat > /etc/cloud/cloud.cfg.d/00-azure-swap.cfg << EOF
123148
#cloud-config
@@ -136,29 +161,34 @@ As an alternative to building your own VHD, SUSE also publishes BYOS (Bring Your
136161
- ["ephemeral0.1", "/mnt"]
137162
- ["ephemeral0.2", "none", "swap", "sw,nofail,x-systemd.requires=cloud-init.service,x-systemd.device-timeout=2", "0", "0"]
138163
EOF
164+
exit
139165
```
140166

141167
15. Run the following commands to deprovision the virtual machine and prepare it for provisioning on Azure:
142168

143169
```console
144-
# sudo rm -rf /var/lib/waagent/
145-
# sudo rm -f /var/log/waagent.log
170+
rm -f ~/.bash_history # Remove current user history
146171

147-
# waagent -force -deprovision+user
148-
# rm -f ~/.bash_history
149-
172+
sudo -i
173+
rm -rf /var/lib/waagent/
174+
rm -f /var/log/waagent.log
150175

151-
# export HISTSIZE=0
176+
waagent -force -deprovision+user
177+
rm -f ~/.bash_history # Remove root user history
178+
179+
export HISTSIZE=0
152180

153-
# logout
181+
logout
154182
```
155183
16. Click **Action -> Shut Down** in Hyper-V Manager. Your Linux VHD is now ready to be [**uploaded to Azure**](./upload-vhd.md#option-1-upload-a-vhd).
156184

157185
---
186+
158187
## Prepare openSUSE 15.2+
188+
159189
1. In the center pane of Hyper-V Manager, select the virtual machine.
160190
2. Click **Connect** to open the window for the virtual machine.
161-
3. On the shell, run the command '`zypper lr`'. If this command returns output similar to the following, then the repositories are configured as expected--no adjustments are necessary (note that version numbers may vary):
191+
3. In a terminal, run the command '`zypper lr`'. If this command returns output similar to the following, then the repositories are configured as expected and no adjustments are necessary (note that version numbers may vary):
162192

163193
| # | Alias | Name | Enabled | Refresh
164194
| - | :-------------------- | :-------------------- | :------ | :------
@@ -169,33 +199,33 @@ As an alternative to building your own VHD, SUSE also publishes BYOS (Bring Your
169199
If the command returns "No repositories defined..." then use the following commands to add these repos:
170200

171201
```console
172-
# sudo zypper ar -f http://download.opensuse.org/repositories/Cloud:Tools/openSUSE_15.2 Cloud:Tools_15.2
173-
# sudo zypper ar -f https://download.opensuse.org/distribution/15.2/repo/oss openSUSE_15.2_OSS
174-
# sudo zypper ar -f http://download.opensuse.org/update/15.2 openSUSE_15.2_Updates
202+
sudo zypper ar -f http://download.opensuse.org/repositories/Cloud:Tools/openSUSE_15.2 Cloud:Tools_15.2
203+
sudo zypper ar -f https://download.opensuse.org/distribution/15.2/repo/oss openSUSE_15.2_OSS
204+
sudo zypper ar -f http://download.opensuse.org/update/15.2 openSUSE_15.2_Updates
175205
```
176206

177-
You can then verify the repositories have been added by running the command '`zypper lr`' again. In case one of the relevant update repositories is not enabled, enable it with following command:
207+
You can then verify the repositories have been added by running the command '`zypper lr`' again. If one of the relevant update repositories isn't enabled, enable it with following command:
178208

179209
```console
180-
# sudo zypper mr -e [NUMBER OF REPOSITORY]
210+
sudo zypper mr -e [NUMBER OF REPOSITORY]
181211
```
182212

183213
4. Update the kernel to the latest available version:
184214

185215
```console
186-
# sudo zypper up kernel-default
216+
sudo zypper up kernel-default
187217
```
188218

189-
Or to update the system with all the latest patches:
219+
Or to update the operating system with all the latest patches:
190220

191221
```console
192-
# sudo zypper update
222+
sudo zypper update
193223
```
194224

195225
5. Install the Azure Linux Agent.
196226

197227
```console
198-
# sudo zypper install WALinuxAgent
228+
sudo zypper install WALinuxAgent
199229
```
200230

201231
6. Modify the kernel boot line in your grub configuration to include additional kernel parameters for Azure. To do this, open "/boot/grub/menu.lst" in a text editor and ensure that the default kernel includes the following parameters:
@@ -204,53 +234,63 @@ As an alternative to building your own VHD, SUSE also publishes BYOS (Bring Your
204234
console=ttyS0 earlyprintk=ttyS0
205235
```
206236

207-
This will ensure all console messages are sent to the first serial port, which can assist Azure support with debugging issues. In addition, remove the following parameters from the kernel boot line if they exist:
237+
This option will ensure all console messages are sent to the first serial port, which can assist Azure support with debugging issues. In addition, remove the following parameters from the kernel boot line if they exist:
208238

209239
```config-grub
210240
libata.atapi_enabled=0 reserve=0x1f0,0x8
211241
```
212242

213-
7. It is recommended to edit the file "/etc/sysconfig/network/dhcp" and change the `DHCLIENT_SET_HOSTNAME` parameter to the following:
243+
7. It's recommended to edit the "/etc/sysconfig/network/dhcp" file and change the `DHCLIENT_SET_HOSTNAME` parameter to the following setting:
214244

215245
```config
216246
DHCLIENT_SET_HOSTNAME="no"
217247
```
218248

219-
8. **Important:** In "/etc/sudoers", comment out or remove the following lines if they exist:
249+
8. **Important:** In the "/etc/sudoers" file, comment out or remove the following lines if they exist:
220250

221251
```text
222252
Defaults targetpw # ask for the password of the target user i.e. root
223253
ALL ALL=(ALL) ALL # WARNING! Only use this together with 'Defaults targetpw'!
224254
```
225255

226-
9. Ensure that the SSH server is installed and configured to start at boot time. This is usually the default.
227-
10. Do not create swap space on the OS disk.
256+
9. Ensure that the SSH server is installed and configured to start at boot time.
257+
10. Don't create swap space on the OS disk.
228258

229-
The Azure Linux Agent can automatically configure swap space using the local resource disk that is attached to the VM after provisioning on Azure. Note that the local resource disk is a *temporary* disk, and might be emptied when the VM is deprovisioned. After installing the Azure Linux Agent (see previous step), modify the following parameters in /etc/waagent.conf appropriately:
259+
The Azure Linux Agent can automatically configure swap space using the local resource disk that is attached to the VM after provisioning on Azure. Note that the local resource disk is a *temporary* disk, and might be emptied when the VM is deprovisioned. After installing the Azure Linux Agent (see previous step), modify the following parameters in the "/etc/waagent.conf" as follows:
230260

231261
```config-conf
232262
ResourceDisk.Format=y
233263
ResourceDisk.Filesystem=ext4
234264
ResourceDisk.MountPoint=/mnt/resource
235265
ResourceDisk.EnableSwap=y
236-
ResourceDisk.SwapSizeMB=2048 ## NOTE: set this to whatever you need it to be.
266+
ResourceDisk.SwapSizeMB=2048 ## NOTE: set the size to whatever you need it to be.
237267
```
238268

239-
11. Run the following commands to deprovision the virtual machine and prepare it for provisioning on Azure:
269+
11. Ensure the Azure Linux Agent runs at startup:
240270

241271
```console
242-
# sudo waagent -force -deprovision
243-
# export HISTSIZE=0
244-
# logout
272+
sudo systemctl enable waagent.service
245273
```
246274

247-
12. Ensure the Azure Linux Agent runs at startup:
275+
12. Run the following commands to deprovision the virtual machine and prepare it for provisioning on Azure:
248276

249277
```console
250-
# sudo systemctl enable waagent.service
278+
rm -f ~/.bash_history # Remove current user history
279+
280+
sudo -i
281+
rm -rf /var/lib/waagent/
282+
rm -f /var/log/waagent.log
283+
284+
waagent -force -deprovision+user
285+
rm -f ~/.bash_history # Remove root user history
286+
287+
export HISTSIZE=0
288+
289+
logout
251290
```
252291

253292
13. Click **Action -> Shut Down** in Hyper-V Manager. Your Linux VHD is now ready to be [**uploaded to Azure**](./upload-vhd.md#option-1-upload-a-vhd).
254293

255294
## Next steps
295+
256296
You're now ready to use your SUSE Linux virtual hard disk to create new virtual machines in Azure. If this is the first time that you're uploading the .vhd file to Azure, see [Create a Linux VM from a custom disk](upload-vhd.md#option-1-upload-a-vhd).

0 commit comments

Comments
 (0)