Skip to content

Commit 2ddb2a0

Browse files
author
Enrique Sanchez Vela
committed
Updates to the SUSE configuration
1 parent 23ed5f0 commit 2ddb2a0

File tree

1 file changed

+124
-72
lines changed

1 file changed

+124
-72
lines changed

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

Lines changed: 124 additions & 72 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,9 +44,47 @@ 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:
52+
53+
```config
54+
add_drivers+=" hv_vmbus hv_netvsc hv_storvsc "
55+
```
56+
57+
Once the configuration file has been saved, run the following command to update the intramfs of the host:
58+
59+
```bash
60+
sudo dracut --verbose --force
61+
```
62+
63+
2. Setup the Serial Console.
64+
65+
In order to successfully work with the serial console, it's required to set up several variables in the "/etc/defaults/grub" file.
66+
67+
```config
68+
# Add console=ttyS0 and earlyprintk=ttS0 to the variable
69+
# remove "splash=silent" and "quiet" options.
70+
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"
71+
72+
# Add "console serial" to GRUB_TERMINAL
73+
GRUB_TERMINAL="console serial"
74+
75+
# Set the GRUB_SERIAL_COMMAND variable
76+
77+
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
78+
```
79+
80+
Next recreate the grub:
81+
82+
```shell
83+
/usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg
84+
```
85+
5086
3. Register your SUSE Linux Enterprise system to allow it to download updates and install packages.
87+
5188
4. Update the system with the latest patches:
5289
5390
```bash
@@ -66,7 +103,7 @@ As an alternative to building your own VHD, SUSE also publishes BYOS (Bring Your
66103
6. Enable waagent & cloud-init to start on boot
67104
68105
```bash
69-
sudo chkconfig waagent on
106+
sudo systemctl enable waagent
70107
sudo systemctl enable cloud-init-local.service
71108
sudo systemctl enable cloud-init.service
72109
sudo systemctl enable cloud-config.service
@@ -75,110 +112,124 @@ As an alternative to building your own VHD, SUSE also publishes BYOS (Bring Your
75112
sudo cloud-init clean
76113
```
77114
78-
7. Update waagent and cloud-init configuration
115+
7. Update the cloud-init configuration
79116
80117
```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'
118+
cat <<EOF | sudo /etc/cloud/cloud.cfg.d/91-azure_datasource.cfg
119+
datasource_list: [ Azure ]
120+
datasource:
121+
Azure:
122+
apply_network_config: False
123+
124+
EOF
85125
```
86126
87-
8. Edit the "/etc/default/grub" file to ensure console logs are sent to the serial port by adding the following line:
127+
```bash
128+
sudo cat <<EOF | sudo tee /etc/cloud/cloud.cfg.d/05_logging.cfg
129+
# This tells cloud-init to redirect its stdout and stderr to
130+
# 'tee -a /var/log/cloud-init-output.log' so the user can see output
131+
# there without needing to look on the console.
132+
output: {all: '| tee -a /var/log/cloud-init-output.log'}
133+
EOF
134+
135+
# Make sure mounts and disk_setup are in the init stage:
136+
echo "Adding mounts and disk_setup to init stage"
137+
sudo sed -i '/ - mounts/d' /etc/cloud/cloud.cfg
138+
sudo sed -i '/ - disk_setup/d' /etc/cloud/cloud.cfg
139+
sudo sed -i '/cloud_init_modules/a\\ - mounts' /etc/cloud/cloud.cfg
140+
sudo sed -i '/cloud_init_modules/a\\ - disk_setup' /etc/cloud/cloud.cfg
141+
```
88142
89-
```config-grub
90-
console=ttyS0 earlyprintk=ttyS0
143+
8. If you want to mount, format, and create a swap partition you can either:
144+
* Pass this configuration in as a cloud-init config every time you create a VM.
145+
* Use a cloud-init directive baked into the image that configures swap space every time the VM is created:
146+
147+
148+
```bash
149+
cat <<EOF | sudo tee -a /etc/systemd/system.conf
150+
'DefaultEnvironment="CLOUD_CFG=/etc/cloud/cloud.cfg.d/00-azure-swap.cfg"'
151+
EOF
152+
153+
cat <<EOF | sudo tee /etc/cloud/cloud.cfg.d/00-azure-swap.cfg
154+
#cloud-config
155+
# Generated by Azure cloud image build
156+
disk_setup:
157+
ephemeral0:
158+
table_type: mbr
159+
layout: [66, [33, 82]]
160+
overwrite: True
161+
fs_setup:
162+
- device: ephemeral0.1
163+
filesystem: ext4
164+
- device: ephemeral0.2
165+
filesystem: swap
166+
mounts:
167+
- ["ephemeral0.1", "/mnt"]
168+
- ["ephemeral0.2", "none", "swap", "sw,nofail,x-systemd.requires=cloud-init.service,x-systemd.device-timeout=2", "0", "0"]
169+
EOF
91170
```
171+
172+
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:
92173
93-
Next, apply this change by running the following command:
94174
95175
```bash
96-
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
176+
sudo sed -i 's/Provisioning.UseCloudInit=n/Provisioning.UseCloudInit=auto/g' /etc/waagent.conf
177+
sudo sed -i 's/Provisioning.Enabled=y/Provisioning.Enabled=n/g' /etc/waagent.conf
178+
sudo sed -i 's/ResourceDisk.Format=y/ResourceDisk.Format=n/g' /etc/waagent.conf
179+
sudo sed -i 's/ResourceDisk.EnableSwap=y/ResourceDisk.EnableSwap=n/g' /etc/waagent.conf
97180
```
98181
99-
This configuration will ensure all console messages are sent to the first serial port, which can assist Azure support with debugging issues.
182+
> [!NOTE]
183+
> 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)**
100184
101-
9. Ensure the "/etc/fstab" file references the disk using its UUID (by-uuid)
185+
10. Ensure the "/etc/fstab" file references the disk using its UUID (by-uuid)
102186
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:
187+
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:
104188
105189
```bash
106-
sudo ln -s /dev/null /etc/udev/rules.d/75-persistent-net-generator.rules
107190
sudo rm -f /etc/udev/rules.d/70-persistent-net.rules
191+
sudo rm -f /etc/udev/rules.d/85-persistent-net-cloud-init.rules
192+
sudo rm -f /etc/sysconfig/network/ifcfg-eth*
108193
```
109194
110-
11. It's recommended to edit the "/etc/sysconfig/network/dhcp" file and change the `DHCLIENT_SET_HOSTNAME` parameter to the following:
195+
12. It's recommended to edit the "/etc/sysconfig/network/dhcp" file and change the `DHCLIENT_SET_HOSTNAME` parameter to the following:
111196
112197
```config
113198
DHCLIENT_SET_HOSTNAME="no"
114199
```
115200
116-
12. In the "/etc/sudoers" file, comment out or remove the following lines if they exist:
201+
13. In the "/etc/sudoers" file, comment out or remove the following lines if they exist:
117202
118203
```output
119204
Defaults targetpw # ask for the password of the target user i.e. root
120205
ALL ALL=(ALL) ALL # WARNING! Only use this setting together with 'Defaults targetpw'!
121206
```
122207
123-
13. Ensure that the SSH server is installed and configured to start at boot time.
124-
125-
14. Swap configuration
126208
127-
Don't create swap space on the operating system disk.
209+
14. Ensure that the SSH server is installed and configured to start at boot time.
128210
211+
```bash
212+
sudo systemctl enable sshd
213+
```
129214

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:
215+
15. Make sure to clean cloud-init stage;
131216

