Skip to content

Commit a2ba874

Browse files
authored
Merge pull request #252900 from esvmicrosoft/suse2
Updates to the SUSE configuration
2 parents 03dc290 + 7f5b78c commit a2ba874

File tree

1 file changed

+154
-106
lines changed

1 file changed

+154
-106
lines changed

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

Lines changed: 154 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ This article assumes that you have already installed a SUSE or openSUSE Leap Lin
2828
* 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.
2929
* Azure supports Gen1 (BIOS boot) and Gen2 (UEFI boot) virtual machines.
3030
* The `vfat` kernel module must be enabled in the kernel
31-
* 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.
3231
* 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.
3332
* 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.
3433

3534

3635
> [!NOTE]
37-
> **_Cloud-init >= 21.2 removes the udf requirement_**. However, without the udf module enabled, the cdrom won't mount during provisioning, preventing custom data from being applied. A workaround for this is to apply custom data using user data. However, unlike custom data, user data isn't encrypted. https://cloudinit.readthedocs.io/en/latest/topics/format.html
36+
> **(_Cloud-init >= 21.2 removes the udf requirement._)** however without the udf module enabled the cdrom won't mount during provisioning, preventing custom data from being applied. A workaround for this is to apply custom data. However, unlike custom data user data, isn't encrypted. https://cloudinit.readthedocs.io/en/latest/topics/format.html
3837
3938

