Search code examples
bootloaderext2

Is ext2 inode 5 (EXT2_BOOT_LOADER_INO) used by any operating systems?


In ext2, there are a number of reserved inodes, such as inode 2 being the root directory. In the Linux ext2 header file, inode 5 is defined as a "Boot loader inode".

Do any operating systems actually use this?

How do you read from and write to this inode?


Solution

  • The number of reserved inodes can be extracted from the superblock structure from linux/fs/ext2.h

    /*
    * Structure of the super block
    */
    struct ext2_super_block {
    ...
        __le32  s_first_ino;        /* First non-reserved inode */
    ...
    }
    

    So the number of reserved inodes is s_first_ino - 1. This number depends on the revision you are using.

    The number of the first non-reserved inode for old revision is:

    /* First non-reserved inode for old ext2 filesystems */
    #define EXT2_GOOD_OLD_FIRST_INO 11
    

    All the reserved inodes are also defined here:

    /*
    * Special inode numbers
     */
    #define EXT2_BAD_INO             1  /* Bad blocks inode */
    #define EXT2_ROOT_INO            2  /* Root inode */
    #define EXT2_BOOT_LOADER_INO     5  /* Boot loader inode */
    #define EXT2_UNDEL_DIR_INO       6  /* Undelete directory inode */
    

    EXT2_BOOT_LOADER_INO points to where the bootloader is placed, it is not currently in use. It is just a unused mechanism (until the kernel version 3.10 where its used to swap boot code as you can seee here) to make easy to place and locate the boot code, so you don't have to search.

    As the previous link says, GRUB wants to use EXT2_BOOT_LOADER_INO in the future as a control mechanism:

    * Support embedding a Stage 1.5 in the EXT2_BOOT_LOADER_INO of an ext2fs
    partition, so that it won't be accidentally erased or modified by
    the kernel.
    

    ...even if there was not code at that time to read or modify the inode.