Ext2/3/4 equivalent of mtools
Ext2/3/4 equivalent of mtools
It would be useful to be able to manipulate ext* disk images purely from userspace, like mtools allows you to do for FAT*. Are there any such tools?
Re: Ext2/3/4 equivalent of mtools
What form of manipulation do you mean? The tools for partitioning disks and creating extx filesystems are userspace programs. (Of course you need the appropriate privileges to manipulate any filesystem.)
Re: Ext2/3/4 equivalent of mtools
Well, I want to be able to build my OS without root permissions, including generating the VM disk image. This is perfectly reasonable; all the inputs and outputs are owned & readable/writeable by me. However, reading & writing to a disk image typically requires mounting the image, which requires root. That can be got around via a suitable /etc/fstab entry marked as user mountable.
Unfortunately, that still doesn't allow you to write to inode 5 (bootloader inode, not actually used by any current OS AFAIK, but it seems a good convention to me, and I intend to use it in my OS), as under Linux you can only write to inode 5 of a mounted filesystem as root.
Unfortunately, that still doesn't allow you to write to inode 5 (bootloader inode, not actually used by any current OS AFAIK, but it seems a good convention to me, and I intend to use it in my OS), as under Linux you can only write to inode 5 of a mounted filesystem as root.
Re: Ext2/3/4 equivalent of mtools
You can use dd to write to any block of a block device without mounting it.
Re: Ext2/3/4 equivalent of mtools
I'm not sure if building a whole image with it is advisable or at least easily possible, but debugfs can work on an ext2 filesystem image with user permissions.
Re: Ext2/3/4 equivalent of mtools
Sure - I have considered having a pre-built crafted image which the file is at a known position and written to with dd. That's not very flexible though, as it basically requires a fixed length file.iansjack wrote:You can use dd to write to any block of a block device without mounting it.
Yes, looks like debugfs could be used. I had looked into it before, but struggled to work out how to use it to write to inode 5. I don't think you can directly write file contents to an inode number, but you can:Kevin wrote:I'm not sure if building a whole image with it is advisable or at least easily possible, but debugfs can work on an ext2 filesystem image with user permissions.
- Use debugfs to link inode 5 to a file in the directory structure
- Mount the fs, write to that file, and unmount
- Use debugfs to unlink inode 5 from the directory structure
Interestingly, e2fsprogs (the project that contains debugfs) also contains a tool called ext2ed, which looked like it had the potential to be what I wanted. Unfortunately, it was originally a university project in 2001 and has barely been maintained since, so I think debugfs is the better option.
Re: Ext2/3/4 equivalent of mtools
I use a tool called genext2fs to build ext2 partitions from source directories. That might fit your use case.
- crunch
- Member
- Posts: 81
- Joined: Wed Aug 31, 2016 9:53 pm
- Libera.chat IRC: crunch
- Location: San Diego, CA
Re: Ext2/3/4 equivalent of mtools
I have developed a tool for exactly what you're asking because I too wanted to write to inode 5. I'm currently writing my VFS layer in Linux (I.e. my VFS layer can be run as a user space Linux program) and I have full write/read/add directories for ext2 etc and it works.
It's not on my GitHub yet, but if you PM I'll send later (not at home now)
I have an old version of the tool up on GitHub here: https://github.com/lazear/ext2util/tree ... 00edb40aa7
I make no promises that any newer commit than that will work, but it should at least enable you to write to inode 5. I started trying to develop my VFS layer after writing the ext2 direct block driver...Not a good idea. Ended up doing it in the proper order.
If there is wide spread interest in this tool, I wouldn't be opposed to going back and fixing it.
It's not on my GitHub yet, but if you PM I'll send later (not at home now)
I have an old version of the tool up on GitHub here: https://github.com/lazear/ext2util/tree ... 00edb40aa7
I make no promises that any newer commit than that will work, but it should at least enable you to write to inode 5. I started trying to develop my VFS layer after writing the ext2 direct block driver...Not a good idea. Ended up doing it in the proper order.
If there is wide spread interest in this tool, I wouldn't be opposed to going back and fixing it.
Some of my open-source projects:
Ext2/ELF32 bootloader
Lightweight x86 assembler, designed to be portable for osdev
Scheme in under 1000 lines of C
Ext2/ELF32 bootloader
Lightweight x86 assembler, designed to be portable for osdev
Scheme in under 1000 lines of C
Re: Ext2/3/4 equivalent of mtools
Unfortunately I've not been able to get this to work. Linux isn't keen on the resulting filesystem after step 1, any command I try gives an error like "cannot access 'mnt/boot_temp': Structure needs cleaning".madanra wrote:...but you can:I think this is an acceptable solution for now.
- Use debugfs to link inode 5 to a file in the directory structure
- Mount the fs, write to that file, and unmount
- Use debugfs to unlink inode 5 from the directory structure
Thanks, that looks really useful! Solves everything apart from writing to inode 5, and is in Debian/Ubuntu repositories, which is a bonus. It doesn't look to have been worked on since 2007, but if it works...klange wrote:I use a tool called genext2fs to build ext2 partitions from source directories. That might fit your use case.
Thanks, that's working for me!crunch wrote:I have developed a tool for exactly what you're asking because I too wanted to write to inode 5. I'm currently writing my VFS layer in Linux (I.e. my VFS layer can be run as a user space Linux program) and I have full write/read/add directories for ext2 etc and it works.
It's not on my GitHub yet, but if you PM I'll send later (not at home now)
I have an old version of the tool up on GitHub here: https://github.com/lazear/ext2util/tree ... 00edb40aa7
I make no promises that any newer commit than that will work, but it should at least enable you to write to inode 5. I started trying to develop my VFS layer after writing the ext2 direct block driver...Not a good idea. Ended up doing it in the proper order.
If there is wide spread interest in this tool, I wouldn't be opposed to going back and fixing it.
Also - having your FS drivers able to run from userspace in Linux sounds an excellent idea, I may well copy that
Re: Ext2/3/4 equivalent of mtools
This is exactly what I hate in *nix File system directory tree : it is unique per machine , you need to be root ( or setuid) to alter what a shell sees. Or use a vfs which makes you bound to gnome / KDE or some heavy machinery
- dchapiesky
- Member
- Posts: 204
- Joined: Sun Dec 25, 2016 1:54 am
- Libera.chat IRC: dchapiesky
Re: Ext2/3/4 equivalent of mtools
You could use a fuse filesystem adapter....madanra wrote:It would be useful to be able to manipulate ext* disk images purely from userspace, like mtools allows you to do for FAT*. Are there any such tools?
https://github.com/alperakcan/fuse-ext2
Plagiarize. Plagiarize. Let not one line escape thine eyes...