4039
## Use SUSE Studio
@@ -45,140 +44,188 @@ As an alternative to building your own VHD, SUSE also publishes BYOS (Bring Your
4544

4645
## Prepare SUSE Linux Enterprise Server for Azure
4746

48-
1. In the center pane of Hyper-V Manager, select the virtual machine.
49-
2. Click **Connect** to open the window for the virtual machine.
47+
1. Configure the Azure/Hyper-v modules if required.
48+
49+
If your software hypervisor is not Hyper-V, other modules need to be added into the initramfs to successfully boot in Azure
50+
51+
Edit the "/etc/dracut.conf" file and add the following line to the file then executeh the ```dracut```command to rebuild the initramfs file:
52+
53+
```config
54+
add_drivers+=" hv_vmbus hv_netvsc hv_storvsc "
55+
```
56+
57+
```bash
58+
sudo dracut --verbose --force
59+
```
60+
61+
2. Setup the Serial Console.
62+
63+
In order to successfully work with the serial console, it's required to set up several variables in the "/etc/defaults/grub" file and recreate the grub on the server.
64+
65+
```config
66+
# Add console=ttyS0 and earlyprintk=ttS0 to the variable
67+
# remove "splash=silent" and "quiet" options.
68+
GRUB_CMDLINE_LINUX_DEFAULT="audit=1 no-scroll fbcon=scrollback:0 mitigations=auto security=apparmor crashkernel=228M,high crashkernel=72M,low console=ttyS0 earlyprintk=ttyS0"
69+
70+
# Add "console serial" to GRUB_TERMINAL
71+
GRUB_TERMINAL="console serial"
72+
73+
# Set the GRUB_SERIAL_COMMAND variable
74+
75+
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
76+
```
77+
78+
```shell
79+
/usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg
80+
```
81+
5082
3. Register your SUSE Linux Enterprise system to allow it to download updates and install packages.
83+
5184
4. Update the system with the latest patches:
5285

53-
```bash
54-
sudo zypper update
55-
```
86+
```bash
87+
sudo zypper update
88+
```
5689

5790
5. Install Azure Linux Agent and cloud-init
5891

59-
```bash
60-
sudo SUSEConnect -p sle-module-public-cloud/15.2/x86_64 (SLES 15 SP2)
61-
sudo zypper refresh
62-
sudo zypper install python-azure-agent
63-
sudo zypper install cloud-init
64-
```
92+
```bash
93+
sudo SUSEConnect -p sle-module-public-cloud/15.2/x86_64 (SLES 15 SP2)
94+
sudo zypper refresh
95+
sudo zypper install python-azure-agent
96+
sudo zypper install cloud-init
97+
```
6598

6699
6. Enable waagent & cloud-init to start on boot
67100

68-
```bash
69-
sudo chkconfig waagent on
70-
sudo systemctl enable cloud-init-local.service
71-
sudo systemctl enable cloud-init.service
72-
sudo systemctl enable cloud-config.service
73-
sudo systemctl enable cloud-final.service
74-
sudo systemctl daemon-reload
75-
sudo cloud-init clean
76-
```
77-
78-
7. Update waagent and cloud-init configuration
79-
80-
```bash
81-
sudo sed -i 's/Provisioning.UseCloudInit=n/Provisioning.UseCloudInit=auto/g' /etc/waagent.conf
82-
sudo sed -i 's/Provisioning.Enabled=y/Provisioning.Enabled=n/g' /etc/waagent.conf
83-
sudo sh -c 'printf "datasource:\n Azure:" > /etc/cloud/cloud.cfg.d/91-azure_datasource.cfg'
84-
sudo sh -c 'printf "reporting:\n logging:\n type: log\n telemetry:\n type: hyperv" > /etc/cloud/cloud.cfg.d/10-azure-kvp.cfg'
85-
```
86-
87-
8. Edit the "/etc/default/grub" file to ensure console logs are sent to the serial port by adding the following line:
101+
```bash
102+
sudo systemctl enable waagent
103+
sudo systemctl enable cloud-init-local.service
104+
sudo systemctl enable cloud-init.service
105+
sudo systemctl enable cloud-config.service
106+
sudo systemctl enable cloud-final.service
107+
sudo systemctl daemon-reload
108+
sudo cloud-init clean
109+
```
88110

89-
```config-grub
90-
console=ttyS0 earlyprintk=ttyS0
91-
```
111+
7. Update the cloud-init configuration
92112

93-
Next, apply this change by running the following command:
113+
```bash
114+
cat <<EOF | sudo /etc/cloud/cloud.cfg.d/91-azure_datasource.cfg
115+
datasource_list: [ Azure ]
116+
datasource:
117+
Azure:
118+
apply_network_config: False
94119
95-
```bash
96-
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
97-
```
120+
EOF
121+
```
98122

99-
This configuration will ensure all console messages are sent to the first serial port, which can assist Azure support with debugging issues.
123+
```bash
124+
sudo cat <<EOF | sudo tee /etc/cloud/cloud.cfg.d/05_logging.cfg
125+
# This tells cloud-init to redirect its stdout and stderr to
126+
# 'tee -a /var/log/cloud-init-output.log' so the user can see output
127+
# there without needing to look on the console.
128+
output: {all: '| tee -a /var/log/cloud-init-output.log'}
129+
EOF
130+
131+
# Make sure mounts and disk_setup are in the init stage:
132+
echo "Adding mounts and disk_setup to init stage"
133+
sudo sed -i '/ - mounts/d' /etc/cloud/cloud.cfg
134+
sudo sed -i '/ - disk_setup/d' /etc/cloud/cloud.cfg
135+
sudo sed -i '/cloud_init_modules/a\\ - mounts' /etc/cloud/cloud.cfg
136+
sudo sed -i '/cloud_init_modules/a\\ - disk_setup' /etc/cloud/cloud.cfg
137+
```
100138

101-
9. Ensure the "/etc/fstab" file references the disk using its UUID (by-uuid)
139+
8. If you want to mount, format, and create a swap partition you can either:
140+
* Pass this configuration in as a cloud-init config every time you create a VM.
141+
* Use a cloud-init directive baked into the image that configures swap space every time the VM is created:
142+
102143

103-
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:
144+
```bash
145+
cat <<EOF | sudo tee -a /etc/systemd/system.conf
146+
'DefaultEnvironment="CLOUD_CFG=/etc/cloud/cloud.cfg.d/00-azure-swap.cfg"'
147+
EOF
148+
149+
cat <<EOF | sudo tee /etc/cloud/cloud.cfg.d/00-azure-swap.cfg
150+
#cloud-config
151+
# Generated by Azure cloud image build
152+
disk_setup:
153+
ephemeral0:
154+
table_type: mbr
155+
layout: [66, [33, 82]]
156+
overwrite: True
157+
fs_setup:
158+
- device: ephemeral0.1
159+
filesystem: ext4
160+
- device: ephemeral0.2
161+
filesystem: swap
162+
mounts:
163+
- ["ephemeral0.1", "/mnt"]
164+
- ["ephemeral0.2", "none", "swap", "sw,nofail,x-systemd.requires=cloud-init.service,x-systemd.device-timeout=2", "0", "0"]
165+
EOF
166+
```
167+
168+
9. 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:
104169

105-
```bash
106-
sudo ln -s /dev/null /etc/udev/rules.d/75-persistent-net-generator.rules
107-
sudo rm -f /etc/udev/rules.d/70-persistent-net.rules
108-
```
109170

110-
11. It's recommended to edit the "/etc/sysconfig/network/dhcp" file and change the `DHCLIENT_SET_HOSTNAME` parameter to the following:
171+
```bash
172+
sudo sed -i 's/Provisioning.UseCloudInit=n/Provisioning.UseCloudInit=auto/g' /etc/waagent.conf
173+
sudo sed -i 's/Provisioning.Enabled=y/Provisioning.Enabled=n/g' /etc/waagent.conf
174+
sudo sed -i 's/ResourceDisk.Format=y/ResourceDisk.Format=n/g' /etc/waagent.conf
175+
sudo sed -i 's/ResourceDisk.EnableSwap=y/ResourceDisk.EnableSwap=n/g' /etc/waagent.conf
176+
```
111177

112-
```config
113-
DHCLIENT_SET_HOSTNAME="no"
114-
```
178+
> [!NOTE]
179+
> Make sure the **'udf'** module is enabled. Removing/disabling them will cause a provisioning/boot failure. **(_Cloud-init >= 21.2 removes the udf requirement. Please read top of document for more detail)**
115180
116-
12. In the "/etc/sudoers" file, comment out or remove the following lines if they exist:
181+
10. Ensure the "/etc/fstab" file references the disk using its UUID (by-uuid)
117182

118-
```output
119-
Defaults targetpw # ask for the password of the target user i.e. root
120-
ALL ALL=(ALL) ALL # WARNING! Only use this setting together with 'Defaults targetpw'!
121-
```
183+
11. Remove udev rules and network adapter configuration files 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:
122184

123-
13. Ensure that the SSH server is installed and configured to start at boot time.
185+
```bash
186+
sudo rm -f /etc/udev/rules.d/70-persistent-net.rules
187+
sudo rm -f /etc/udev/rules.d/85-persistent-net-cloud-init.rules
188+
sudo rm -f /etc/sysconfig/network/ifcfg-eth*
189+
```
124190

125-
14. Swap configuration
191+
12. It's recommended to edit the "/etc/sysconfig/network/dhcp" file and change the `DHCLIENT_SET_HOSTNAME` parameter to the following:
126192

127-
Don't create swap space on the operating system disk.
193+
```config
194+
DHCLIENT_SET_HOSTNAME="no"
195+
```
128196

197+
13. In the "/etc/sudoers" file, comment out or remove the following lines if they exist:
129198

130-
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:
199+
```output
200+
Defaults targetpw # ask for the password of the target user i.e. root
201+
ALL ALL=(ALL) ALL # WARNING! Only use this setting together with 'Defaults targetpw'!
202+
```
131203

132-
```bash
133-
sudo sed -i 's/ResourceDisk.Format=y/ResourceDisk.Format=n/g' /etc/waagent.conf
134-
sudo sed -i 's/ResourceDisk.EnableSwap=y/ResourceDisk.EnableSwap=n/g' /etc/waagent.conf
135-
```
136204

137-
For more information on the waagent.conf configuration options, see the [Linux agent configuration](../extensions/agent-linux.md#configuration) documentation.
205+
14. Ensure that the SSH server is installed and configured to start at boot time.
138206

139-
If you want to mount, format, and create a swap partition you can either:
140-
* Pass this configuration in as a cloud-init config every time you create a VM.
141-
* Use a cloud-init directive baked into the image that configures swap space every time the VM is created:
207+
```bash
208+
sudo systemctl enable sshd
209+
```
142210

143-
```bash
144-
sudo echo 'DefaultEnvironment="CLOUD_CFG=/etc/cloud/cloud.cfg.d/00-azure-swap.cfg"' >> /etc/systemd/system.conf
145-
cat > /etc/cloud/cloud.cfg.d/00-azure-swap.cfg << EOF
146-
#cloud-config
147-
# Generated by Azure cloud image build
148-
disk_setup:
149-
ephemeral0:
150-
table_type: mbr
151-
layout: [66, [33, 82]]
152-
overwrite: True
153-
fs_setup:
154-
- device: ephemeral0.1
155-
filesystem: ext4
156-
- device: ephemeral0.2
157-
filesystem: swap
158-
mounts:
159-
- ["ephemeral0.1", "/mnt"]
160-
- ["ephemeral0.2", "none", "swap", "sw,nofail,x-systemd.requires=cloud-init.service,x-systemd.device-timeout=2", "0", "0"]
161-
EOF
162-
```
163-
> [!NOTE]
164-
> Make sure the **'udf'** module is enabled. Removing/disabling them will cause a provisioning/boot failure. **(_Cloud-init >= 21.2 removes the udf requirement. Please read top of document for more detail)**
211+
15. Make sure to clean cloud-init stage;
165212

213+
```bash
214+
sudo cloud-init clean --seed --logs
215+
```
166216

167-
15. Run the following commands to deprovision the virtual machine and prepare it for provisioning on Azure:
217+
16. Run the following commands to deprovision the virtual machine and prepare it for provisioning on Azure:
168218

169-
> [!NOTE]
170-
> If you're migrating a specific virtual machine and don't wish to create a generalized image, skip the deprovision step.
219+
>[!NOTE]
220+
> If you're migrating a specific virtual machine and don't wish to create a generalized image, skip the deprovision step
171221
172222
```bash
173-
sudo rm -f /var/log/waagent.log
174-
sudo cloud-init clean
175-
sudo waagent -force -deprovision+user
176-
sudo rm -f ~/.bash_history
177-
sudo export HISTSIZE=0
178-
```
223+
sudo rm -f /var/log/waagent.log
224+
sudo waagent -force -deprovision+user
225+
sudo export HISTSIZE=0
226+
sudo rm -f ~/.bash_history
227+
```
179228

180-
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).
181-
182229
---
183230

184231
## Prepare openSUSE 15.2+
@@ -225,13 +272,13 @@ As an alternative to building your own VHD, SUSE also publishes BYOS (Bring Your
225272
sudo zypper install WALinuxAgent
226273
```
227274
228-
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:
275+
6. Modify the kernel boot line in your grub configuration to include other 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:
229276
230277
```config-grub
231278
console=ttyS0 earlyprintk=ttyS0
232279
```
233280
234-
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:
281+
This option ensures 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:
235282
236283
```config-grub
237284
libata.atapi_enabled=0 reserve=0x1f0,0x8
@@ -253,13 +300,13 @@ As an alternative to building your own VHD, SUSE also publishes BYOS (Bring Your
253300
9. Ensure that the SSH server is installed and configured to start at boot time.
254301
10. Don't create swap space on the OS disk.
255302
256-
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:
303+
The Azure Linux Agent can automatically configure swap space using the local resource disk that is attached to the VM after provisioning on Azure. The local resource disk is a *temporary* disk and will 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:
257304
258305
```config-conf
259-
ResourceDisk.Format=y
306+
ResourceDisk.Format=n
260307
ResourceDisk.Filesystem=ext4
261308
ResourceDisk.MountPoint=/mnt/resource
262-
ResourceDisk.EnableSwap=y
309+
ResourceDisk.EnableSwap=n
263310
ResourceDisk.SwapSizeMB=2048 ## NOTE: set the size to whatever you need it to be.
264311
```
265312
@@ -276,6 +323,7 @@ As an alternative to building your own VHD, SUSE also publishes BYOS (Bring Your
276323
277324
```bash
278325
sudo rm -f ~/.bash_history # Remove current user history
326+
sudo -i
279327
sudo rm -rf /var/lib/waagent/
280328
sudo rm -f /var/log/waagent.log
281329
sudo waagent -force -deprovision+user

0 commit comments

Comments
 (0)