Skip to content

Commit 45052f6

Browse files
authored
Merge pull request #232430 from msaenzbosupport/patch-4
[DOC-a-THON] Updating Centos upload VHD
2 parents 4b3656c + 5a7d23c commit 45052f6

File tree

1 file changed

+72
-65
lines changed

1 file changed

+72
-65
lines changed

articles/virtual-machines/linux/create-upload-centos.md

Lines changed: 72 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,23 @@ This article assumes that you've already installed a CentOS (or similar derivati
2626
**CentOS installation notes**
2727

2828
* For more tips on preparing Linux for Azure, see [General Linux Installation Notes](create-upload-generic.md#general-linux-installation-notes).
29-
* 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. If you're using VirtualBox this means selecting **Fixed size** as opposed to the default dynamically allocated when creating the disk.
29+
* 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. If you're using VirtualBox, this means selecting **Fixed size** as opposed to the default dynamically allocated when creating the disk.
3030
* The vfat kernel module must be enabled in the kernel
31-
* When installing the Linux system it's *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 identical 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.
31+
* When installing the Linux system it's **recommended** that you use standard partitions rather than LVM (often the default for many installations). This avoids LVM name conflicts with cloned VMs, particularly if an OS disk ever needs to be attached to another identical 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.
3232
* **Kernel support for mounting UDF file systems is necessary.** At first boot on Azure the provisioning configuration is passed to the Linux VM by using UDF-formatted media that is attached to the guest. The Azure Linux agent or cloud-init must mount the UDF file system to read its configuration and provision the VM.
33-
* Linux kernel versions below 2.6.37 don't support NUMA on Hyper-V with larger VM sizes. This issue primarily impacts older distributions using the upstream Red Hat 2.6.32 kernel, and was fixed in RHEL 6.6 (kernel-2.6.32-504). Systems running custom kernels older than 2.6.37, or RHEL-based kernels older than 2.6.32-504 must set the boot parameter `numa=off` on the kernel command-line in grub.conf. For more information see Red Hat [KB 436883](https://access.redhat.com/solutions/436883).
34-
* don't configure a swap partition on the OS disk. More information about this can be found in the steps below.
35-
* 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.
33+
* Linux kernel versions below 2.6.37 don't support NUMA on Hyper-V with larger VM sizes. This issue primarily impacts older distributions using the upstream Centos 2.6.32 kernel, and was fixed in Centos 6.6 (kernel-2.6.32-504). Systems running custom kernels older than 2.6.37, or RHEL-based kernels older than 2.6.32-504 must set the boot parameter `numa=off` on the kernel command-line in grub.conf. For more information, see Red Hat [KB 436883](https://access.redhat.com/solutions/436883).
34+
* Don't configure a swap partition on the OS disk.
35+
* 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.
3636

3737
> [!NOTE]
3838
> **(_Cloud-init >= 21.2 removes the udf requirement._)** however without the udf module enabled the cdrom will not mount during provisioning preventing custom data from being applied. A workaround for this would be 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
3939
4040

4141
## CentOS 6.x
4242

43+
> [!IMPORTANT]
44+
>Please note that CentOS 6 has reached its End Of Life (EOL) and is no longer supported by the CentOS community. This means that no further updates or security patches will be released for this version, leaving it vulnerable to potential security risks. We strongly recommend upgrading to a more recent version of CentOS to ensure the safety and stability of your system. Please consult with your IT department or system administrator for further assistance.
45+
4346
1. In Hyper-V Manager, select the virtual machine.
4447

4548
2. Click **Connect** to open a console window for the virtual machine.
@@ -52,14 +55,14 @@ This article assumes that you've already installed a CentOS (or similar derivati
5255

5356
4. Create or edit the file `/etc/sysconfig/network` and add the following text:
5457

55-
```console
58+
```output
5659
NETWORKING=yes
5760
HOSTNAME=localhost.localdomain
5861
```
5962

6063
5. Create or edit the file `/etc/sysconfig/network-scripts/ifcfg-eth0` and add the following text:
6164

62-
```console
65+
```output
6366
DEVICE=eth0
6467
ONBOOT=yes
6568
BOOTPROTO=dhcp
@@ -76,15 +79,15 @@ This article assumes that you've already installed a CentOS (or similar derivati
7679
sudo rm -f /etc/udev/rules.d/70-persistent-net.rules
7780
```
7881

79-
7. Ensure the network service will start at boot time by running the following command:
82+
7. Ensure the network service starts at boot time by running the following command:
8083

8184
```bash
8285
sudo chkconfig network on
8386
```
8487

85-
8. If you would like to use the OpenLogic mirrors that are hosted within the Azure datacenters, then replace the `/etc/yum.repos.d/CentOS-Base.repo` file with the following repositories. This will also add the **[openlogic]** repository that includes additional packages such as the Azure Linux agent:
88+
8. If you would like to use the OpenLogic mirrors that are hosted within the Azure datacenters, then replace the `/etc/yum.repos.d/CentOS-Base.repo` file with the following repositories. This will also add the **[openlogic]** repository that includes extra packages such as the Azure Linux agent:
8689

87-
```console
90+
```output
8891
[openlogic]
8992
name=CentOS-$releasever - openlogic packages for $basearch
9093
baseurl=http://olcentgbl.trafficmanager.net/openlogic/$releasever/openlogic/$basearch/
@@ -138,14 +141,14 @@ This article assumes that you've already installed a CentOS (or similar derivati
138141
139142
9. Add the following line to /etc/yum.conf:
140143
141-
```console
144+
```output
142145
http_caching=packages
143146
```
144147
145148
10. Run the following command to clear the current yum metadata and update the system with the latest packages:
146149
147150
```bash
148-
yum clean all
151+
sudo yum clean all
149152
```
150153
151154
Unless you're creating an image for an older version of CentOS, it's recommended to update all the packages to the latest:
@@ -177,34 +180,34 @@ This article assumes that you've already installed a CentOS (or similar derivati
177180
```
178181
179182
180-
The WALinuxAgent package will remove the NetworkManager and NetworkManager-gnome packages if they were not already removed as described in step 3.
183+
The WALinuxAgent package removes the NetworkManager and NetworkManager-gnome packages if they were not already removed as described in step 3.
181184
182185
13. 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:
183186
184-
```console
187+
```output
185188
console=ttyS0 earlyprintk=ttyS0 rootdelay=300
186189
```
187190
188191
This will also ensure all console messages are sent to the first serial port, which can assist Azure support with debugging issues.
189192
190193
In addition to the above, it's recommended to *remove* the following parameters:
191194
192-
```console
195+
```output
193196
rhgb quiet crashkernel=auto
194197
```
195198
196-
Graphical and `quiet boot` are not useful in a cloud environment where we want all the logs to be sent to the serial port. The `crashkernel` option may be left configured if desired, but note that this parameter will reduce the amount of available memory in the VM by 128MB or more, which may be problematic on the smaller VM sizes.
199+
Graphical and `quiet boot` aren't useful in a cloud environment where we want all the logs to be sent to the serial port. The `crashkernel` option may be left configured if desired, but note that this parameter will reduce the amount of available memory in the VM by 128 MB or more, which may be problematic on the smaller VM sizes.
197200
198201
> [!Important]
199202
> CentOS 6.5 and earlier must also set the kernel parameter `numa=off`. See Red Hat [KB 436883](https://access.redhat.com/solutions/436883).
200203
201204
14. Ensure that the SSH server is installed and configured to start at boot time. This is usually the default.
202205
203-
15. don't create swap space on the OS disk.
206+
15. Don't create swap space on the OS disk.
204207
205-
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:
208+
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 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:
206209
207-
```console
210+
```output
208211
ResourceDisk.Format=y
209212
ResourceDisk.Filesystem=ext4
210213
ResourceDisk.MountPoint=/mnt/resource
@@ -214,11 +217,13 @@ This article assumes that you've already installed a CentOS (or similar derivati
214217
215218
16. Run the following commands to deprovision the virtual machine and prepare it for provisioning on Azure:
216219
217-
```bash
218-
sudo waagent -force -deprovision+user
219-
export HISTSIZE=0
220-
logout
221-
```
220+
```bash
221+
sudo waagent -force -deprovision+user
222+
sudo export HISTSIZE=0
223+
```
224+
> [!NOTE]
225+
> If you are migrating a specific virtual machine and do not wish to create a generalized image, skip the deprovision step.
226+
222227
223228
17. 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).
224229
@@ -227,14 +232,14 @@ This article assumes that you've already installed a CentOS (or similar derivati
227232
228233
**Changes in CentOS 7 (and similar derivatives)**
229234
230-
Preparing a CentOS 7 virtual machine for Azure is very similar to CentOS 6, however there are several important differences worth noting:
235+
Preparing a CentOS 7 virtual machine for Azure is similar to CentOS 6, however there are several important differences worth noting:
231236
232237
* The NetworkManager package no longer conflicts with the Azure Linux agent. This package is installed by default and we recommend that it'sn't removed.
233238
* GRUB2 is now used as the default bootloader, so the procedure for editing kernel parameters has changed (see below).
234239
* XFS is now the default file system. The ext4 file system can still be used if desired.
235-
* Since CentOS 8 Stream and newer no longer include `network.service` by default, you will need to install it manually:
240+
* Since CentOS 8 Stream and newer no longer include `network.service` by default, you need to install it manually:
236241
237-
```console
242+
```bash
238243
sudo yum install network-scripts
239244
sudo systemctl enable network.service
240245
```
@@ -247,14 +252,14 @@ Preparing a CentOS 7 virtual machine for Azure is very similar to CentOS 6, howe
247252
248253
3. Create or edit the file `/etc/sysconfig/network` and add the following text:
249254
250-
```console
255+
```output
251256
NETWORKING=yes
252257
HOSTNAME=localhost.localdomain
253258
```
254259
255260
4. Create or edit the file `/etc/sysconfig/network-scripts/ifcfg-eth0` and add the following text:
256261
257-
```console
262+
```output
258263
DEVICE=eth0
259264
ONBOOT=yes
260265
BOOTPROTO=dhcp
@@ -273,7 +278,7 @@ Preparing a CentOS 7 virtual machine for Azure is very similar to CentOS 6, howe
273278
274279
6. If you would like to use the OpenLogic mirrors that are hosted within the Azure datacenters, then replace the `/etc/yum.repos.d/CentOS-Base.repo` file with the following repositories. This will also add the **[openlogic]** repository that includes packages for the Azure Linux agent:
275280
276-
```console
281+
```output
277282
[openlogic]
278283
name=CentOS-$releasever - openlogic packages for $basearch
279284
baseurl=http://olcentgbl.trafficmanager.net/openlogic/$releasever/openlogic/$basearch/
@@ -332,17 +337,17 @@ Preparing a CentOS 7 virtual machine for Azure is very similar to CentOS 6, howe
332337
333338
8. Modify the kernel boot line in your grub configuration to include additional kernel parameters for Azure. To do this, open `/etc/default/grub` in a text editor and edit the `GRUB_CMDLINE_LINUX` parameter, for example:
334339
335-
```console
340+
```output
336341
GRUB_CMDLINE_LINUX="rootdelay=300 console=ttyS0 earlyprintk=ttyS0 net.ifnames=0"
337342
```
338343
339344
This will also ensure all console messages are sent to the first serial port, which can assist Azure support with debugging issues. It also turns off the new CentOS 7 naming conventions for NICs. In addition to the above, it's recommended to *remove* the following parameters:
340345
341-
```console
346+
```output
342347
rhgb quiet crashkernel=auto
343348
```
344349
345-
Graphical and quiet boot are not useful in a cloud environment where we want all the logs to be sent to the serial port. The `crashkernel` option may be left configured if desired, but note that this parameter will reduce the amount of available memory in the VM by 128MB or more, which may be problematic on the smaller VM sizes.
350+
Graphical and quiet boot isn't useful in a cloud environment where we want all the logs to be sent to the serial port. The `crashkernel` option may be left configured if desired, but note that this parameter will reduce the amount of available memory in the VM by 128 MB or more, which may be problematic on the smaller VM sizes.
346351
347352
9. Once you're done editing `/etc/default/grub` per above, run the following command to rebuild the grub configuration:
348353
@@ -360,7 +365,7 @@ Preparing a CentOS 7 virtual machine for Azure is very similar to CentOS 6, howe
360365
361366
Edit `/etc/dracut.conf`, add content:
362367
363-
```console
368+
```output
364369
add_drivers+=" hv_vmbus hv_netvsc hv_storvsc "
365370
```
366371
@@ -379,22 +384,25 @@ Preparing a CentOS 7 virtual machine for Azure is very similar to CentOS 6, howe
379384
380385
12. Install cloud-init to handle the provisioning
381386
382-
```console
383-
yum install -y cloud-init cloud-utils-growpart gdisk hyperv-daemons
384-
385-
# Configure waagent for cloud-init
386-
sed -i 's/Provisioning.Agent=auto/Provisioning.Agent=auto/g' /etc/waagent.conf
387-
sed -i 's/ResourceDisk.Format=y/ResourceDisk.Format=n/g' /etc/waagent.conf
388-
sed -i 's/ResourceDisk.EnableSwap=y/ResourceDisk.EnableSwap=n/g' /etc/waagent.conf
389-
390-
echo "Adding mounts and disk_setup to init stage"
391-
sed -i '/ - mounts/d' /etc/cloud/cloud.cfg
392-
sed -i '/ - disk_setup/d' /etc/cloud/cloud.cfg
393-
sed -i '/cloud_init_modules/a\\ - mounts' /etc/cloud/cloud.cfg
394-
sed -i '/cloud_init_modules/a\\ - disk_setup' /etc/cloud/cloud.cfg
395-
396-
echo "Allow only Azure datasource, disable fetching network setting via IMDS"
397-
cat > /etc/cloud/cloud.cfg.d/91-azure_datasource.cfg <<EOF
387+
```bash
388+
sudo yum install -y cloud-init cloud-utils-growpart gdisk hyperv-daemons
389+
```
390+
1. Configure waagent for cloud-init
391+
```bash
392+
sudo sed -i 's/Provisioning.Agent=auto/Provisioning.Agent=auto/g' /etc/waagent.conf
393+
sudo sed -i 's/ResourceDisk.Format=y/ResourceDisk.Format=n/g' /etc/waagent.conf
394+
sudo sed -i 's/ResourceDisk.EnableSwap=y/ResourceDisk.EnableSwap=n/g' /etc/waagent.conf
395+
```
396+
```bash
397+
sudo echo "Adding mounts and disk_setup to init stage"
398+
sudo sed -i '/ - mounts/d' /etc/cloud/cloud.cfg
399+
sudo sed -i '/ - disk_setup/d' /etc/cloud/cloud.cfg
400+
sudo sed -i '/cloud_init_modules/a\\ - mounts' /etc/cloud/cloud.cfg
401+
sudo sed -i '/cloud_init_modules/a\\ - disk_setup' /etc/cloud/cloud.cfg
402+
```
403+
```bash
404+
sudo echo "Allow only Azure datasource, disable fetching network setting via IMDS"
405+
sudo cat > /etc/cloud/cloud.cfg.d/91-azure_datasource.cfg <<EOF
398406
datasource_list: [ Azure ]
399407
datasource:
400408
Azure:
@@ -415,7 +423,6 @@ Preparing a CentOS 7 virtual machine for Azure is very similar to CentOS 6, howe
415423
# there without needing to look on the console.
416424
output: {all: '| tee -a /var/log/cloud-init-output.log'}
417425
EOF
418-
419426
```
420427
421428
@@ -425,18 +432,18 @@ Preparing a CentOS 7 virtual machine for Azure is very similar to CentOS 6, howe
425432
426433
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 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:
427434
428-
```console
429-
sed -i 's/ResourceDisk.Format=y/ResourceDisk.Format=n/g' /etc/waagent.conf
430-
sed -i 's/ResourceDisk.EnableSwap=y/ResourceDisk.EnableSwap=n/g' /etc/waagent.conf
435+
```bash
436+
sudo sed -i 's/ResourceDisk.Format=y/ResourceDisk.Format=n/g' /etc/waagent.conf
437+
sudo sed -i 's/ResourceDisk.EnableSwap=y/ResourceDisk.EnableSwap=n/g' /etc/waagent.conf
431438
```
432439
433440
If you want mount, format and create swap you can either:
434441
* Pass this in as a cloud-init config every time you create a VM
435442
* Use a cloud-init directive baked into the image that will do this every time the VM is created:
436443
437-
```console
438-
echo 'DefaultEnvironment="CLOUD_CFG=/etc/cloud/cloud.cfg.d/00-azure-swap.cfg"' >> /etc/systemd/system.conf
439-
cat > /etc/cloud/cloud.cfg.d/00-azure-swap.cfg << EOF
444+
```bash
445+
sudo echo 'DefaultEnvironment="CLOUD_CFG=/etc/cloud/cloud.cfg.d/00-azure-swap.cfg"' >> /etc/systemd/system.conf
446+
sudo cat > /etc/cloud/cloud.cfg.d/00-azure-swap.cfg << EOF
440447
#cloud-config
441448
# Generated by Azure cloud image build
442449
disk_setup:
@@ -457,15 +464,15 @@ Preparing a CentOS 7 virtual machine for Azure is very similar to CentOS 6, howe
457464
458465
14. Run the following commands to deprovision the virtual machine and prepare it for provisioning on Azure:
459466
460-
**Note:** if you're migrating a specific virtual machine and don't wish to create a generalized image, skip the deprovision step
467+
> [!NOTE]
468+
> If you are migrating a specific virtual machine and don't wish to create a generalized image, skip the deprovision step.
461469
462-
```console
463-
# sudo rm -f /var/log/waagent.log
464-
# sudo cloud-init clean
465-
# waagent -force -deprovision+user
466-
# rm -f ~/.bash_history
467-
# export HISTSIZE=0
468-
# logout
470+
```bash
471+
sudo rm -f /var/log/waagent.log
472+
sudo cloud-init clean
473+
sudo waagent -force -deprovision+user
474+
sudo rm -f ~/.bash_history
475+
sudo export HISTSIZE=0
469476
```
470477
471478
15. 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).

0 commit comments

Comments
 (0)