loop device in WSL

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
prajwal
Member
Member
Posts: 154
Joined: Sat Oct 23, 2004 11:00 pm
Contact:

loop device in WSL

Post by prajwal »

Hi,

For my os development, I was able to set up dev env. in WSL - i.e. cross compiler, qemu etc. But I then realized that loop devices are not supported on WSL.
[ so far I have been using VM running ubuntu on windows 10 ordirectly boot to ubuntu OS ]

I need loop device to mount disk image files that I create using 'dd' command. I then partition the same using kpartx and also format these partitions in fat32/ext, then copy required os binary files onto mounted disk image and run qemu against these disk image files. In this, the part that is automated in a script is to mount the disk image file, copy os binaries and unmount disk image file

However, loop device isn't supported on WSL nor kpartx/related commands work on WSL

Is there any way to make this work on WSL or any alternatives to above (that can be automated through a script that can be run from within WSL) while I continue to use linux subsystem on windows 10

Thanks
Prajwal
complexity is the core of simplicity
User avatar
iansjack
Member
Member
Posts: 4938
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: loop device in WSL

Post by iansjack »

As you are using FAT for your disk image, mount it in Windows and copy the files to it in Windows,
User avatar
prajwal
Member
Member
Posts: 154
Joined: Sat Oct 23, 2004 11:00 pm
Contact:

Re: loop device in WSL

Post by prajwal »

Can I do mount + copy files + unmount in a script that’s run from within WSL ?

Also, I need to use ext2fs format as well
complexity is the core of simplicity
User avatar
prajwal
Member
Member
Posts: 154
Joined: Sat Oct 23, 2004 11:00 pm
Contact:

[SOLVED] Re: loop device in WSL

Post by prajwal »

I just updated my windows 10 to use insider preview build and got wsl2 installed and set up. I then noticed that loop device are now supported in wsl2! :)

I use 'Bash on Ubuntu' that now uses wsl2 and I am able to run my OS build and set up scripts that can mount disk images (created from dd), format and copy files like how I do it on a real linux installation

Thanks
Prajwal
complexity is the core of simplicity
User avatar
iansjack
Member
Member
Posts: 4938
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: loop device in WSL

Post by iansjack »

Thanks for the update. That's worth knowing.
mmdmine
Member
Member
Posts: 47
Joined: Sat Dec 28, 2019 5:19 am
Location: Iran
Contact:

Re: loop device in WSL

Post by mmdmine »

WSL is a software layer that allows you to run linux elf binaries on top of NT kernel. as NT doesn't support ext4 and loop device you can't use them in WSL. WSL2 actually is a virtual machine that runs a light version of linux kernel so it's possible on it.
i think ext2fs won't work on WSL on disk image as you can only access fixed disks in WSL even you dont have access to fat usb disks.
instead you can create a cpio initrd and boot your kernel with it directly with qemu, as qemu supports booting multiboot kernel directly.

Code: Select all

qemu -kernel kernel.bin -initrd ramdisk.tar.gz
Post Reply