Hard drive linux windows

Use Linux Hard Drives in EXT4 in Windows 10 without Programs

The Windows subsystem for Linux has changed the way things are done in Windows 10. Especially for the most curious users, the advanced users, developers and technicians. Thanks to WSL, any Windows 10 user can have their own Linux Kernel within Windows, run it in isolation and even, soon, have their own graphical environment to run any program from it. With the arrival of WSL2, the second version of this tool, Microsoft has gone one step further. And now the integration with Linux is such that, finally, we can mount EXT4 hard drives in Windows without using other programs.

Until now, users who wanted to mount Linux EXT4 hard drives in order to access their data or copy files had to resort to third-party programs to do so. These programs acted as “drivers” so that the operating system could recognize these systems and work with them as if they were NTFS drives. This type of software is not exactly fast, nor is it stable. And most of the programs are even already unsupported. Mounting Linux drives on Windows was getting more and more difficult.

With the arrival of WSL, things have changed. Especially with version 2 of the Windows subsystem for Linux. From now on, users who work with both operating systems will be able to mount their Linux drives directly in Windows 10 , without special programs for it. It is not an automatic process, nor is it fast. But by learning a series of commands we will be able to access these units, and all their data, whenever we want.

Mount an EXT4 disk in Windows 10

Unfortunately, Microsoft has not (yet) made this process semi-automatic, or double-clicking on the drive. Windows 10 forces us to identify the drive and mount it manually using commands in order to start using these drives.

The requirements that we will need to be able to use this function are:

  • Windows 10 Pro.
  • Hyper-V activated.
  • Windows subsystem for Linux enabled.
  • Latest version of Windows installed (WSL2 compliant).

To carry out this task we have to follow a series of steps.

Identify the unit

The first thing we will have to do is identify the unit we want to mount. It can be a complete hard drive, internal or external, or a single partition. But we have to know what it is. To do this, what we must do is run the following command in a CMD window:

wmic diskdrive list brief

In the list of elements that will appear, we will have to look at the “DeviceID”, since it will be the identifier of the hard disk.

Identificar unidades para WSL EXT4

Once we identify the disk, we will begin with the assembly. Of course, before continuing we must indicate that, once the unit is mounted, it will be blocked and will be inaccessible to Windows. To use it again in Windows 10 we will have to disassemble it.

Читайте также:  Apache сервер установить linux

Mount EXT4 disk

To mount the unit, what we have to do is use the command ” wsl –mount “, followed by the disk identifier. For example, supposing that our unit only has one partition (and all of it is in EXT4), and it is the first one that we have connected to the PC, the command that we must execute will be:

If our hard drive has several partitions, and only one of them is in EXT4, then what we must do is select the partition with the “partition” parameter. In this way, the command would be as follows:

wsl —mount .PHYSICALDRIVE0 —partition 1

We remember that we must change both the disk identifier and the partition number to suit our unit. Once the command is executed, we can see that in the file explorer, in the bar on the right, a new Linux icon appears, and within it all the directories of the unit in EXT4.

WSL Linux en Windows 10 build 19603 - 1

The EXT4 units will also be accessible from any distro that we have installed in WSL. We will find these units within the point “/ mnt” of the WSL distro.

Disassemble unit

When we have already done everything we have to do, and we do not want the EXT4 unit to remain mounted in Windows 10, we can unmount it. This must also be done with a simple command, only instead of using the “mount” parameter we will have to use “unmount”. Thus, to dismount the unit that we have mounted in the previous points we will have to execute the following:

wsl —unmount .PHYSICALDRIVE0

Mount hard drives on other file systems

By default, WSL is configured so that using wsl –mount mounts drives in an EXT4 file system on Windows 10. But this, although it is the most used system, is not the only one. There are users who prefer to use other file systems (such as VFAT, BTRFS, and even NTFS, although this would not make much sense) that bring other advantages to drives and hard drives.

WSL will allow us to mount drives on any file system that is directly supported by the Linux Kernel. To do this, all we have to do is use the “-t” parameter followed by the file system that we want to mount. For example, to load a drive formatted in VFAT, we can do it with the command:

wsl —mount .PHYSICALDRIVE0 —partition 1 -t vfat

And in the case of wanting to mount one in btrfs, the command would be:

wsl —mount .PHYSICALDRIVE0 —partition 1 -t btrfs

Alternatives to read and write EXT4 in Windows 10

Now that it is possible to use WSL to have official support for this file system, using third-party programs for it is meaningless. However, there are users who probably prefer to continue using these programs. Especially those who have Windows 10 Home, not being able to use WSL due to the lack of support for Hyper-V.

Some of the programs that allow us to do this are:

Ext2SFD

If what we want is a free program, this is one of the ones that works best. With it, we will be able to mount all types of Linux partitions in Windows, so that we can access the data of the EXT2, EXT3 and EXT4 units in an almost native way. We will be able to read and write data to these drives, as if they were NTFS, and even configure them to mount automatically at Windows startup and have them ready from the first moment.

Читайте также:  Разрешение экрана linux vga

We can download the tool from the developer’s official website .

Linux File Systems for Windows

If what we are looking for is a program developed and controlled by a well-known company, such as Paragon, this program will help us to work with Linux drives in Windows 10. This program will allow us to mount any Linux drive , both EXT (2, 3 and 4) and BTRFS or XFS, to be able to use them as if they were Windows NTFS drives.

Источник

Mount a Linux disk in WSL 2

If you want to access a Linux disk format that isn’t supported by Windows, you can use WSL 2 to mount your disk and access its content. This tutorial will cover the steps to identify the disk and partition to attach to WSL2, how to mount them, and how to access them.

