Linux 创建一个没有安装的虚拟软盘映像?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11202706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 07:02:59  来源:igfitidea点击:

create a virtual floppy image without mount?

linuxsudomountddfloppy

提问by Congbin Guo

There are a lot of posts to show to create a virtual floppy image file as a super user or users can run sudocommand. The basic steps are:

有很多帖子可以作为超级用户或用户可以运行sudo命令来创建虚拟软盘映像文件。基本步骤是:

  1. create empty 1.44MB image file by ddcommand
  2. format the image file by mkfs.msdos
  3. mount the image file to some mount point
  4. copy something to the mount point
  5. umountthe virtual floppy image file
  1. 通过dd命令创建空的 1.44MB 图像文件
  2. 格式化图像文件 mkfs.msdos
  3. 将图像文件挂载到某个挂载点
  4. 复制一些东西到挂载点
  5. umount虚拟软盘映像文件

my question is, in case I am just a common user who cannot run sudocommand, how can I follow above steps to create a virtual floppy image and write something in it?

我的问题是,如果我只是一个无法运行sudo命令的普通用户,我该如何按照上述步骤创建虚拟软盘映像并在其中写入内容?

Thanks a lot.

非常感谢。

采纳答案by Igor Chubin

Yes, of course you can do this. Use mtoolsfor the FAT and e2toolsor genext2fsfor the ext2 filesystems.

是的,你当然可以这样做。使用mtoolsFAT和e2toolsgenext2fs用于EXT2文件系统。

$ dd if=/dev/zero of=/tmp/disk1.img count=1440 bs=1k 
1440+0 records in
1440+0 records out
1474560 bytes (1.5 MB) copied, 0.00569719 s, 259 MB/s

$ /sbin/mkfs.msdos /tmp/disk1.img 
mkfs.msdos 3.0.12 (29 Oct 2011)

$ mdir -i /tmp/disk1.img
 Volume in drive : has no label
 Volume Serial Number is 9913-BFF6
Directory for ::/

No files
                          1 457 664 bytes free

$ mcopy -i /tmp/disk1.img /etc/issue.net ::/
$ mdir -i /tmp/disk1.img
 Volume in drive : has no label
 Volume Serial Number is 9913-BFF6
Directory for ::/

issue    net        28 2012-06-26  10:49 
        1 file                   28 bytes
                          1 457 152 bytes free

And of course, I have no root rights.

当然,我没有root权限。