Skip to content

Commit

Permalink
ADD EXT2 SUPPORT WOOO
Browse files Browse the repository at this point in the history
  • Loading branch information
pcd1193182 committed Jan 17, 2020
1 parent 56932da commit edb28bf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
34 changes: 25 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# cursedfs

Make a disk image formatted with both ZFS and FAT, at once.
Make a disk image formatted with ZFS, ext2, and FAT all at once.

```bash
~/cursedfs% wget 'https://github.com/pcd1193182/cursedfs/releases/download/v1.1/cursed.img'
~/cursedfs% sudo mount -o loop -t msdos cursed.img mountpoint/
~/cursedfs% ls mountpoint/
duckroll.jpg
~/cursedfs% sudo umount mountpoint
~/cursedfs% sudo mount -o loop -t ext2 cursed.img mountpoint/
~/cursedfs% ls mountpoint/
rickroll.jpg
~/cursedfs% sudo zpool import cursed -d .
~/cursedfs% ls /cursed/
rickroll.jpg
rickroll.mp4
```

# Why?
Expand All @@ -18,13 +22,25 @@ rickroll.jpg

# How?

Bulding on NieDzejkob's great work, since zfs leaves the first 8k of
the disk empty, you can easily have the two coexist. The FAT
filesystem lives in zfs's 3.5M of reserved boot space. This can be
extended with a read-only ext2 filesystem as well; I'll try that
eventually
FAT uses the first 512 bytes to store its superblock. ext2 stores its
metadata starting at the third 512 bytes. ZFS stores its metadata
starting at the 8k marker. By using a program that creates an ext2
filesystem that marks many of its blocks unusable, all three of these
can be made to not overlap their metadata, allowing them to live in
harmony. This builds on NieDzejkob's great work. The ext2 and FAT
filesystems live inside ZFS's 3.5MiB boot block space; the ext2
filesystem lives in the first 512KiB of it, and the FAT filesystem
lives in the next 3 MiB.

# Can I write to the filesystems?

Yes! Because FAT reserves the sectors used by ZFS's labels and ZFS
doesn't write to the boot space, both exist in harmony.
Yes! Because FAT and ext2 reserve the sectors used by ZFS's labels,
and FAT reserves all space used by ext2, and ZFS doesn't write to the
boot space, all three exist in harmony.

# Notes

You will need to use the [mkext2
utility](https://github.com/pcd1193182/mkext2) to build your cursed
filesystem, since it knows how to reserve blocks when creating an ext2
filesystem.
9 changes: 6 additions & 3 deletions mkfs.cursed
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

set -euxo pipefail
FAT_TMP="$(mktemp)"
trap "rm $FAT_TMP" EXIT
EXT2_TMP="$(mktemp)"
trap "rm $FAT_TMP $EXT2_TMP" EXIT

truncate -s 64M cursed.img
truncate -s 4M $FAT_TMP
mkfs.fat -R 1024 cursed.img
dd if=$FAT_TMP of=cursed.img bs=512 skip=1 seek=1 conv=notrunc
mkext2 $EXT2_TMP 2048 1024
mkfs.fat -R 2048 $FAT_TMP
dd if=$EXT2_TMP of=$FAT_TMP bs=512 skip=1 seek=1 conv=notrunc
dd if=$FAT_TMP of=cursed.img bs=512 conv=notrunc
sudo zpool create cursed $(pwd)/cursed.img

0 comments on commit edb28bf

Please sign in to comment.