(Solved) Putting files on Virtual HDDs

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
Post Reply
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

(Solved) Putting files on Virtual HDDs

Post 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.
Last edited by Octacone on Sun Dec 17, 2017 7:42 am, edited 1 time in total.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
iansjack
Member
Member
Posts: 4683
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Putting files on Virtual HDDs

Post by iansjack »

Mtools.
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

(Solved) Putting files on Virtual HDDs

Post 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)
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: (Solved) Putting files on Virtual HDDs

Post 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
Octocontrabass
Member
Member
Posts: 5501
Joined: Mon Mar 25, 2013 7:01 pm

Re: (Solved) Putting files on Virtual HDDs

Post 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.
Post Reply