Ext2 filesystem on BluRay disc24 July 2020
The standard filesystem format for BluRay discs has a maximum individual file size of 4GB, which was a bit of a headache as I had some 5GB tarfiles I did not want to unpack before burning to disc. I was aware that it was possible to write Linux-native filesystems to disc in order to get around ISO9660 file size limitation at the expense of the disc being readable only on Linux, but the guide that explained how had long since disappeared from the internet. Having worked out how to do it I decided to record it here. The procedure is not specific to BluRay, as it can also be used on CD and DVD, but for the latter two disc types the ISO9660 limitations are not really an issue.
Why ext2?At time of writing BDXL discs of 100GB capacity are around £15 each which is not far off the £21 I recently paid for a 128GB SSD, and 50GB double-layer discs are a bit above £5 a pop. In contrast basic single-layer 25GB discs are now basically commodity so for the foreseeable future the latter are the only ones that are economic to use. The only limitation of ext2 that is even remotely going to be an issue is the 16GB maximum file size, and the improvements ext3 and ext4 have over ext2 are of minimal value for a read-only filesystem. Ext3 is basically ext2 with journaling, and ext4's advances all seem to be write-related. While ISO9660 does have later revisions that allow for files larger than 4GB how well these extensions are supported seems dubious, so I am back to the assumption that the disc will probably be Linux-only anyway.
Creating an imageThe first thing to do is create an empty file of the desired size and then initialise it as an ext2 filesystem, which is done by the two commands below. Some versions of
mke2fswill ask for confirmation before writing to a file rather than a block device, but the one that ships with Slackware simply gets on with the task.
dd if=/dev/zero of=wilderness.img bs=1024k count=23575 /sbin/mke2fs -b 2048 wilderness.img
From experimentation there is enough space on a BluRay disc for 23,575 blocks of 1 megabyte each, at least with the drive and disc stock I had at hand at the time. Actual capacity is probably a little bigger, but I did not want to waste a whole stack of discs finding the exact value.
Reserved blocksExt2 by default reserves 5% of space for use by root, the idea being if a system has run out of space it is still possible for root to login and sort things out. This is wasted space in this case, so it is best to tune the filesystem and set the reserved space to zero. Use the
-loption to see how much space is actually reserved.
/sbin/tune2fs -m0 wilderness.img
Of course it is possible to simply populate the image as root, but in general doing stuff as root that does not need to be is a bad idea
Populating the imageMount the image using the loopback device and then use it like any other storage device. Nothing stopping you moving files around as well as deleting them, but to avoid fragmentation it is probably best to just copy in files and then leave them alone.
mount -o ro wilderness.img /mnt/tmp
Burning to discOnce the filesystem is ready, unmount it and burn it in the same way as an ISO image:
growisofs -Z /dev/dvd=wilderness.img