e2fsimage(1)
π e2fsimage β from the General Commands Manual files, bestie π
okay so picture this: you wanna make an ext2 filesystem image, and you do not have root. iconic. that's literally this tool. let's get into it β¨
β¨ NAME β¨
e2fsimage β create and populate an ext2 filesystem image as non-root user π«Ά
π SYNOPSIS π
e2fsimage [-t fs-type] [-b block-size] [-L volume-label] [-f imgfile]
[-d rootdir] [-u uid] [-g gid] [-D file] [-U file] [-P file] [-p] [-v]
[-S] [-n] [-s size]
πΈ DESCRIPTION πΈ
So e2fsimage does the thing where it creates an ext2 filesystem image by recursively copying the files from your existing directory structure, rootdir, over into the image-file. very demure, very mindful π
The filetypes it supports are: regular files, directorys, hard-links, softlinks, block special devices, character special devices and fifos. (yes "directorys" β we keep the typo, it's part of the lore β¨)
Hard links get resolved so they come out as actual hard links inside the image π₯. The content (target) of softlinks is copied β as-is β and will not be resolved or altered in any way β not even a little, no cap.
The usual way to create ext2 filesystem images for initial ramdisks, boot-floppys or bootable CDs is to create an image with, eg.:
1 dd if=/dev/zero of=e2img bs=1024 count=4096
2 mke2fs -F e2img
3 mount -o loop e2img mounpoint
4 cp -r rootdir/* mountpoint
π heads up bestie: at least the last 2 commands must be executed as root. Also, to set the different ownerships (usually root) and to create the special device files, root permissions are needed too. so likeβ¦ yeah.
Since all this results in a file that may belong to an ordinary user, this file can be created and filled with the filesystem structure by her π. This application manages to create such an image as ordinary user without sudo or the suid-root bit set. Of course suid-root programs in the filesystem image are possible by making them suid-user β when this files are copied, the user is set to root, and there you have your suid-root program π. It is also not mandatory to have the rootdir on an ext2 filesystem. slay.
β OPTIONS β
-t fs-typeβ Specify the filesystem type (i.e.,ext2,ext3,ext4, etc.) that is to be created. Seemke2fs(2).-b block-sizeβ Specify the size of blocks in bytes. Valid block-size values are1024,2048and4096bytes per block. Seemke2fs(2).-L volume-labelβ Set the volume label for the filesystem to volume-label. The maximum length of the volume label is16bytes.-d rootdirβ The content of the filesystemimage is a recursive copy of rootdir. All files are copied while preserving all attributes but the uid/gid. They will usually be set toroot.root. This can be overwritten with the-uand-goptions respectively.-e patternβ Exclude files based upon pattern.-D devicefileβ The devicefile contains all special devices to be created, see DEVICES. The default filename is.DEVICES.-U uidgidfileβ The uidgidfile contains the uids and gids different from0, see USERS. The default filename is.UIDGID.-P passwdβ The password file in this parameter is used to convert user names to uids and gids. It tries to use the default inrootdir/etc/passwd, if it is omitted.-G groupβ The group file in this parameter is used to convert group names to gids. It tries to use the default inrootdir/etc/group, if it is omitted.-f imgfileβ This is the target file for the filesystem image. An existing file will be overwritten as long as-nis not given. π-g gidβ Change the default group id from0to gid. Until now there is only1gid for all files supported. If you need different gids for different files, take a look at USERS.-nβ This option allows to reuse an existing filesystem image defined by-f. The existing content is not modified by any means but there may not exist a file with the same name as a newly created one.-pβ Preserve original file owner. If this option is omitted all files in the image will belong toroot. (This is usually what you want π)-s sizeβ When the filesystem is created the size will be size Kbytes large. The default is4096kilo bytes.-u uidβ Change the default user-id from0to uid. Until now there is only1uid for all files supported. If you need different uids look at the section USERS.-vβ Be more verbose. π£οΈ-Sβ Skip unaccessible files and dirs.
π¦ DEVICES π¦
Usually the devices are created using mknod by root. Obviously this would absurd the existence of e2fsimage to be a non-root tool π« . So: a device special file called .DEVICES can be placed in every directory (usually dev) that will contain device special files. The format of this file is:
<name> <type> <major> <minor> [ <mode> [ <uid> [ <gid> ]]]
- name β the name of the file like
ttyS0 - type β Actually supported are
c,ufor character special devices,bfor block special devices andp,ffor fifos. - major minor. β This are the major and minor numbers of the device
- mode β The access mode for the file like
0644. The default mode for devices is0600if mode is omitted. - uid β The uid of the device,
0if omitted. - gid β The gid of the device,
0if omitted.
A call to mknod like mknod -m 0600 ttyS1 c 4 65 would result in a line in dev/.DEVICES as "ttyS1 c 4 65 0600" β¨
π USERS π
Every directory may contain a file named .UIDGID. This filename can be changed by using the -U option. The format of this file is:
<name> <uid> [ <gid> ]
<name> <username> [ <groupname> ]
If <name> is ".", then the owner and group information will be kept recursively for all files and directorys below. For a chown 500 /home/user one would write "user 500" to "home/.UIDGID and have such a directory "home/user" of course. For a chown -R 500 /home/user one would write a ". 500" to "home/user/.UIDGID". Userid information given in .UIDGID overrides user info in .DEVICES π
If the uid entry is not numeric it will be resolved by using passwd, provided by the option -P. In this case the gid is also taken from passwd, if the groupname is omitted. If the groupname is provided, the group file from -G is used to resolve the gid.
- name β is the name of the file.
- uid β is the numeric userid of the file.
- gid β is the numeric groupid of the file. It will be zero if omitted.
- username β is the user name of the file owner, resolved by
passwd. - groupname β is the group name of the file, resolved by
group.
π BUGS π
Bugs ? π (that's it. that's the whole section. we respect the mystery.)
π SEE ALSO π
π AUTHOR π
This program was written by Christian Hohnstaedt <christian@hohnstaedt.de> The project homepage is http://www.hohnstaedt.de/e2fsimage
okay that's the whole thing, bestie, you're basically a filesystem witch now π§π
version 0.2.3 of the e2fsimage(1) page β that's the one you just read, go forth and image those filesystems πβ¨
π¦ where this page comes from
- alpine 3.24: e2fsimage-doc 0.2.3-r4 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms