Most new PCs don't come with DVD drives anymore. So it can be a pain to install Windows on a new computer.
To update macOS from the command line, first launch Terminal, which can be found in the Applications/Utilities folder. This will open a Terminal window and a command prompt for you to begin typing. Open Mac Spotlight using the ⌘ + space keyboard shortcut. Then type the word 'terminal' and select Terminal from the dropdown list. Paste the following command into your terminal and hit enter: diskutil list. You will see output like this (note - your Mac's terminal may be black text on a white background if you haven't customized it). Head to the “Updates” tab to see a list of available updates. You can opt to update each app individually, or click “Update All” instead. If you want your Mac App Store apps to update automatically, launch the App Store, then click on “App Store” in the top-left corner of the screen.
Luckily, Microsoft makes a tool that you can use to install Windows from a USB storage drive (or 'thumbdrive' as they are often called).
But what if you don't have a second PC for setting up that USB storage drive in the first place?
In this tutorial we'll show you how you can set this up from a Mac.
You can download the ISO file straight from Windows. That's right - everything we're going to do here is 100% legal and sanctioned by Microsoft.
If you want an English-language version of the latest update of Windows 10, you can download the ISO here.
If you have a relatively new computer, you probably want the 64-bit version. If you're not sure, go with the 32-bit version to be safe.
If you want a non-English-language version of Windows, or want to get an older update version, download the ISO here instead.
The ISO file is only about 5 gigabytes, but I recommend you use a USB drive with at least 16 gigabytes of space just in case Windows needs more space during the installation process.
I bought a 32 gigabyte USB drive at Walmart for only $3, so this shouldn't be very expensive.
Stick your USB drive into your Mac. Then open your terminal. You can do this using MacOS Spotlight by pressing both the ⌘ and Space bar at the same time, then typing 'terminal' and hitting enter.
Don't be intimidated by the command line interface. I'm going to tell you exactly which commands to enter.
Open Mac Spotlight using the ⌘ + space keyboard shortcut. Then type the word 'terminal' and select Terminal from the dropdown list.
Paste the following command into your terminal and hit enter:
diskutil list
You will see output like this (note - your Mac's terminal may be black text on a white background if you haven't customized it).
Copy the text I point to here. It will probably be something like
/dev/disk2
.
Next format your USB drive to Windows FAT32 format. This is a format that Windows 10 will recognize.
Note that you should replace the disk2
with the name of the your drive from step 3 if it wasn't disk2
. (It may be disk3
or disk4
).
Run this command using the correct disk number for your USB:
diskutil eraseDisk MS-DOS 'WIN10' GPT /dev/disk2
Then you'll see terminal output like this.
This will probably only take about 20 seconds on a newer computer, but may take longer on an older computer.
Note that for some hardware, you may instead need to run this command, which uses the MBR format for partitioning instead of GPT. Come back and try this command if step 7 fails, then redo steps 5, 6, and 7:
Now we're going to prep our downloaded ISO file so we can copy it over to our USB drive.
You will need to check where your downloaded Windows 10 ISO file is and use that. But your file is probably located in your ~/Downloads
folder with a name of Win10_1903_V1_English_x64.iso
.
hdiutil mount ~/Downloads/Win10_1903_V1_English_x64.iso
Update April 2020: One of the files in the Windows 10 ISO – install.wim – is now too large to copy over to a FAT-32 formatted USB drive. So I'll show you how to copy it over separately.
Thank you to @alexlubbock for coming up with this workaround.
First run this command to copy over everything but that file:
rsync -vha --exclude=sources/install.wim /Volumes/CCCOMA_X64FRE_EN-US_DV9/* /Volumes/WIN10
Then run this command to install Homebrew (if you don't have it installed on your Mac yet):
/usr/bin/ruby -e '$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)'
Then use Homebrew to install a tool called wimlib with this terminal command:
brew install wimlib
Then go ahead and create the directory that you're going to write the files into:
mkdir /Volumes/WIN10/sources
Then run this command. Note that this process may take several hours, you may see 0% progress until it finishes. Don't abort it. It will use wimlib to split the install.wim file into 2 files less than 4 GB each (I use 3.8 GB in the following command), then copy them over to your USB:
wimlib-imagex split /Volumes/CCCOMA_X64FRE_EN-US_DV9/sources/install.wim /Volumes/WIN10/sources/install.swm 3800
Once that's done, you can eject your USB from your Mac inside Finder.
Congratulations - your computer now should boot directly from your USB drive. If it doesn't, you may need to check your new PC's BIOS and change the boot order to boot from your USB drive.
Windows will pop up a screen and start the installation process.
Enjoy your new PC, and your newly-installed copy of Windows.
Update May, 2019
Now that there are SecureToken users, the command below no longer works to reset another user's password. Thanks to mario on the MacAdmins Slack for testing.
Acknowledgements
Just a cleaned-up version of directions from Mac Script to change Administrator password
Changing a user password via terminal command
If you ever want to—perhaps for scripting purposes?—change a user's password from the command-line (despite what it says in the link above, you don't have to be logged in as the user to change the user's password, but you do have to be logged in as an admin user), these are the commands you'd use:
sudo security set-keychain-password -o oldpassword -p newpassword /Users/username/Library/Keychains/login.keychain
If you don't know the old password...
If, for some reason, you (and the user both) have forgotten the user's old password and don't want to deal with keychains issues, you can also just delete the existing keychain (instead of running the second command to update the keychain password):
Security issues
One strong caveat is that the terminal, by default, will save commands to ~/.bash_history in plain text, so you're essentially storing a user's password in plain text, unless you temporarily disable bash history or later go into the ~/.bash_history file with a text editor (like nano) and delete the offending lines manually.
If you distribute this as part of a .pkg, nothing will be visible in a .bash_history file, but make sure you keep that .pkg extra secure or delete it after deploying it.