自己制作软盘镜像文件
2006-10-07 00:14
441 查看
现在较以往编写操作系统方便的地方就是有许多虚拟机可以应用,因此不必要在硬件上不停重启机器。然而,新机器很多也没有软驱。因此需要用模拟的软驱,即用一个img文件来代替软驱。vmware和bochs都支持模拟软驱。
但是img文件如何生成呢?
1.使用winimage软件。该软件可以生成各种镜像文件。然而不可以直接写二进制,即未格式化的二进制img文件。
2.自己写一个可以拷贝二进制进而生成img文件的代码(在linux AS4上编译调试通过):
/**************************************************************
文件名 : writeimg.c
说 明 :将二进制文件写成一个软盘image文件,用于引导
版权所有 2006, 周海汉,保留所有权利
Copyright 2006, ablo zhou. All Right Reserved.
版权声明:
汉风操作系统(Hanos),分发遵循汉风操作系统授权协议(Hanos License)。
***************************************************************/
#include <sys/types.h> /* unistd.h 需要这个文件 */
#include <unistd.h> /* 包含有read和write函数 */
#include <fcntl.h>
#include <string.h>
void menu(void)
{
printf("write binary file to image file or floppy/n /
copy right 2006 zhouhh /n/n /
using : /n /
writeimg [-i infile] [-o outfile] /n /
-i : binary input file /n /
-o : output image file /n /
eg:/n /
writeimg -i boot.bin -o boot.img/n /
writeimg -i boot.bin -o /dev/fd0 /n");
}
int main(int argc,char** argv)
{
char in_file[256]="boot.bin";
char out_file[256]="BOOT.IMG";
int i=0;
char boot_buf[1440*1024]={0};
int size=0;
int floppy_desc, file_desc;
if(argc == 1)
{
menu();
return;
}
for(i = 1; i < argc; i+=2)
{
if(i+1 > argc)
{
menu();
return;
}
if(strcmp(argv[i],"-i")==0)
{
strcpy(in_file,argv[i+1]);
}
else if(strcmp(argv[i],"-o")==0)
{
strcpy(out_file,argv[i+1]);
}
}
file_desc = open(in_file,O_RDONLY);
if(file_desc <=0)
{
printf("error: can't open file %s /n",in_file);
menu();
return;
}
size = lseek(file_desc,0L,SEEK_END);
lseek(file_desc,0L,SEEK_SET);
read(file_desc, boot_buf, size);
close(file_desc);
boot_buf[510] = 0x55;
boot_buf[511] = 0xaa;
floppy_desc = open(out_file,O_RDWR|O_CREAT);
if(floppy_desc <=0)
{
printf("error: can't open file %s /n",out_file);
menu();
return;
}
lseek(floppy_desc, 0, SEEK_CUR);
write(floppy_desc, boot_buf, 1440*1024);
close(floppy_desc);
printf("image file %s create successfully./n",out_file);
}
该程序可以直接拷贝二进制到img文件或者软驱。可以用于制作直接启动盘。
但是img文件如何生成呢?
1.使用winimage软件。该软件可以生成各种镜像文件。然而不可以直接写二进制,即未格式化的二进制img文件。
2.自己写一个可以拷贝二进制进而生成img文件的代码(在linux AS4上编译调试通过):
/**************************************************************
文件名 : writeimg.c
说 明 :将二进制文件写成一个软盘image文件,用于引导
版权所有 2006, 周海汉,保留所有权利
Copyright 2006, ablo zhou. All Right Reserved.
版权声明:
汉风操作系统(Hanos),分发遵循汉风操作系统授权协议(Hanos License)。
***************************************************************/
#include <sys/types.h> /* unistd.h 需要这个文件 */
#include <unistd.h> /* 包含有read和write函数 */
#include <fcntl.h>
#include <string.h>
void menu(void)
{
printf("write binary file to image file or floppy/n /
copy right 2006 zhouhh /n/n /
using : /n /
writeimg [-i infile] [-o outfile] /n /
-i : binary input file /n /
-o : output image file /n /
eg:/n /
writeimg -i boot.bin -o boot.img/n /
writeimg -i boot.bin -o /dev/fd0 /n");
}
int main(int argc,char** argv)
{
char in_file[256]="boot.bin";
char out_file[256]="BOOT.IMG";
int i=0;
char boot_buf[1440*1024]={0};
int size=0;
int floppy_desc, file_desc;
if(argc == 1)
{
menu();
return;
}
for(i = 1; i < argc; i+=2)
{
if(i+1 > argc)
{
menu();
return;
}
if(strcmp(argv[i],"-i")==0)
{
strcpy(in_file,argv[i+1]);
}
else if(strcmp(argv[i],"-o")==0)
{
strcpy(out_file,argv[i+1]);
}
}
file_desc = open(in_file,O_RDONLY);
if(file_desc <=0)
{
printf("error: can't open file %s /n",in_file);
menu();
return;
}
size = lseek(file_desc,0L,SEEK_END);
lseek(file_desc,0L,SEEK_SET);
read(file_desc, boot_buf, size);
close(file_desc);
boot_buf[510] = 0x55;
boot_buf[511] = 0xaa;
floppy_desc = open(out_file,O_RDWR|O_CREAT);
if(floppy_desc <=0)
{
printf("error: can't open file %s /n",out_file);
menu();
return;
}
lseek(floppy_desc, 0, SEEK_CUR);
write(floppy_desc, boot_buf, 1440*1024);
close(floppy_desc);
printf("image file %s create successfully./n",out_file);
}
该程序可以直接拷贝二进制到img文件或者软驱。可以用于制作直接启动盘。
相关文章推荐
- 制作带有 GRUB 引导功能的软盘镜像文件
- 制作带有 GRUB 引导功能的软盘镜像文件
- 制作带有 GRUB 引导功能的软盘镜像文件
- 简单两步自己动手制作联想windows7 sp1 64位旗舰版安装镜像文件windows7旗舰版主
- 制作适合自己的linux系统镜像文件
- linux下制作软盘镜像文件
- 自己制作Linux的镜像文件XXX.iso的大致组成
- 制作软盘镜像文件
- initrd镜像文件的作用与制作
- 嵌入式文件系统镜像制作及烧写
- RTEMS连载 (3) 启动镜像文件制作 (上)
- 怎样在Linux下制作软盘和光盘镜像
- Porting:telnet远程登录开发板、制作并烧写cramfs和ext4和ramdisk三种格式根文件系统镜像
- 自己动手将在线文档制作成CHM文件
- linux光盘镜像文件制作攻略[转]
- 实战DeviceIoControl 之三:制作磁盘镜像文件
- 深度学习caffe平台--制作自己.lmdb格式数据集及分类标签文件
- hi3531 SDK已编译文件系统制作jffs2文件系统镜像并解决问题 . 分类: arm-linux-Ubuntu HI3531 2014-06-18 08:45 951人阅读 评论(0) 收藏
- 自己制作MSDN2012本地安装文件光盘
- 实战DeviceIoControl 之三:制作磁盘镜像文件