-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tools for working with or creating MBR-formatted disk images #14
Comments
Hello @reynir |
@PizieDust what would you like to work on? I suggest working on one of the two first as they are not as difficult as the latter two. It may be helpful to look at the wikipedia article. We implement the "modern standard MBR". https://en.wikipedia.org/wiki/Master_boot_record To create a new binary executable you can use |
Hi @reynir , I apologize for the delay on this issue. This is my first time working with functional programming. |
Okay thank you. This is very helpful. |
@reynir
or for the modern mbr standard which contains the fields:
and for each of the partitions (max 4), we also iterate over them and read the fields which are:
In the file So my question is, in the implementation of we also have an I'm trying to figure out the ocaml syntax on how to achieve this. hope I am in the right direction? |
For the second task, here is a basic implementation I have (pardon the wrong syntax)
|
Yes, you're on the right track. Use the The difference between the type |
@reynir I'm trying to create a partition with the code (which will be saved in a file) and then use this partition to test the code for this task, but I keep having errors with creating the partition. Here is the code I am using: let disk_length_bytes = Int32.(mul (mul 16l 1024l) 1024l) in
let disk_length_sectors = Int32.(div disk_length_bytes 512l) in
let start_sector = 2048l in
let length_sectors = Int32.sub disk_length_sectors start_sector in
let partition1 = Mbr.Partition.make ~active:true ~ty:6 start_sector length_sectors in
let mbr = Mbr.make [ partition1 ] in
match mbr with
| Ok -> print_endline "MBR created"
| Error msg -> Printf.printf "MBR failed %s\n" msg running dune build gives the error: 11| let mbr = Mbr.make [ partition1 ] in (* partitions is underlined *)
Error: This expression has type (Mbr.Partition.t, string) result but an expression was expected of type Mbr.Partition.t Please what could I be doing wrongly? |
Edit: I forgot to explain the error. The error is due to I created a test archive (in a .tar.gz due to github limitations): test.img.tar.gz I used the following commands: $ fallocate -l 2M test.img # Allocate a 2 MB file, which is 4 sectors
$ parted --align none test.img mklabel msdos # Write MBR
$ parted --align none test.img mkpart primary 1s 1s # Add a one-sector partition
$ parted --align none test.img mkpart primary 2s 3s # Add a two-sector partition (remaining space) The argument |
Oh I see. Thank you. I just downloaded the archive. It'll come in really handy. thanks much |
@reynir Concerning task 3 (resizing partitions in a disk image).
my idea of the function was something like this: let resize_partiton mbr partition_number new_size =
..... where our function takes in the MBR, the partition number to be resized and the new size. From here, I think we'll update the partitions in the MBR and write the changes to the file (overwrite??) I created a new file |
Indeed, the partitions may overlap and care should be taken in that case. The default should be to error if partitions would overlap. Shifting partitions would require moving data around on the disk (image). If this fails, for example sudden shutdown or the user aborting the command, you may end up with a bad state in the partition. I don't expect you to implement this. You would need to overwrite the first 512 bytes of the file with a new header. Take care not to truncate or replace the file. The interface of the library likely has to be extended a bit. The types |
Thank you, this is very helpful. |
The MBR structure needs to be marshaled and the marshaled structure is what needs to be written. |
I updated the issue with tasks done and I clarified the second task -- it's about reading the data from a partition |
okay great. For the second task, reading the data content of a partition: meaning what is actually stored in this partition ? |
Yes. The idea is a partition may contain e.g. a tar archive. Because of the MBR header (and potentially other partitions before) the standard tar tools are not able to read the tar archive. Instead, it may be useful to "extract" the partition data in order to use other tools. A related task could be to "blit" or write data from a file into a partition in a disk image. |
Hello @reynir |
You can use the Unix module for the command line tools. They are for running in a Unix-like environment. While the I/O operations would need to be changed for Mirage the source of the tool can serve as an example on how to use the library (while being useful!) |
Oh thank you. Let me get on it. I have some bare code written, I'll just add the Unix module and experiment with it. |
I think you should be able to use |
I would like to work on one of the last two, can you assign me, please? |
That's cool. But I already have some code in development. Maybe you could help review when I open PR's |
@0x0god I would advice that you focus on reynir/mirage-block-partition#6. The last two tasks in this issue are not easy first tasks. |
Thanks for the advice, Please check my comment on my recent PR. |
Hello @reynir
So far we have been working with MBR headers. The task is about creating an MBR formatted disk. Is this to achieve the same thing as when we use By empty sections do we mean un-allocated space? I don't quite understand what padding here means. Also what's the expected implementation for this task like? A script which maybe executes some unix commands to create the disk, usage of the other scripts such as |
Yes, this is about achieving the same as we did with Given that you wrote several tools that can be used to achieve some of the sub tasks it maybe makes more sense to just write a tool for writing a fresh MBR header. Then a small script could be written to achieve the above. |
Thank you. This is a great explanation. |
Hi @reynir |
It would be nice to develop one or more tools to:
The text was updated successfully, but these errors were encountered: