HOWTO - Create UEFI Shell bootable thumb drivePost Date: 2020-12-15 |
Post Reply
|
| Author | |
ErikW
Newbie
Joined: 26 Aug 2020 Online Status: Offline Posts: 22 |
Quote Reply
Topic: HOWTO - Create UEFI Shell bootable thumb drivePosted: 15 Dec 2020 at 7:38pm |
|
This tutorial explains how to create a thumb drive that boots to the UEFI shell. You will need to download a copy of the UEFI Shell. You can get that by downloading the rEFInd ISO or flash image. The file is "\EFI\tools\shellx64.efi". Or, you can download the shell from Github and other locations.
You can use these same instructions to create any kind of UEFI bootable hard disk media. The "\EFI\BOOT\BOOTX64.EFI" file will be booted unless you create a firmware boot entry to boot something else. For example, to make a Windows boot disk you copy "BOOTMGFW.EFI" to "\EFI\BOOT\BOOTX64.EFI". Here is how you create the thumb drive using Windows 10. It is helpful if you start with a thumb drive that has a unique filesystem label or unique files on it that you can recognize. The contents will be erased. First, plug in the thumb drive. Look to see what drive letter Windows assigns to the thumb drive and the label for the filesystem so that you can recognize it later. Right click the start icon on the task bar and then left click on "Disk Management". Look at the list of disks and partitions. Note which disk number is assigned to your thumb drive. If that isn't clear to you, then eject the thumb drive, or use the icon at the right of the task bar to safely remove it. You should see one of the disks disappear from the list in Disk Management. Plug the thumb drive in again and look to see which drive reappears in Disk Management. The disk number will be used for DISKPART commands, so make a note of it. Remove all the drive letters assigned to the thumb drive if there are any. Right click on the partition in the drive diagram then click "Change Drive letter and Paths..." Verify that you see the same drive letter that you want to remove. Click the "Remove" button and then click "Yes" and "OK" to confirm the removal. Note the location of your UEFI Shell executable file. It is probably named "shellx64.efi". I will assume that is the name, but that really doesn't matter so long as you use the correct name when creating boot entries or copying files. You might want to copy it to a more convenient location, perhaps even "C:\" for now. To prepare the flash drive you need to start a Windows Command Prompt running as an Administrator. You can find that in the start menu folder "Windows System". Right click on "Command Prompt" and then choose "More" (if needed) and "Run as administrator". Click "Yes" to allow the Command Prompt to run. Most of these steps will be done by typing commands into the DISKPART utility. I will show those commands to the right of "DISKPART>", the prompt from the utility. Don't type in the "DISKPART>" to the left of commands, you will only have to type "DISKPART" once at the command prompt to run DISKPART. The normal Windows Command prompt shows the default drive and directory. It starts out as "C:\Windows\System32" but I am just going to show that pompt as "C:\>". Don't type the "C:\>" as part of the commands. First, change the default directory to the location of the UEFI Shell executable file. The command prompt will be the default "C:\Windows\System32>" Type "cd" and everything after that below. C:\Windows\System32> cd /d C:\ If your file is located somewhere else, then use that directory path instead of "C:\". you should be able to see your file with the "DIR" command. C:\> dir Now it's time to start the DISKPART utility, so type in "DISKPART" and press the Enter key to start the program. C:\> diskpart You should see something similar to this. Microsoft DiskPart version 10.0.19041.610 Copyright (C) Microsoft Corporation. On computer: SOMECOMPUTERNAME DISKPART> The rest of the commands will be for DISKPART. First, display the disk drives using the following command. DISKPART> list disk You will see a list of the connected disks. Disk ### Status Size Free Dyn Gpt -------- ------------- ------- ------- --- --- Disk 0 Online 100 GB 1024 KB Disk 1 Online 7437 MB 0 B * The example above shows a 100 GB disk that is obviously the OS or important files, and an approximately 8 GB thumb drive. The thumb drive is disk 1.Find the disk number for your thumb drive. It will probably still be the same disk number that you saw in Disk Management, but you can double check by looking at the size. The next command will select the thumb drive for subsequent commands. DISKPART> select disk 1 Disk 1 is now the selected disk. Replace the "1" with the correct disk number. It is very important that you use the correct disk number, or you may delete your operating system or important files! List the partitions on the disk to make sure that you have the correct one. DISKPART> list partition Partition ### Type Size Offset ------------- ---------------- ------- ------- Partition 1 System 6159 KB 1024 KB Partition 2 Reserved 32 MB 8 MB Partition 3 Primary 7397 MB 40 MB Notice that the sizes are about right for an 8 GB thumb drive. To be really sure that you have the correct disk, you can also look at volumes (filesystems). DISKPART> list volume Volume ### Ltr Label Fs Type Size Status Info ---------- --- ----- ------ ----- ---------- ------- --------- -------- Volume 0 D CD-ROM 0 B No Media Volume 1 EFISys NTFS Partition 50 MB Healthy System Volume 2 C Win 10 NTFS Partition 99 GB Healthy Boot Volume 3 NTFS Partition 505 MB Healthy Hidden Volume 4 G Blade 1 FAT32 Removable 7397 MB Healthy Notice that the type for the thumb drive says "Removable" and the size matches a partition shown in the list. If you selected the wrong disk, then use "list disk" again and "select disk" with the correct disk number. The next command will immediately delete everything on the selected disk. You will NOT get an "are you sure" prompt! DISKPART> clean DiskPart succeeded in cleaning the disk. Now there are no partitions on the disk. You have to create at least the EFI System Partition ESP. What size should you make your EFI System Partition? It depends on the size of the disk and what you plan to put in the EFI System Partition. On 1 TB and larger disks I usually create a 550 MB EFI System Partition. That's around where FAT32 is efficient to use. It's way more than I ever expect to need, and it is still only a tiny fraction of the disk. For a thumb drive that is 8 GB to 256 GB, I would use 100 MB, but you may be able to use a size as small as 20 MB or less. I am going to use 100 MB in the examples below. Windows 10 is picky about what kind of partitions it can format on external drives, and what kind of partitions can be assigned drive letters. An EFI System Partition is one of the types that DISKPART CANNOT format or assign a drive letter. So, the easiest approach is to create an ordinary basic data partition first, format it, assign a drive letter and copy files. After all the files are in the partition, then you can change it to an EFI System Partition. If you need to make changes later, you can assign a drive letter using "mountvol" or temporarily change the type back to "basic data". Use this command to initially create a basic data partition that will later be changed to an EFI System Partition. NOTE: You can copy the long GUID following "id=" from the help for the command. It is the GUID for a basic data partition. DISKPART> help create partition primary ... DISKPART> create partition primary size=100 id=ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 DiskPart succeeded in creating the specified partition. Verify that the partition was created and is correct. DISKPART> list partition Partition ### Type Size Offset ------------- ---------------- ------- ------- * Partition 1 System 100 MB 1024 KB If the partition is correct, select the partition. DISKPART> select partition 1 Partition 1 is now the selected partition. Format the partition with the FAT32 file-system. DISKPART> format fs=fat32 label="EFI System" 100 percent completed DiskPart successfully formatted the volume. Finally, assign a drive letter to the new volume. I used "U" but it can be any available drive letter. DISKPART> assign letter=U DiskPart successfully assigned the drive letter or mount point. Exit from DISKPART. NOTE: The next steps are done using the Windows Command prompt. You can use the Windows graphical file Explorer instead. If you use Explorer, don't exit from "DISKPART". DISKPART will be used again later. DISKPART> exit Leaving DiskPart... C:\> At this point it is time to create the directories and copy the files for the partition. I'm assuming that you changed the default directory to the one containing the EFI Shell executable file. If you didn't, then either do so now, or type in the full file path for the files you want to copy. To make an external drive bootable with UEFI using no special boot entries, it has to have the file "\EFI\BOOT\BOOTX64.EFI". That is all you need, unless that executable program requires other files. The UEFI shell does not require other files, but you may want drivers for other filesystems (ISO, ext4, etc.). Create the directories that you want in the partition. C:\> mkdir U:\EFI C:\> mkdir U:\EFI\BOOT Copy the file that you want to boot by default. You might want other files in the partition, or a second copy of the executable file. C:\> mkdir U:\EFI\SHELL C:\> copy shellx64.efi U:\EFI\SHELL\SHELLX64.EFI The capitalization of file names makes no difference to Windows or UEFI After all the files are in the partition, you can use this command to get a diagram of your directories and files. C:\> tree /f U:\ Volume serial number is E6AD-8F64 U:\ └───EFI ├───BOOT │ BOOTX64.EFI │ └───SHELL SHELLX64.EFI The last thing to do is change the partition type to EFI System Partition. The DISKPART program must be used to do that. If you didn't exit from DISKPART then you don't need to type the next command to start DISKPART. C:\> diskpart List the disks and select the correct disk number assigned to the thumb drive. DISKPART> list disk Disk ### Status Size Free Dyn Gpt -------- ------------- ------- ------- --- --- Disk 0 Online 100 GB 1024 KB Disk 1 Online 7437 MB 7336 MB * DISKPART> select disk 1 Disk 1 is now the selected disk. List the partitions on the disk. There should be only one. Verify that it is the partition created on the thumb drive. If you followed the example it will have a size of 100 MB. DISKPART> list partition Partition ### Type Size Offset ------------- ---------------- ------- ------- Partition 1 Primary 100 MB 1024 KB Select the partition. DISKPART> select partition 1 Partition 1 is now the selected partition. Change the partition type to EFI System Partition using the following command. NOTE: You can copy the long GUID following "id=" from the help for the command. It is the GUID for a an EFI System Partition DISKPART> help set id ... DISKPART> set id=c12a7328-f81f-11d2-ba4b-00a0c93ec93bDiskPart successfully set the partition ID. DISKPART> list partition Partition ### Type Size Offset ------------- ---------------- ------- ------- * Partition 1 System 100 MB 1024 KB Exit from DISKPART. DISKPART> exit Leaving DiskPart... C:\> You are done with the command prompt, so you can exit from that. C:\> exit You can eject the thumb drive or use the "safely remove hardware" icon, then unplug the thumb drive. When you plug in the drive, if you want to remove the drive letter from the thumb drive, or assign a different one, then you must use the "mountvol" command as Administrator. C:\> mountvol U: /d C:\> mountvol U: \\?\Volume{a8c73893-3db3-11eb-9a36-0800270f42f3}\ It may be difficult to figure out the correct volume ID. You can list them using just the command "mountvol" with nothing after it. Use that command before plugging in the thumb drive and then after plugging in the thumb drive. The new volumes that appear are on the thumb drive. If there is no drive letter assigned, then "NO MOUNT POINTS" will appear after the volume ID on the next line. You only have to change the partition type back to "basic data" if you want to use DISKPART to format the drive. The behavior of external drives has been changed many times in Windows, so don't be surprised if things don't work exactly the way I described. If you need to access your live EFI System Partition on the hard disk that you booted, the above steps will not work. The way that you assign a drive letter to that partition, and what you are allowed to do depends on the version of Windows 10. Newer versions of Windows 10 require you to use this command to assign a drive letter to the live EFI System Partition. C:\> mountvol U: /s You remove the drive letter with "mountvol" in the normal way. C:\> mountvol U: /d With newer versions of Windows 10, you cannot display or modify your live EFI System Partition using the Windows graphical file Explorer. You can use the command prompt to type in commands that display, modify or copy files by specifying the assigned drive letter. You may be able to use some other graphical file explorer software to access the EFI System Partition using the assigned drive letter. The new restrictions on modifying the EFI System Partition are another reason why you may want to use the UEFI Shell. Edited by ErikW - 15 Dec 2020 at 9:46pm |
|
![]() |
|
Post Reply
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |