Page 1 of 1

(Solved) Putting files on Virtual HDDs

Posted: Sat Dec 16, 2017 3:34 pm
by Octacone
Does anybody know if there is a way to put a file (Stage_2.sys) on a virtual FAT32 HDD partition without using loopback devices (I tried them but they are only good for filesystem formatting and suck for everything else, especially writing files and build automation)? I need a tool of some sort that can do that (both adding and removing files ofc).
If you know a way I would be grateful to know.

Re: Putting files on Virtual HDDs

Posted: Sun Dec 17, 2017 5:32 am
by iansjack
Mtools.

(Solved) Putting files on Virtual HDDs

Posted: Sun Dec 17, 2017 6:59 am
by Octacone
iansjack wrote:Mtools.
I know they exist but there is 0 information online.
Cannot find a way to specify a partition of a virtual HDD...
I tried editing mtools config file and adding drive d: file="...HDD.img" partition=1, but no luck, partition not aligned, other errors etc... That is definitely not the right way of doing it...

This gives me, cannot initialize target, non dos media etc...
mcopy -i HDD.img Stage_2.sys ::/ (as you can see no way to specify a partition).

Edit:
Okay so I figured it out. To anybody in the future:
Put this inside your ~/.mtoolsrc
drive c: file="/path_to_your/HDD.img" partition=1 (1-4 are valid options) (the drive doesn't need to be labeled "c":)
mtools_skip_check=1
To copy a file to your virtual HDD partition use:
sudo mcopy Output/Stage_2.sys (your file) c: (your disk)
To delete a file from your virtual HDD partition use:
sudo mdel c:Stage_2.sys (your_drive:your_file)

Re: (Solved) Putting files on Virtual HDDs

Posted: Mon Dec 18, 2017 3:36 am
by AJ
Octacone wrote:I know they exist but there is 0 information online.
https://www.gnu.org/software/mtools/manual/mtools.html

Cheers,
Adam

Re: (Solved) Putting files on Virtual HDDs

Posted: Mon Dec 18, 2017 9:22 am
by Octocontrabass
Octacone wrote:(I tried them but they are only good for filesystem formatting and suck for everything else, especially writing files and build automation)
Writing files is easy, all you have to do is mount the partition:

Code: Select all

mount /dev/loop0p1 /mnt
cp file1 file2 file3 /mnt
umount /mnt
Unfortunately, I couldn't tell you if it's possible to make this happen in the context of build automation. For that, mtools may be a better solution.