如何创建没有root权限的多分区SD磁盘映像? [英] How to create a multi partition SD disk image without root privileges?

查看:199
本文介绍了如何创建没有root权限的多分区SD磁盘映像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在没有root特权的情况下(即没有环回安装)在linux中创建完整的SD映像?我正在寻找一种自动化嵌入式系统映像创建的方法.该映像应包括特定的分区结构,以及格式化为FAT和ext2的分区,并使用来自构建系统的文件进行填充.

Is it possible to create a complete SD image in linux without having root privileges (that is, no loopback mount)? I'm looking for a way to automate embedded system image creation. The image should include a specific partition structure and partitions formatted to FAT and ext2 populated with files from the build system.

推荐答案

我正在尝试做同样的事情.我第一次尝试使用回送阻止设备,但是我发现了需要回送的两个步骤的解决方法.

I'm trying to do the same thing. My first attempt used the loopback block device, but I have found work-arounds to both steps that require loopback.

这就是我正在做的事情($ 1是图像文件名,$ 2是文件大小):

Here's what I'm doing ( $1 is image file name, $2 is file size):

  1. 使用dd if=/dev/zero of=$1 bs=512 count=$(($2/512))
  2. 创建清零的磁盘映像文件
  3. 使用parted -s $1 mklabel msdos
  4. 创建分区表
  5. 使用parted -s $1 "mkpart primary 0% 100%"
  6. 创建分区
  7. 附加分区以循环sudo losetup --find $1 --offset $OFFSET_TO_PARTITION_BYTES
  8. 使用mcfs.ext4和mkfs.ext4 -I 128 -L BOOT -b 2048 -O ^has_journal /dev/loop0 $SIZE_IN_2048_BLOCKS
  9. 制作文件系统
  10. 挂载/dev/loop0
  1. create zeroed disk image file with dd if=/dev/zero of=$1 bs=512 count=$(($2/512))
  2. create partition table with parted -s $1 mklabel msdos
  3. create partition with parted -s $1 "mkpart primary 0% 100%"
  4. attach partition to loop sudo losetup --find $1 --offset $OFFSET_TO_PARTITION_BYTES
  5. make file system with mkfs.ext4 with mkfs.ext4 -I 128 -L BOOT -b 2048 -O ^has_journal /dev/loop0 $SIZE_IN_2048_BLOCKS
  6. mount /dev/loop0

之所以使用环回,是因为

The loopback is used because

  • 在步骤4&中5,mkfs没有偏移选项,因此使用Lostup解决了该问题
  • 在第6步中,安装允许使用操作系统ext4驱动程序

第4步和第4步的糟糕解决方法5:

Shitty work-around for step 4 & 5:

  • xmount --in dd --out vdi disk.img mnt/
  • vdfuse -f mnt/disk.vdi -r ./mnt2
  • ./mnt2现在将具有两个文件:EntireDisk和Partition1
  • 将mkfs.ext4指向./mnt2/Partition1

第6步的解决方法:

  • 按照步骤5的所有步骤进行操作
  • 使用fuseext2来安装./mnt2/Partition1

注意事项:ext4支持未在其文档中公布,尝试进行安装时会出现警告:

Caveat: ext4 support is not advertised in their documentation, and attempts to mount come with a warning:

This is experimental code, opening rw a real file system could be
dangerous for your data. Please add "-o ro" if you want to open the file
system image in read-only mode, or "-o rw+" if you accept the risk to test
this module

更新

vdfuse应该能够在没有xmount帮助的情况下挂载原始映像,但是存在一个忽略RAW选项的错误.

Update

vdfuse should be able to mount a raw image without the help of xmount, but there is a bug which ignores the RAW option.

我在此处跟踪并修复了该错误:

I tracked down and fixed the bug with a patch here:

https://bugs.launchpad.net/ubuntu/+ source/virtualbox-ose/+ bug/1019075

这篇关于如何创建没有root权限的多分区SD磁盘映像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