Write. img files in Linux

Source: Internet
Author: User

Write. IMG files in Linux

Hedgehog @ http://blog.csdn.net/littlehedgehog

 

 

 

 

Next we will use bximage to create a floppy disk image. (Of course, you can also use other tools, such as the VPC on windows platform)

$ Bximage
========================================================== ======================================
Bximage
Disk Image Creation Tool for Bochs
$ Id: bximage. c, v 1.32 2006/06/16 07:29:33 vruppert Exp $
========================================================== ======================================

Do you want to create a floppy disk image or a hard disk image?
Please type hd or fd. [hd] fd

Choose the size of floppy disk image to create, in megabytes.
Please type 0.16, 0.18, 0.32, 0.36, 0.72, 1.2, 1.44, 1.68, 1.72, or 2.88.
[1.44]
I will create a floppy image
Cyl = 80
Heads = 2
Sectors per track = 18
Total sectors = 2880
Total bytes = 1474560

What shoshould I name the image?
[A. img]

Writing: [] Done.

I wrote 1474560 bytes to a. img.

The following line shoshould appear in your bochsrc:
Floppya: image = "a. img", status = inserted

After creating an image file, you need to write the generated binary file to the absolute sector of the floppy disk. Let's take a look at the usage of the dd tool.
$Dd -- Help
Usage: dd [operand]...
Or: dd Option
Copy the file and convert and format the data according to the following operations.

Bs = byte forced ibs = <byte> and obs = <byte>
Cbs = Specified <byte>
Conv = the keyword is expressed as a comma-separated keyword to convert the file
Count = The number of blocks only copies the input data of the specified number of blocks.
Ibs = bytes read the specified <byte>
If = File Read <File> content rather than non-standard input data
Iflag = mark replace comma with the specified mark as the delimiter for reading the symbol list
Obs = Specified <byte>
Of = file writes data to <File> instead of standard output
Oflag = mark replace comma with the specified mark as the delimiter for writing the symbol list
Seek = The number of blocks first skips the output data of the specified <number of blocks> In obs.
Skip = The number of blocks first skips the specified <block quantity> input data in ibs Unit
Status = noxfer does not display the data transmission status

You can add the following units to the <number of blocks> and <byte>:
XM = M, c = 1, w = 2, B = 512, kB = 1000, K = 1024, MB = 1000*1000, M = 1024*1024,
GB = 1000*1000*1000, G = 1024*1024*1024, T, P, E, Z, Y, and so on.
Each <keyword> can be:

Ascii is converted from EBCDIC to ASCII
Ebcdic is converted from ASCII code to EBCDIC code
IBM converted from ASCII code to replaced EBCDIC code
Block replaces the line breaks in the ending character block with long spaces.
Unblock replaces spaces at the end of a cbs block with a linefeed.
Lcase converts uppercase letters to lowercase letters
Nocreat does not create output files
Excl operation failed if the output file already exists
Notrunc does not intercept output files
Ucase converts lowercase characters to uppercase letters
Swab exchanges each pair of input data bytes
After noerror reads data, it continues.
Sync fills each input data block with NUL characters to the size of ibs.
Or unblock, it is filled with spaces instead of NUL characters.
Fdatasync effectively writes the output file before the operation is completed
Fsync is similar to the above, but it also writes metadata

Each <tag> symbol can be:

Append mode (only meaningful for output operations)
Direct uses Direct I/O Access Mode
Dsync synchronizes data using I/O
Sync is similar to the above, but it also takes effect for metadata
Nonblock use non-blocking I/O
Nofollow does not follow the link file
Noctty does not assign control terminals based on files

Sending a USR1 signal to the running "dd" process causes
The I/O statistics are printed to the device with a standard error and the replication operation is resumed.

$ Dd if =/dev/zero of =/dev/null & pid = $!
$ Kill-USR1 $ pid; sleep 1; kill $ pid
18335302 + 0 records in
18335302 + 0 records out
9387674624 bytes (9.4 GB) copied, 34.6279 seconds, 271 MB/s

Available options include:

-- Help: displays the help information and leaves
-- Version: displays the version information and leaves.

Report errors to <bug-coreutils@gnu.org>.

Run the following command to write the absolute sector of the floppy disk.
$Dd If = boot. bin of = A. img bs = 512 COUNT = 1 Conv = notrunc
1 + 0 read records
1 + 0 records
512 bytes (512 B) Copied, 0.000112553 seconds, 4.5 MB/second

Now we can see the execution result. Enter
$Bochs-Q-F bochsrc. bxrc
Virtual Machine running effect: the red T is clearly visible. Although we didn't do screen cleaning.
This is probably the case for Linux debugging. It should be a good choice to write a Makefile to process a series of tasks.

However, in windows, I remember to write a batch file. To simulate it, I only need to double-click the batch file. Is it true in Linux? The answer is yes. We can write a shell script for execution. Like the batch file in Windows, only two lines of code are required:
#! /Bin/sh
Bochs-q-f bochsrc. bxrc
After writing the file, save any file name and add executable permissions to the file name. For example, my (File Name: run ):
$Sudo chmod + x run
Then, if you want to simulate it, you only need to input it in the terminal.
$Sudo./run
You can see that bochs is running.

What should I do if I debug a floppy image file with a file system. Don't worry. The following commands can also be done.
First, create a folder under the/mnt directory. In the future, our image files will be mounted here.
$CD/mnt/
$Sudo mkdir floppy
Return to the Development Directory of the operating system and mount the image file of the floppy disk to the directory created above. Assume that the image file of my floppya. IMG is
Then I use the following command to hold the load:
$Sudo mount./floppya. img/mnt/floppy/-o loop
-O loop refers to the image file as a block device (loop device ).
Then we can easily write files into this directory.
After writing the file, do not forget to detach the attached floppy disk image.
Then use bochs for simulation. The effect is as follows:

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.