Block filesystems
- Storage devices are classified in two main types: block devices and flash devices
- They are handled by different subsystems and different filesystems
- Block devices can be read and written to on a per-block basis, in random order, without erasing.
- Hard disks, floppy disks, RAM disks
- USB keys, SSD, Compact Flash, SD card, eMMC: these are based on flash storage, but have an integrated controller that emulates a block device, managing the flash in a transparent way.
- Raw flash devices are driven by a controller on the SoC. They can be read, but writing requires erasing, and often occurs on a larger size than the “block” size.
- NOR flash, NAND flash
Block device list
- The list of all block devices available in the system can be found in /proc/partitions $ cat /proc/partitions major minor #blocks name
- And also in /sys/block/
Partitioning
- Block devices can be partitioned to store different parts of a system
- The partition table is stored inside the device itself, and is read and analyzed automatically by the Linux kernel
- mmcblk0 is the entire device
- mmcblk0p2 is the second partition of mmcblk0
- Two partition table formats:
- MBR, the legacy format
- GPT, the new format, not yet used everywhere, but becoming more and more common
- Numerous tools to create and modify the partitions on a block device: fdisk, gdisk, cfdisk, sfdisk, parted, etc.
Transfering data to a block device
- It is often necessary to transfer data to or from a block device in a raw way
- Especially to write a filesystem image to a block device
- This directly writes to the block device itself, bypassing any filesystem layer.
- The block devices in /dev/ allow such raw access
- dd is the tool of choice for such transfers:
- dd if=/dev/mmcblk0p1 of=testfile bs=1M count=16 Transfers 16 blocks of 1 MB from /dev/mmcblk0p1 to testfile
- dd if=testfile of=/dev/sda2 bs=1M seek=4 Transfers the complete contents of testfile to /dev/sda2, by blocks of 1 MB, but starting at offset 4 MB in /dev/sda2
Available filesystems
Standard Linux filesystem format: ext2, ext3, ext4
- The standard filesystem used on Linux systems is the series of ext{2,3,4} filesystems
- ext2
- ext3, brought journaling compared to ext2
- ext4, mainly brought performance improvements and support for even larger filesystems
- ext4 is now the default filesystem used on most Linux distributions
- It supports all features Linux needs from a filesystem: permissions, ownership, device files, symbolic links, etc.
Journaled filesystems
Designed to stay in a coherent state even after system crashes or a sudden poweroff
- Writes are first described in the journal before being committed to files (can be all writes, or only metadata writes depending on the configuration)
- Allows to skip a full disk check at boot time after an unclean shutdown
Filesystem recovery after crashes
- Thanks to the journal, the recovery at boot time is quick, since the operations in progress at the moment of the unclean shutdown are clearly identified
- Does not mean that the latest writes made it to the storage: this depends on syncing the changes to the filesystem.
Other Linux/Unix filesystems
- btrfs, intended to become the next standard filesystem for Linux. Integrates numerous features: data checksuming, integrated volume management, snapshots, etc.
- XFS, high-performance filesystem inherited from SGI IRIX, still actively developed.
- JFS, inherited from IBM AIX. No longer actively developed, provided mainly for compatibility.
- reiserFS, used to be a popular filesystem, but its latest version Reiser4 was never merged upstream. All those filesystems provide the necessary functionalities for Linux systems: symbolic links, permissions, ownership, device files, etc.
F2FS: filesystem for flash-based storage
http://en.wikipedia.org/wiki/F2FS
- Filesystem that takes into account the characteristics of flash-based storage: eMMC, SD cards, SSD, etc.
- Developed and contributed by Samsung
- Available in the mainline Linux kernel
- For optimal results, need a number of details about the storage internal behavior which may not easy to get
- Benchmarks: best performer on flash devices most of the time: See http://lwn.net/Articles/520003/
- Technical details: http://lwn.net/Articles/518988/
- Not as widely used as ext3,4, even on flash-based storage.
Squashfs: read-only filesystem
- Read-only, compressed filesystem for block devices. Fine for parts of a filesystem which can be read-only (kernel, binaries...)
- Great compression rate, which generally brings improved read performance
- Used in most live CDs and live USB distributions
- Supports several compression algorithm (LZO, XZ, etc.)
- Benchmarks: roughly 3 times smaller than ext3, and 2-4 times faster (http://elinux.org/Squash_Fs_Comparisons)
- Details: http://squashfs.sourceforge.net/
Compatibility filesystems
Linux also supports several other filesystem formats, mainly to be interopable with other operating systems:
- vfat for compatibility with the FAT filesystem used in the Windows world and on numerous removable devices
- This filesystem does not support features like permissions, ownership, symbolic links, etc. Cannot be used for a Linux root filesystem.
- ntfs for compatibility with the NTFS filesystem used on Windows
- hfs for compatibility with the HFS filesystem used on Mac OS
- iso9660, the filesystem format used on CD-ROMs, obviously a read-only filesystem
tmpfs: filesystem in RAM
- Not a block filesystem of course!
- Perfect to store temporary data in RAM: system log files, connection data, temporary files...
- More space-efficient than ramdisks: files are directly in the file cache, grows and shrinks to accommodate stored files
- How to use: choose a name to distinguish the various tmpfs instances you could have. Examples: mount -t tmpfs varrun /var/run mount -t tmpfs udev /dev
- See Documentation/filesystems/tmpfs.txt in kernel sources.