Skip to content

Commit 92abef0

Browse files
Merge pull request #232520 from divargas-msft/patch-2
[Doc-a-thon] Updating disk-encryption-linux
2 parents 222ed6b + e63c81f commit 92abef0

File tree

1 file changed

+35
-69
lines changed

1 file changed

+35
-69
lines changed

articles/virtual-machines/linux/disk-encryption-linux.md

Lines changed: 35 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,33 @@ In all cases, you should [take a snapshot](snapshot-copy-managed-disk.md) and/or
3737

3838
Azure Disk Encryption can be enabled and managed through the [Azure CLI](/cli/azure) and [Azure PowerShell](/powershell/azure/new-azureps-module-az). To do so, you must install the tools locally and connect to your Azure subscription.
3939

40-
### Azure CLI
40+
# [Azure CLI](#tab/azcliazure)
4141

4242
The [Azure CLI 2.0](/cli/azure) is a command-line tool for managing Azure resources. The CLI is designed to flexibly query data, support long-running operations as non-blocking processes, and make scripting easy. You can install it locally by following the steps in [Install the Azure CLI](/cli/azure/install-azure-cli).
4343

44-
45-
4644
To [Sign in to your Azure account with the Azure CLI](/cli/azure/authenticate-azure-cli), use the [az login](/cli/azure/reference-index#az-login) command.
4745

4846
```azurecli
4947
az login
5048
```
5149

5250
If you would like to select a tenant to sign in under, use:
53-
51+
5452
```azurecli
5553
az login --tenant <tenant>
5654
```
5755

5856
If you have multiple subscriptions and want to specify a specific one, get your subscription list with [az account list](/cli/azure/account#az-account-list) and specify with [az account set](/cli/azure/account#az-account-set).
59-
57+
6058
```azurecli
6159
az account list
6260
az account set --subscription "<subscription name or ID>"
6361
```
6462

6563
For more information, see [Get started with Azure CLI 2.0](/cli/azure/get-started-with-azure-cli).
6664

67-
### Azure PowerShell
65+
# [Azure PowerShell](#tab/powershellazure)
66+
6867
The [Azure PowerShell az module](/powershell/azure/new-azureps-module-az) provides a set of cmdlets that uses the [Azure Resource Manager](../../azure-resource-manager/management/overview.md) model for managing your Azure resources. You can use it in your browser with [Azure Cloud Shell](../../cloud-shell/overview.md), or you can install it on your local machine using the instructions in [Install the Azure PowerShell module](/powershell/azure/install-az-ps).
6968

7069
If you already have it installed locally, make sure you use the latest version of Azure PowerShell SDK version to configure Azure Disk Encryption. Download the latest version of [Azure PowerShell release](https://github.com/Azure/azure-powershell/releases).
@@ -89,7 +88,9 @@ To confirm the Azure Disk Encryption cmdlets are installed, use the [Get-command
8988
Get-command *diskencryption*
9089
```
9190

92-
For more information, see [Getting started with Azure PowerShell](/powershell/azure/get-started-azureps).
91+
For more information, see [Getting started with Azure PowerShell](/powershell/azure/get-started-azureps).
92+
93+
---
9394

9495
## Enable encryption on an existing or running Linux VM
9596

@@ -102,7 +103,7 @@ In this scenario, you can enable encryption by using the Resource Manager templa
102103
103104
To disable the encryption, see [Disable encryption and remove the encryption extension](#disable-encryption-and-remove-the-encryption-extension).
104105

105-
### Enable encryption on an existing or running Linux VM using Azure CLI
106+
# [Using Azure CLI](#tab/enableadecli)
106107

107108
You can enable disk encryption on your encrypted VHD by installing and using the [Azure CLI](/cli/azure/) command-line tool. You can use it in your browser with [Azure Cloud Shell](../../cloud-shell/overview.md), or you can install it on your local machine and use it in any PowerShell session. To enable encryption on existing or running Linux VMs in Azure, use the following CLI commands:
108109

@@ -131,9 +132,10 @@ https://[keyvault-name].vault.azure.net/keys/[kekname]/[kek-unique-id]
131132
```azurecli-interactive
132133
az vm encryption show --name "MySecureVM" --resource-group "MyVirtualMachineResourceGroup"
133134
```
135+
134136
To disable the encryption, see [Disable encryption and remove the encryption extension](#disable-encryption-and-remove-the-encryption-extension).
135137
136-
### Enable encryption on an existing or running Linux VM using PowerShell
138+
# [Using PowerShell](#tab/enableadeps)
137139
138140
Use the [Set-AzVMDiskEncryptionExtension](/powershell/module/az.compute/set-azvmdiskencryptionextension) cmdlet to enable encryption on a running virtual machine in Azure. Take a [snapshot](snapshot-copy-managed-disk.md) and/or back up the VM with [Azure Backup](../../backup/backup-azure-vms-encryption.md) before disks are encrypted. The -skipVmBackup parameter is already specified in the PowerShell scripts to encrypt a running Linux VM.
139141
@@ -151,6 +153,7 @@ Use the [Set-AzVMDiskEncryptionExtension](/powershell/module/az.compute/set-azvm
151153
152154
Set-AzVMDiskEncryptionExtension -ResourceGroupName $VMRGName -VMName $vmName -DiskEncryptionKeyVaultUrl $diskEncryptionKeyVaultUrl -DiskEncryptionKeyVaultId $KeyVaultResourceId -VolumeType '[All|OS|Data]' -SequenceVersion $sequenceVersion -skipVmBackup;
153155
```
156+
154157
- **Encrypt a running VM using KEK:** You may need to add the -VolumeType parameter if you're encrypting data disks and not the OS disk.
155158
156159
```azurepowershell
@@ -173,17 +176,16 @@ Use the [Set-AzVMDiskEncryptionExtension](/powershell/module/az.compute/set-azvm
173176
/subscriptions/[subscription-id-guid]/resourceGroups/[resource-group-name]/providers/Microsoft.KeyVault/vaults/[keyvault-name]</br>
174177
> The syntax for the value of the key-encryption-key parameter is the full URI to the KEK as in:
175178
https://[keyvault-name].vault.azure.net/keys/[kekname]/[kek-unique-id]
176-
177-
- **Verify the disks are encrypted:** To check on the encryption status of a VM, use the [Get-AzVmDiskEncryptionStatus](/powershell/module/az.compute/get-azvmdiskencryptionstatus) cmdlet.
178-
179+
180+
- **Verify the disks are encrypted:** To check on the encryption status of a VM, use the [Get-AzVmDiskEncryptionStatus](/powershell/module/az.compute/get-azvmdiskencryptionstatus) cmdlet.
181+
179182
```azurepowershell-interactive
180183
Get-AzVmDiskEncryptionStatus -ResourceGroupName 'MyVirtualMachineResourceGroup' -VMName 'MySecureVM'
181184
```
182185
183186
To disable the encryption, see [Disable encryption and remove the encryption extension](#disable-encryption-and-remove-the-encryption-extension).
184187
185-
186-
### Enable encryption on an existing or running Linux VM with a template
188+
# [Using a Resource Manager template](#tab/enableadearm)
187189
188190
You can enable disk encryption on an existing or running Linux VM in Azure by using the [Resource Manager template](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.compute/encrypt-running-linux-vm-without-aad).
189191
@@ -207,6 +209,8 @@ For more information about configuring the Linux VM disk encryption template, se
207209
208210
To disable the encryption, see [Disable encryption and remove the encryption extension](#disable-encryption-and-remove-the-encryption-extension).
209211
212+
---
213+
210214
## Use EncryptFormatAll feature for data disks on Linux VMs
211215
212216
The **EncryptFormatAll** parameter reduces the time for Linux data disks to be encrypted. Partitions meeting certain criteria will be formatted, along with their current file systems, then remounted back to where they were before command execution. If you wish to exclude a data disk that meets the criteria, you can unmount it before running the command.
@@ -218,7 +222,9 @@ The **EncryptFormatAll** parameter reduces the time for Linux data disks to be e
218222
>If you're setting this parameter while updating encryption settings, it might lead to a reboot before the actual encryption. In this case, you will also want to remove the disk you don't want formatted from the fstab file. Similarly, you should add the partition you want encrypt-formatted to the fstab file before initiating the encryption operation.
219223
220224
### EncryptFormatAll criteria
225+
221226
The parameter goes through all partitions and encrypts them as long as they meet **all** of the criteria below:
227+
222228
- Is not a root/OS/boot partition
223229
- Is not already encrypted
224230
- Is not a BEK volume
@@ -228,7 +234,8 @@ The parameter goes through all partitions and encrypts them as long as they meet
228234
229235
Encrypt the disks that compose the RAID or LVM volume rather than the RAID or LVM volume.
230236
231-
### Use the EncryptFormatAll parameter with Azure CLI
237+
# [Use the EncryptFormatAll parameter with Azure CLI](#tab/efacli)
238+
232239
Use the [az vm encryption enable](/cli/azure/vm/encryption#az-vm-encryption-enable) command to enable encryption on a running virtual machine in Azure.
233240
234241
- **Encrypt a running VM using EncryptFormatAll:**
@@ -237,7 +244,8 @@ Use the [az vm encryption enable](/cli/azure/vm/encryption#az-vm-encryption-enab
237244
az vm encryption enable --resource-group "MyVirtualMachineResourceGroup" --name "MySecureVM" --disk-encryption-keyvault "MySecureVault" --volume-type "data" --encrypt-format-all
238245
```
239246
240-
### Use the EncryptFormatAll parameter with a PowerShell cmdlet
247+
# [Use the EncryptFormatAll parameter with a PowerShell cmdlet](#tab/efaps)
248+
241249
Use the [Set-AzVMDiskEncryptionExtension](/powershell/module/az.compute/set-azvmdiskencryptionextension) cmdlet with the EncryptFormatAll parameter.
242250
243251
**Encrypt a running VM using EncryptFormatAll:** As an example, the script below initializes your variables and runs the Set-AzVMDiskEncryptionExtension cmdlet with the EncryptFormatAll parameter. The resource group, VM, and key vault were created as prerequisites. Replace MyVirtualMachineResourceGroup, MySecureVM, and MySecureVault with your values.
@@ -254,56 +262,14 @@ $KeyVaultResourceId = $KeyVault.ResourceId;
254262
Set-AzVMDiskEncryptionExtension -ResourceGroupName $VMRGName -VMName $vmName -DiskEncryptionKeyVaultUrl $diskEncryptionKeyVaultUrl -DiskEncryptionKeyVaultId $KeyVaultResourceId -VolumeType "data" -EncryptFormatAll
255263
```
256264

265+
---
257266

258-
### Use the EncryptFormatAll parameter with Logical Volume Manager (LVM)
259-
We recommend an LVM-on-crypt setup. For all the following examples, replace the device-path and mountpoints with whatever suits your use-case. This setup can be done as follows:
260-
261-
1. Add the data disks that will compose the VM.
262-
263-
1. Format, mount, and add these disks to the fstab file.
264-
265-
1. Choose a partition standard, create a partition that spans the entire drive, and then format the partition. We use symlinks generated by Azure here. Using symlinks avoids problems related to device names changing. For more information, see the [Troubleshoot Device Names problems](/troubleshoot/azure/virtual-machines/troubleshoot-device-names-problems) article.
266-
267-
```bash
268-
parted /dev/disk/azure/scsi1/lun0 mklabel gpt
269-
parted -a opt /dev/disk/azure/scsi1/lun0 mkpart primary ext4 0% 100%
270-
271-
mkfs -t ext4 /dev/disk/azure/scsi1/lun0-part1
272-
```
273-
274-
1. Mount the disks:
275-
276-
```bash
277-
mount /dev/disk/azure/scsi1/lun0-part1 /mnt/mountpoint
278-
````
279-
280-
Add to fstab file:
281-
282-
```bash
283-
echo "/dev/disk/azure/scsi1/lun0-part1 /mnt/mountpoint ext4 defaults,nofail 0 2" >> /etc/fstab
284-
```
285-
286-
1. Run the Azure PowerShell [Set-AzVMDiskEncryptionExtension](/powershell/module/az.compute/set-azvmdiskencryptionextension) cmdlet with -EncryptFormatAll to encrypt these disks.
287-
288-
```azurepowershell-interactive
289-
$KeyVault = Get-AzKeyVault -VaultName "MySecureVault" -ResourceGroupName "MySecureGroup"
290-
291-
Set-AzVMDiskEncryptionExtension -ResourceGroupName "MySecureGroup" -VMName "MySecureVM" -DiskEncryptionKeyVaultUrl $KeyVault.VaultUri -DiskEncryptionKeyVaultId $KeyVault.ResourceId -EncryptFormatAll -SkipVmBackup -VolumeType Data
292-
```
293-
294-
If you wish to use a key encryption key (KEK), pass the URI of your KEK and the ResourceID of your key vault to the -KeyEncryptionKeyUrl and -KeyEncryptionKeyVaultId parameters, respectively:
295-
296-
```azurepowershell-interactive
297-
$KeyVault = Get-AzKeyVault -VaultName "MySecureVault" -ResourceGroupName "MySecureGroup"
298-
$KEKKeyVault = Get-AzKeyVault -VaultName "MyKEKVault" -ResourceGroupName "MySecureGroup"
299-
$KEK = Get-AzKeyVaultKey -VaultName "myKEKVault" -KeyName "myKEKName"
300-
301-
Set-AzVMDiskEncryptionExtension -ResourceGroupName "MySecureGroup" -VMName "MySecureVM" -DiskEncryptionKeyVaultUrl $KeyVault.VaultUri -DiskEncryptionKeyVaultId $KeyVault.ResourceId -EncryptFormatAll -SkipVmBackup -VolumeType Data -KeyEncryptionKeyUrl $$KEK.id -KeyEncryptionKeyVaultId $KEKKeyVault.ResourceId
302-
```
267+
### Use the EncryptFormatAll parameter with Logical Volume Manager (LVM)
303268

304-
1. Set up LVM on top of these new disks. Note the encrypted drives are unlocked after the VM has finished booting. So, the LVM mounting will also have to be subsequently delayed.
269+
We recommend an LVM-on-crypt setup. For detailed instructions about the LVM on crypt configuration, see [Configure LVM and RAID on ADE encrypted devices](/azure/virtual-machines/linux/how-to-configure-lvm-raid-on-crypt).
305270

306271
## New VMs created from customer-encrypted VHD and encryption keys
272+
307273
In this scenario, you can enable encrypting by using PowerShell cmdlets or CLI commands.
308274

309275
Use the instructions in the Azure Disk encryption same scripts for preparing pre-encrypted images that can be used in Azure. After the image is created, you can use the steps in the next section to create an encrypted Azure VM.
@@ -315,9 +281,8 @@ Use the instructions in the Azure Disk encryption same scripts for preparing pre
315281
>
316282
> Encrypting or disabling encryption may cause the VM to reboot.
317283
284+
### Use Azure PowerShell to encrypt VMs with pre-encrypted VHDs
318285

319-
320-
### Use Azure PowerShell to encrypt VMs with pre-encrypted VHDs
321286
You can enable disk encryption on your encrypted VHD by using the PowerShell cmdlet [Set-AzVMOSDisk](/powershell/module/Az.Compute/Set-AzVMOSDisk#examples). The example below gives you some common parameters.
322287

323288
```azurepowershell
@@ -330,7 +295,7 @@ New-AzVM -VM $VirtualMachine -ResourceGroupName "MyVirtualMachineResourceGroup"
330295

331296
You can add a new data disk using [az vm disk attach](add-disk.md), or [through the Azure portal](attach-disk-portal.md). Before you can encrypt, you need to mount the newly attached data disk first. You must request encryption of the data drive since the drive will be unusable while encryption is in progress.
332297

333-
### Enable encryption on a newly added disk with Azure CLI
298+
# [Using Azure CLI](#tab/adedatacli)
334299

335300
If the VM was previously encrypted with "All" then the --volume-type parameter should remain "All". All includes both OS and data disks. If the VM was previously encrypted with a volume type of "OS", then the --volume-type parameter should be changed to "All" so that both the OS and the new data disk will be included. If the VM was encrypted with only the volume type of "Data", then it can remain "Data" as demonstrated below. Adding and attaching a new data disk to a VM is not sufficient preparation for encryption. The newly attached disk must also be formatted and properly mounted within the VM prior to enabling encryption. On Linux the disk must be mounted in /etc/fstab with a [persistent block device name](/troubleshoot/azure/virtual-machines/troubleshoot-device-names-problems).
336301

@@ -348,9 +313,9 @@ In contrast to PowerShell syntax, the CLI does not require the user to provide a
348313
az vm encryption enable --resource-group "MyVirtualMachineResourceGroup" --name "MySecureVM" --disk-encryption-keyvault "MySecureVault" --key-encryption-key "MyKEK_URI" --key-encryption-keyvault "MySecureVaultContainingTheKEK" --volume-type "Data"
349314
```
350315
351-
### Enable encryption on a newly added disk with Azure PowerShell
316+
# [Using Azure PowerShell](#tab/adedataps)
317+
352318
When using PowerShell to encrypt a new disk for Linux, a new sequence version needs to be specified. The sequence version has to be unique. The script below generates a GUID for the sequence version. Take a [snapshot](snapshot-copy-managed-disk.md) and/or back up the VM with [Azure Backup](../../backup/backup-azure-vms-encryption.md) before disks are encrypted. The -skipVmBackup parameter is already specified in the PowerShell scripts to encrypt a newly added data disk.
353-
354319
355320
- **Encrypt data volumes of a running VM:** The script below initializes your variables and runs the Set-AzVMDiskEncryptionExtension cmdlet. The resource group, VM, and key vault should have already been created as prerequisites. Replace MyVirtualMachineResourceGroup, MySecureVM, and MySecureVault with your values. Acceptable values for the -VolumeType parameter are All, OS, and Data. If the VM was previously encrypted with a volume type of "OS" or "All", then the -VolumeType parameter should be changed to "All" so that both the OS and the new data disk will be included.
356321
@@ -366,6 +331,7 @@ In contrast to PowerShell syntax, the CLI does not require the user to provide a
366331
367332
Set-AzVMDiskEncryptionExtension -ResourceGroupName $VMRGName -VMName $vmName -DiskEncryptionKeyVaultUrl $diskEncryptionKeyVaultUrl -DiskEncryptionKeyVaultId $KeyVaultResourceId -VolumeType 'data' –SequenceVersion $sequenceVersion -skipVmBackup;
368333
```
334+
369335
- **Encrypt data volumes of a running VM using KEK:** Acceptable values for the -VolumeType parameter are All, OS, and Data. If the VM was previously encrypted with a volume type of "OS" or "All", then the -VolumeType parameter should be changed to All so that both the OS and the new data disk will be included.
370336
371337
```azurepowershell
@@ -389,8 +355,9 @@ In contrast to PowerShell syntax, the CLI does not require the user to provide a
389355
> The syntax for the value of the key-encryption-key parameter is the full URI to the KEK as in:
390356
https://[keyvault-name].vault.azure.net/keys/[kekname]/[kek-unique-id]
391357
392-
## Disable encryption and remove the encryption extension
358+
---
393359
360+
## Disable encryption and remove the encryption extension
394361
395362
You can disable the Azure disk encryption extension, and you can remove the Azure disk encryption extension. These are two distinct operations.
396363
@@ -441,7 +408,6 @@ You can remove the encryption extension using Azure PowerShell or the Azure CLI.
441408
az vm extension delete -g "MyVirtualMachineResourceGroup" --vm-name "MySecureVM" -n "AzureDiskEncryptionForLinux"
442409
```
443410
444-
445411
## Unsupported scenarios
446412
447413
Azure Disk Encryption does not work for the following Linux scenarios, features, and technology:

0 commit comments

Comments
 (0)