{"id":420,"date":"2020-08-18T19:23:47","date_gmt":"2020-08-18T20:23:47","guid":{"rendered":"http:\/\/www.linux-tutorial.info\/?page_id=77"},"modified":"2020-08-22T19:26:39","modified_gmt":"2020-08-22T20:26:39","slug":"this-is-the-page-title-toplevel-253","status":"publish","type":"page","link":"http:\/\/www.linux-tutorial.info\/?page_id=420","title":{"rendered":"The EXT2 File System"},"content":{"rendered":"\n<title>The Second Extended File system (EXT2)<\/title>\n<p>\n<img decoding=\"async\" src=\"ext2.gif\">\n<p>\nFigure: Physical Layout of the EXT2 File system\n<p>\nThe Second Extended File system was devised (by R&#233;my Card) as an extensible\nand powerful file system for Linux.\nIt is also the most successful file system so far in the Linux community and is the\nbasis for all of the currently shipping Linux distributions.\n<p>\nThe EXT2 file system, like a lot of the file systems, is built on the premise that the\ndata held in files is kept in data blocks.\nThese data blocks are all of the same length and, although that length can\nvary between different EXT2 file systems the block size of a particular\nEXT2 file system is set when it is created (using <command>mke2fs<\/command>).\nEvery file&#8217;s size is rounded up to an integral number of blocks.\nIf the block size is 1024 bytes, then a file of 1025 bytes will occupy two 1024 byte\nblocks.\nUnfortunately this means that on average you waste half a block per file.\nUsually in computing you trade off CPU usage for memory and disk space utilisation.\nIn this case Linux, along with most operating systems, trades off a relatively\ninefficient disk usage in order to reduce the workload on the CPU.\nNot all of the blocks in the file system hold data, some must be used to contain the\ninformation that describes the structure of the file system.\nEXT2 defines the file system topology by describing each file\nin the system with an inode data structure.\nAn inode describes which blocks the data within a file occupies as well as the\naccess rights of the file, the file&#8217;s modification times and the type of the file.\nEvery file in the EXT2 file system is described by a single inode and each inode\nhas a single unique number identifying it.\nThe inodes for the file system are all kept together in inode tables.\nEXT2 directories are simply special files\n(themselves described by inodes)\nwhich contain pointers to the inodes  of their directory entries.\n<p>\nThe figure above shows the layout of the\nEXT2 file system as occupying a series of blocks in a block structured device.\nSo far as each file system is concerned, block devices are just a series of blocks\nthat can be read and written. A file system does not need to concern itself with\nwhere on the physical media\na block should be put, that is the job of the device&#8217;s driver.\nWhenever a file system needs to read information or data from the block device\ncontaining it, it requests that its supporting device driver reads an integral\nnumber of blocks.\nThe EXT2 file system divides the logical partition that it occupies\ninto Block Groups.\n<p>\nEach group duplicates information critical to the integrity of the file system\nas well as holding real files and directories as  blocks of information and data.\nThis duplication is neccessary should a disaster occur and the file system need\nrecovering.\nThe subsections describe in more detail the contents of each Block Group.\n<p>\n<!-- START copyright James Mohr:1996-2003: -->\n<p>\nOne benefit of the ext2fs over the extfs is the\nsize of the file systems that can be managed. Currently (after some enhancements\nin the VFS layer), the ext2fs can access file systems as large as 4TB. In\ncontrast to other UNIXs, the ext2fs uses a variable\nlength directory and can  have files names that are as long as 255 characters.\n<\/p>\n<p>\nWhen creating the\nfile system, the ext2fs enables you to choose what size block you want. Using\nlarger blocks will speed up the data transfer because the head disk does not\nneed to look (seek) as much. However, if you have a lot of small files, a larger\nblock size means you waste more space.\n<\/p>\n<question id=\"200\" text=\"Where is the path to the 'real' file stored with a fast symbolic links?\" \/>\n<concept id=\"152\" description=\"With a fast symbolic links the path to the 'real' file is stored in the inode.\" \/>\n<question id=\"201\" text=\"How many characters long can file names be with fast symbolic links?\" \/>\n<p>\nAlso to speed up access, the ext2fs\nuses a technique called a &#8220;fast <glossary>symbolic link<\/glossary>.&#8221;\nOn many <glossary>UNIX<\/glossary> systems,\nthe files to which symbolic links point are stored as files themselves. This\nmeans that each time a file is read as a <glossary>symbolic link<\/glossary>,\nthe disk is accessed to get the <glossary>inode<\/glossary>\nof the link, the path is read out of the file, and its inode needs\nto be read, and then the actual file can be accessed.\n<\/p>\n<p>\nWith a fast symbolic link, the path to the file is stored in the\n<glossary>inode<\/glossary>. This not only speeds up\naccess but also saves the space that the file is no longer taking on the hard\ndisk. The only drawback is that when the path to the real file has more than 60\ncharacters, it cannot fit in the <glossary>inode<\/glossary>\nand must sit in a file. Therefore, if you\nare using symbolic links and want to increase performance, make sure the path\nhas fewer than 60 characters.\n<\/p>\n<question id=\"202\" text=\"Each block group in an ext2fs has a descriptor which contains all but which of the following?\" \/>\n<p>\nAnother advantages of the ext2fs is its reliability. The ext2fs is made of what are\ncalled &#8220;block groups.&#8221; Each block group has a block group <glossary>descriptor<\/glossary>,\nwhich provides an information copy of the <glossary>superblock<\/glossary>,\nas well as a block bitmap, <glossary>inode<\/glossary> bitmap, a piece of the\ninode table, and data blocks.\n<\/p>\n<p>\nThere is also an entry that contains the\nnumber of directories within the group block. When creating a new directory, the\nsystem will try to put the directory into the block group with the fewest\ndirectories. This makes accessing any one directory quicker.\n<\/p>\n<concept id=\"153\" description=\" An ext2fs block group contains copies of the primary control structures, making recovery easy.\" \/>\n<question id=\"204\" text=\"An ext2fs block group contains copies of the primary control structures, making recovery easy.\" \/>\n<p>\nBecause the block group contains copies of the primary control structures, it can be\nrepaired by these copies should the <glossary>superblock<\/glossary>\nat the start of the disk get corrupted. In addition, because the <glossary>inode<\/glossary>\ntable, as such, is spread out across the disk, you have to search less. Plus,\nthe distance between the <glossary>inode<\/glossary> table and the data block is\nreduced, thereby increasing performance ever further.\n<\/p>\n<question id=\"203\" text=\"How does the ext2fs speed up all sequential accesses?\" \/>\n<p>\nThere&#8217;s still more! The ext2fs will preallocate up to eight\nadjacent blocks when it allocates a block for a file. This gives the file a\nlittle room to grow. By preallocating the blocks, you have a file that is\nlocated in the same area of the disk. This speeds up all sequential\naccesses.\n<\/p>\n<p>\nThe directories entries in the ext2fs are in a singly linked\nlist, as compared to an array with fixed entry lengths on some systems. Within\nthe directory entry, you will find the name of the file as well as the inode\nnumber. Note that this is the only place where the name of the file appears. In\naddition, there&#8217;s a field that has the total length of the record in bytes (which\nis always a multiple of 4) that is then used to calculate the start of the next\nblock. Therefore, there are no pointers as in other linked lists.\n<\/p>\n <question id=\"205\" text=\"The ext2fs saves space in the directories by keeping the file names in what kind of structure.\" \/>\n<p>\nWhen a file is deleted, the <glossary>inode<\/glossary>\nis set to 0 and the previous entry &#8220;takes over&#8221; the slot. This saves time because no shifts\nare required. There may be a slight loss in space, but if a new entry that will fill up the\nold slot is created, it will fill up the old slot. Because of this scheme, you can implement\nlong file names without wasting space. In some systems, specific-length fields\nare set aside. If the file name doesn&#8217;t fill up the slot, the space is just wasted.\n<\/p>\n<!-- START copyright James Mohr:1996-2003: -->\n","protected":false},"excerpt":{"rendered":"<p>The Second Extended File system (EXT2) Figure: Physical Layout of the EXT2 File system The Second Extended File system was devised (by R&#233;my Card) as an extensible and powerful file system for Linux. It is also the most successful file &hellip; <a href=\"http:\/\/www.linux-tutorial.info\/?page_id=420\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-420","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/420","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=420"}],"version-history":[{"count":1,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/420\/revisions"}],"predecessor-version":[{"id":742,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/420\/revisions\/742"}],"wp:attachment":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=420"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}