Wednesday, June 15, 2022

Cannot Safely Remove USB Drive on Windows 10? Use Diskpart

From time to time, I cannot safely remove or eject a USB drive. The reason is that one or more processes locks some files. For instance, I observed the following files were locked by a svchost.exe process on the USB drive F:,

F:\$Extended$
F:\System Volume Information\

The method that works consistently for me is to use Diskpart. Note this requires administrative privilege.   Below is an example to remove the external drive (shown as Disk 1),

C:> diskpart
DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          465 GB  1024 KB        *
  Disk 1    Online         1862 GB      0 B

DISKPART> select disk 1

Disk 1 is now the selected disk.

DISKPART> offline disk

DiskPart successfully offlined the selected disk.

DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          465 GB  1024 KB        *
* Disk 1    Offline        1862 GB      0 B

To bring the disk back online without re-plugging it, we do the steps illustrated in the example below,
C:> diskpart
DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          465 GB  1024 KB        *
* Disk 1    Offline        1862 GB      0 B

DISKPART> select disk 1

Disk 1 is now the selected disk.

DISKPART> online disk

DiskPart successfully onlined the selected disk.

DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          465 GB  1024 KB        *
* Disk 1    Online         1862 GB      0 B

DISKPART>

Wednesday, June 1, 2022

Removing OpenVPN 2 Private Key Password

I wanted to remove the password protection for a OpenVPN 2 client private key. The solution is to use the ssh-keygen command. For instance, assuming the key file is client_private_key.key, we run

ssh-keygen -p -N "" -m pem -f client_private_key.key

The key file will be replaced by the key without the password protection.

Before I figured out this solution for OpenVPN 2, I ran into a problem. That is, I ran the following command instead,

ssh-keygen -p -N "" -f client_private_key.key

where there is no "-m" option to specify "pem" as the format of the key file and the key file is in the default PKCS 8 format. Then when I attempted to restart the OpenVPN 2 client, I saw in the log,

Error: private key password verification failed

The message is misleading in this case because the actual problem is that OpenVPN 2 does not recognize the PKCS 8 format. To correct the problem, we just need to run the ssh-keygen again and this time we specify the pem format as the file format, i.e.,

ssh-keygen -p -N "" -m pem -f client_private_key.key

Of course, in retrospective, I should have had run this command from the beginning with.