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.
相关问题
- Views base64 encoded blob in HTML with PHP
- How to get the background from multiple images by
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- CV2 Image Error: error: (-215:Assertion failed) !s
you might want to look at genextfs, that creates an ext2 filesystem in a regular file without any sort of mounting.
I had this problem and couldn't find a viable solution, so I wrote this utility that we've open-sourced here.
From the README:
Minimal runnable
sfdisk
+mke2fs
example withoutsudo
In this example, we will create, without
sudo
orsetsuid
, an image file that contains two ext2 partitions, each populated with files from a host directory.We will then use
sudo losetup
just to mount the partitions to test that the Linux kernel can actually read them as explained at: How to mount one partition from an image file that contains multiple partitions on Linux?For more details, see:
sfdisk
: deals with the partition table: https://superuser.com/questions/332252/how-to-create-and-format-a-partition-using-a-bash-script/1132834#1132834mke2fs
: deals with EXT formatting of partitions: https://superuser.com/questions/605196/how-to-create-ext2-image-without-superuser-rights/1366762#1366762The example:
Tested on Ubuntu 18.04. GitHub upstream.
Yes, this is possible with guestfish:
The result will be
debian-unstable.img
with one ext2 partition on it, containing all files from the tarballdebian-unstable.tar
and the whole thing is made bootable with extlinux. You can verify the disk image using qemu.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.
Steps with loopback
Here's what I'm doing ( $1 is image file name, $2 is file size):
dd if=/dev/zero of=$1 bs=512 count=$(($2/512))
parted -s $1 mklabel msdos
parted -s $1 "mkpart primary 0% 100%"
sudo losetup --find $1 --offset $OFFSET_TO_PARTITION_BYTES
mkfs.ext4 -I 128 -L BOOT -b 2048 -O ^has_journal /dev/loop0 $SIZE_IN_2048_BLOCKS
The loopback is used because
Looback workarounds
Shitty work-around for step 4 & 5:
Work-around solution to step 6:
Caveat
Caveat: ext4 support is not advertised in their documentation, and attempts to mount come with a warning:
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