132217
```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
218+
sudo cloud-init clean --seed --logs
135219
```
136220

137-
For more information on the waagent.conf configuration options, see the [Linux agent configuration](../extensions/agent-linux.md#configuration) documentation.
138-
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:
142-
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)**
221+
16. Run the following commands to deprovision the virtual machine and prepare it for provisioning on Azure:
165222

223+
>[!NOTE]
224+
> If you're migrating a specific virtual machine and don't wish to create a generalized image, skip the deprovision step
166225

167-
15. Run the following commands to deprovision the virtual machine and prepare it for provisioning on Azure:
168-
169-
> [!NOTE]
170-
> If you're migrating a specific virtual machine and don't wish to create a generalized image, skip the deprovision step.
171-
172-
```bash
226+
```bash
173227
sudo rm -f /var/log/waagent.log
174-
sudo cloud-init clean
175228
sudo waagent -force -deprovision+user
176-
sudo rm -f ~/.bash_history
177229
sudo export HISTSIZE=0
178-
```
230+
sudo rm -f ~/.bash_history
231+
```
179232

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-
182233
---
183234

184235
## Prepare openSUSE 15.2+
@@ -225,13 +276,13 @@ As an alternative to building your own VHD, SUSE also publishes BYOS (Bring Your
225276
sudo zypper install WALinuxAgent
226277
```
227278
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:
279+
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:
229280
230281
```config-grub
231282
console=ttyS0 earlyprintk=ttyS0
232283
```
233284
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:
285+
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:
235286
236287
```config-grub
237288
libata.atapi_enabled=0 reserve=0x1f0,0x8
@@ -253,13 +304,13 @@ As an alternative to building your own VHD, SUSE also publishes BYOS (Bring Your
253304
9. Ensure that the SSH server is installed and configured to start at boot time.
254305
10. Don't create swap space on the OS disk.
255306
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:
307+
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:
257308
258309
```config-conf
259-
ResourceDisk.Format=y
310+
ResourceDisk.Format=n
260311
ResourceDisk.Filesystem=ext4
261312
ResourceDisk.MountPoint=/mnt/resource
262-
ResourceDisk.EnableSwap=y
313+
ResourceDisk.EnableSwap=n
263314
ResourceDisk.SwapSizeMB=2048 ## NOTE: set the size to whatever you need it to be.
264315
```
265316
@@ -276,6 +327,7 @@ As an alternative to building your own VHD, SUSE also publishes BYOS (Bring Your
276327
277328
```bash
278329
sudo rm -f ~/.bash_history # Remove current user history
330+
sudo -i
279331
sudo rm -rf /var/lib/waagent/
280332
sudo rm -f /var/log/waagent.log
281333
sudo waagent -force -deprovision+user

0 commit comments

Comments
 (0)