If you are looking for guidance on how to connect a USB device (flash drive, SD card reader, etc), see Connect USB devices.

Administrator access is required to attach a disk to WSL 2. The WSL 2 mount command does not support mounting a disk (or partitions that belong to the disk) that is currently in use. wsl —mount always attaches the entire disk even if only a partition is requested. You can’t mount the Windows installation disk.

Prerequisites

You will need to be on Windows 11 Build 22000 or later, or be running the Microsoft Store version of WSL. You can join the Windows Insiders Program to get the latest preview builds.

Mounting an unpartitioned disk

In this simplest case, if you have a disk that doesn’t have any partitions, you can mount it directly using the wsl —mount command. First you need to identify the disk.

    Identify the disk — To list the available disks in Windows, run:

GET-CimInstance -query "SELECT * from Win32_DiskDrive" 

Mounting a drive in WSL

Mounting a partitioned disk

If you have a disk that you aren’t sure what file format it is in, or what partitions it has, you can follow the steps below to mount it.

    Identify the disk — To list the available disks in Windows, run:

GET-CimInstance -query "SELECT * from Win32_DiskDrive" 

Inside Linux, a block device is identified as /dev/ . For example, /dev/sdb3, is the partition number 3 of disk sdb .

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb 8:16 0 1G 0 disk ├─sdb2 8:18 0 50M 0 part ├─sdb3 8:19 0 873M 0 part └─sdb1 8:17 0 100M 0 part sdc 8:32 0 256G 0 disk / sda 8:0 0 256G 0 disk 

Identifying the filesystem type

If you don’t know the type of filesystem of a disk or partition, you can use this command:

This will output the detected filesystem type (under the TYPE=»» format).

Mount the selected partitions

Once you have identified the partitions you want to mount, run this command on each partition:

If you wish to mount the entire disk as a single volume (i.e. if the disk isn’t partitioned), —partition can be omitted.

If omitted, the default filesystem type is «ext4».

Access the disk content

Once mounted, the disk can be accessed under the path pointed to by the config value: automount.root . The default value is /mnt/wsl .

From Windows, the disk can be accessed from File Explorer by navigating to: \\wsl$\\\\ (pick any Linux distribution).

Unmount the disk

If you want to unmount and detach the disk from WSL 2, run:

Mount a VHD in WSL

WSL from the Microsoft Store introduces a new argument to directly mount a VHD: wsl —mount —vhd

Читайте также:  What is i386 linux

You can also mount virtual hard disk files (VHD) into WSL using wsl —mount . To do this, you first need to mount the VHD into Windows using the Mount-VHD command in Windows. Be sure to run this command with administrator privileges. Below is an example where we use this command, and also output the disk path. Be sure to replace with your actual VHD path.

Write-Output "\\.\PhysicalDrive$((Mount-VHD -Path -PassThru | Get-Disk).Number)" 

You can use the output above to obtain the disk path for this VHD and mount that into WSL following the instructions in the previous section.

You can also use this technique to mount and interact with the virtual hard disks of other WSL distros, as each WSL 2 distro is stored via a virtual hard disk file called: ext4.vhdx . By default the VHDs for WSL 2 distros are stored in this path: C:\Users\[user]\AppData\Local\Packages\[distro]\LocalState\[distroPackageName] , please exercise caution accessing these system files, this is a power user workflow. Make sure to run wsl —shutdown before interacting with this disk to ensure the disk is not in use.

Mounting WSL VHD

Command line reference

Mounting a specific filesystem

By default, WSL 2 will attempt to mount the device as ext4. To specify another filesystem, run:

For example, to mount a disk as fat, run:

To list the available filesystems in WSL2, run: cat /proc/filesystems
When a disk has been mounted via WSL2 (Linux file system), it is no longer available to mount via an ext4 driver on the Windows file system.

Mounting a specific partition

By default, WSL 2 attempts to mount the entire disk. To mount a specific partition, run:

This only works if the disk is either MBR (Master Boot Record) or GPT (GUID Partition Table). Read about partition styles — MBR and GPT.

Specifying mount options

To specify mount options, run:

Only filesystem specific options are supported at this time. Generic options such as ro, rw, noatime, . are not supported.

Attaching the disk without mounting it

If the disk scheme isn’t supported by any of the above options, you can attach the disk to WSL 2 without mounting it by running:

This will make the block device available inside WSL 2 so it can be mounted manually from there. Use lsblk to list the available block devices inside WSL 2.

Specifying the mount name

This option is only available with WSL from the Microsoft Store

By default the mountpoint name is generated based on the physical disk or VHD name. This can be overriden with —name . Example:

Detaching a disk

To detach a disk from WSL 2, run:

If Diskpath is omitted, all attached disks are unmounted and detached.

If one disk fails to unmount, WSL 2 can be forced to exit by running wsl —shutdown , which will detach the disk.

Limitations

  • At this time, only entire disks can be attached to WSL 2, meaning that it’s not possible to attach only a partition. Concretely, this means that it’s not possible to use wsl —mount to read a partition on the boot device, because that device can’t be detached from Windows.
  • Only filesystems that are natively supported in the kernel can be mounted by wsl —mount . This means that it’s not possible to use installed filesystem drivers (such as ntfs-3g for example) by calling wsl —mount .
  • Filesystems not directly supported by the kernel can be mounted via a —bare attach and then invoking the relevant FUSE driver.

Feedback

Submit and view feedback for

Источник

Оцените статью
Adblock
detector