You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/virtual-machines/linux/disk-encryption-linux.md
+35-69Lines changed: 35 additions & 69 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,34 +37,33 @@ In all cases, you should [take a snapshot](snapshot-copy-managed-disk.md) and/or
37
37
38
38
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.
39
39
40
-
### Azure CLI
40
+
#[Azure CLI](#tab/azcliazure)
41
41
42
42
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).
43
43
44
-
45
-
46
44
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.
47
45
48
46
```azurecli
49
47
az login
50
48
```
51
49
52
50
If you would like to select a tenant to sign in under, use:
53
-
51
+
54
52
```azurecli
55
53
az login --tenant <tenant>
56
54
```
57
55
58
56
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
+
60
58
```azurecli
61
59
az account list
62
60
az account set --subscription "<subscription name or ID>"
63
61
```
64
62
65
63
For more information, see [Get started with Azure CLI 2.0](/cli/azure/get-started-with-azure-cli).
66
64
67
-
### Azure PowerShell
65
+
# [Azure PowerShell](#tab/powershellazure)
66
+
68
67
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).
69
68
70
69
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
89
88
Get-command *diskencryption*
90
89
```
91
90
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
+
---
93
94
94
95
## Enable encryption on an existing or running Linux VM
95
96
@@ -102,7 +103,7 @@ In this scenario, you can enable encryption by using the Resource Manager templa
102
103
103
104
To disable the encryption, see [Disable encryption and remove the encryption extension](#disable-encryption-and-remove-the-encryption-extension).
104
105
105
-
### Enable encryption on an existing or running Linux VM using Azure CLI
106
+
#[Using Azure CLI](#tab/enableadecli)
106
107
107
108
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:
az vm encryption show --name "MySecureVM" --resource-group "MyVirtualMachineResourceGroup"
133
134
```
135
+
134
136
To disable the encryption, see [Disable encryption and remove the encryption extension](#disable-encryption-and-remove-the-encryption-extension).
135
137
136
-
### Enable encryption on an existing or running Linux VM using PowerShell
138
+
# [Using PowerShell](#tab/enableadeps)
137
139
138
140
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.
139
141
@@ -151,6 +153,7 @@ Use the [Set-AzVMDiskEncryptionExtension](/powershell/module/az.compute/set-azvm
- **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.
To disable the encryption, see [Disable encryption and remove the encryption extension](#disable-encryption-and-remove-the-encryption-extension).
184
187
185
-
186
-
### Enable encryption on an existing or running Linux VM with a template
188
+
# [Using a Resource Manager template](#tab/enableadearm)
187
189
188
190
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).
189
191
@@ -207,6 +209,8 @@ For more information about configuring the Linux VM disk encryption template, se
207
209
208
210
To disable the encryption, see [Disable encryption and remove the encryption extension](#disable-encryption-and-remove-the-encryption-extension).
209
211
212
+
---
213
+
210
214
## Use EncryptFormatAll feature for data disks on Linux VMs
211
215
212
216
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
218
222
>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.
219
223
220
224
### EncryptFormatAll criteria
225
+
221
226
The parameter goes through all partitions and encrypts them as long as they meet **all** of the criteria below:
227
+
222
228
- Is not a root/OS/boot partition
223
229
- Is not already encrypted
224
230
- Is not a BEK volume
@@ -228,7 +234,8 @@ The parameter goes through all partitions and encrypts them as long as they meet
228
234
229
235
Encrypt the disks that compose the RAID or LVM volume rather than the RAID or LVM volume.
230
236
231
-
### Use the EncryptFormatAll parameter with Azure CLI
237
+
# [Use the EncryptFormatAll parameter with Azure CLI](#tab/efacli)
238
+
232
239
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.
233
240
234
241
- **Encrypt a running VM using EncryptFormatAll:**
@@ -237,7 +244,8 @@ Use the [az vm encryption enable](/cli/azure/vm/encryption#az-vm-encryption-enab
237
244
az vm encryption enable --resource-group "MyVirtualMachineResourceGroup" --name "MySecureVM" --disk-encryption-keyvault "MySecureVault" --volume-type "data" --encrypt-format-all
238
245
```
239
246
240
-
### Use the EncryptFormatAll parameter with a PowerShell cmdlet
247
+
# [Use the EncryptFormatAll parameter with a PowerShell cmdlet](#tab/efaps)
248
+
241
249
Use the [Set-AzVMDiskEncryptionExtension](/powershell/module/az.compute/set-azvmdiskencryptionextension) cmdlet with the EncryptFormatAll parameter.
242
250
243
251
**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.
### 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
1. Run the Azure PowerShell [Set-AzVMDiskEncryptionExtension](/powershell/module/az.compute/set-azvmdiskencryptionextension) cmdlet with -EncryptFormatAll to encrypt these disks.
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:
### Use the EncryptFormatAll parameter with Logical Volume Manager (LVM)
303
268
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).
305
270
306
271
## New VMs created from customer-encrypted VHD and encryption keys
272
+
307
273
In this scenario, you can enable encrypting by using PowerShell cmdlets or CLI commands.
308
274
309
275
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
315
281
>
316
282
> Encrypting or disabling encryption may cause the VM to reboot.
317
283
284
+
### Use Azure PowerShell to encrypt VMs with pre-encrypted VHDs
318
285
319
-
320
-
### Use Azure PowerShell to encrypt VMs with pre-encrypted VHDs
321
286
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.
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.
332
297
333
-
### Enable encryption on a newly added disk with Azure CLI
298
+
#[Using Azure CLI](#tab/adedatacli)
334
299
335
300
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).
336
301
@@ -348,9 +313,9 @@ In contrast to PowerShell syntax, the CLI does not require the user to provide a
348
313
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"
349
314
```
350
315
351
-
### Enable encryption on a newly added disk with Azure PowerShell
316
+
# [Using Azure PowerShell](#tab/adedataps)
317
+
352
318
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
-
354
319
355
320
- **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.
356
321
@@ -366,6 +331,7 @@ In contrast to PowerShell syntax, the CLI does not require the user to provide a
- **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.
370
336
371
337
```azurepowershell
@@ -389,8 +355,9 @@ In contrast to PowerShell syntax, the CLI does not require the user to provide a
389
355
> The syntax for the value of the key-encryption-key parameter is the full URI to the KEK as in:
0 commit comments