Windows下无需第三方软件,命令行/脚本格式化SD卡为EXT4的方法问询
Alright, let's tackle this problem directly: Windows' native format command doesn't support EXT4 out of the box, which is exactly what you're hitting. But don't worry—there's a way to do this without installing third-party software, using tools that are already built into modern Windows 10/11.
WSL is a built-in Windows feature that lets you run a Linux environment directly on Windows, and it gives you access to Linux's native disk tools like mkfs.ext4—perfect for formatting your SD card for a Linux device.
Step 1: Enable WSL (if not already set up)
Open PowerShell as Administrator and run this command to install WSL and a default Linux distro (like Ubuntu):
wsl --install
You'll need to restart your PC after the installation finishes.
Step 2: Identify your SD card in Windows
First, confirm which disk is your SD card to avoid accidentally formatting your system drive:
- Open Command Prompt or PowerShell as Administrator and run:
diskpart - List all connected disks:
list disk - Look for your SD card (it'll usually be smaller than your internal drive, and marked as "Removable"). Note its disk number (e.g.,
Disk 2). - Exit DiskPart:
exit
Step 3: Format the SD card via WSL
- Launch your WSL distro (e.g., Ubuntu) from the Start Menu.
- First, identify the SD card's device path in WSL. Run:
Your SD card will show up aslsblk/dev/sdX(e.g.,/dev/sdbif it wasDisk 2in Windows). Double-check the size to be sure. - Unmount any mounted partitions on the SD card (to avoid errors):
Replacesudo umount /dev/sdX*sdXwith your actual device letter (e.g.,sdb). - Format the entire SD card as EXT4:
Or, if you only want to format a specific partition (e.g., the first partition):sudo mkfs.ext4 /dev/sdXsudo mkfs.ext4 /dev/sdX1 - When prompted, type
yto confirm the format (this will erase all data on the card, so make sure you've backed up anything important!).
If you want to create a Linux-specific partition first using Windows' native DiskPart, you can do this before formatting via WSL:
- Follow Step 2 above to select your SD card in DiskPart.
- Clean all existing partitions on the card:
clean - Create a primary partition:
create partition primary - Set the partition type to Linux (ID
83):set id=83 - Exit DiskPart, then jump back to Step 3 in the WSL method to format the partition as EXT4.
Important Notes:
- Always verify the disk/device path twice—formatting the wrong drive will erase all data irrecoverably.
- WSL requires administrative access to interact with physical disks, so you'll need to use
sudoin the Linux commands.
内容的提问来源于stack exchange,提问作者lquasar

