Page 1 of 1

loop device in WSL

Posted: Sat Dec 28, 2019 3:38 am
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

Re: loop device in WSL

Posted: Sat Dec 28, 2019 4:52 am
by iansjack
As you are using FAT for your disk image, mount it in Windows and copy the files to it in Windows,

Re: loop device in WSL

Posted: Sat Dec 28, 2019 5:17 am
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

[SOLVED] Re: loop device in WSL

Posted: Tue Dec 31, 2019 12:05 am
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

Re: loop device in WSL

Posted: Tue Dec 31, 2019 12:40 am
by iansjack
Thanks for the update. That's worth knowing.

Re: loop device in WSL

Posted: Tue Dec 31, 2019 1:19 am
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