GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing wiki.archlinux.org — Ext4 - ArchWiki Related articles From Ext4 - Linux Kernel Newbies:
Create a new ext4 filesystemTo format a partition do: # mkfs.ext4 /dev/partition See mke2fs(8) for more options. Tip To view/configure default mke2fs options, edit
/etc/mke2fs.conf.Bytes-per-inode ratioFrom mke2fs(8):
Creating a new file, directory, symlink etc. requires at least one free inode. If the inode count is too low, no file can be created on the filesystem even though there is still space left on it. Because it is not possible to change either the bytes-per-inode ratio or the inode count after the filesystem is created, However, for partitions with size in the hundreds or thousands of GB and average file size in the megabyte range, this usually results in a much too large inode number because the number of files created never reaches the number of inodes. This results in a waste of disk space, because all those unused inodes each take up 256 bytes on the filesystem (this is also set in This situation can be evaluated by comparing the $ df -h /home Filesystem Size Used Avail Use% Mounted on /dev/mapper/lvm-home 115G 56G 59G 49% /home $ df -hi /home Filesystem Inodes IUsed IFree IUse% Mounted on /dev/mapper/lvm-home 1.8M 1.1K 1.8M 1% /home To specify a different bytes-per-inode ratio, use the # mkfs.ext4 -T largefile /dev/device The bytes-per-inode ratio can also be set directly via the Tip Conversely, if setting up a partition dedicated to host millions of small files like emails or newsgroup items, use smaller usage-type values such as
news (one inode for every 4096 bytes) or small (same plus smaller inode and block sizes).Warning If making heavy use of symbolic links, make sure to keep the inode count high enough with a low bytes-per-inode ratio, because while not taking more space every new symbolic link consumes one new inode and therefore the filesystem may run out of them quickly.
Reserved blocksBy default, 5% of the filesystem blocks will be reserved for the super-user, to avoid fragmentation and "allow root-owned daemons to continue to function correctly after non-privileged processes are prevented from writing to the filesystem" (from mke2fs(8)). For modern high-capacity disks, this is higher than necessary if the partition is used as a long-term archive or not crucial to system operations (like It is generally safe to reduce the percentage of reserved blocks to free up disk space when the partition is either:
The To totally prevent reserving blocks upon filesystem creation, use: # mkfs.ext4 -m 0 /dev/device To change it to 1% afterwards, use: # tune2fs -m 1 /dev/device To set the number of reserved block space to an absolute size in gigabytes, use # tune2fs -r $((ngigs * 1024**3 / blocksize)) /dev/device
# tune2fs -l /dev/device | grep 'Block size:' Block size: 4096 The # tune2fs -r (math 'ngigs * 1024^3 / blocksize') /dev/device These commands can be applied to currently-mounted filesystems and changes will take effect immediately. Use findmnt(8) to find the device name: # tune2fs -m 1 "$(findmnt -no SOURCE /the/mount/point)" To query the current number of reserved blocks: # tune2fs -l /dev/mapper/proxima-root | grep 'Reserved block count:' Reserved block count: 2975334 This is the number of blocks, so this has to be multiplied by the filesystem's block size to get the number of bytes or gigabytes: Migrating from ext2/ext3 to ext4Mounting ext2/ext3 partitions as ext4 without convertingRationaleA compromise between fully converting to ext4 and simply remaining with ext2/ext3 is to mount the partitions as ext4. Pros:
Cons:
Note Except for the relative novelty of ext4 (which can be seen as a risk), there is no major drawback to this technique.
Procedure
Converting ext2/ext3 partitions to ext4RationaleTo experience the benefits of ext4, an irreversible conversion process must be completed. Pros: Cons:
ProcedureThese instructions were adapted from Kernel documentation and a BBS thread. Warning
In the following steps
Improving performanceDisabling access time updateThe ext4 file system records information about when a file was last accessed and there is a cost associated with recording it. See fstab#atime options for the Increasing commit intervalThe sync interval for data and metadata can be increased by providing a higher time delay to the The default 5 sec means that if the power is lost, one will lose as much as the latest 5 seconds of work.
It forces a full sync of all data/journal to physical media every 5 seconds. The filesystem will not be damaged though, thanks to the journaling.
The following fstab illustrates the use of /etc/fstab /dev/sda5 / ext4 defaults,commit=60 0 1 Turning barriers offWarning Disabling barriers for disks without battery-backed cache is not recommended and can lead to severe file system corruption and data loss.
Ext4 enables write barriers by default. It ensures that file system metadata is correctly written and ordered on disk, even when write caches lose power. This goes with a performance cost especially for applications that use fsync heavily or create and delete many small files. For disks that have a write cache that is battery-backed in one way or another, disabling barriers may safely improve performance. To turn barriers off, add the option /etc/fstab /dev/sda5 / ext4 defaults,barrier=0 0 1 Disabling journalingWarning Using a filesystem without journaling can result in data loss in case of sudden dismount like power failure or kernel lockup.
Disabling the journal with ext4 can be done with the following command on an unmounted disk: # tune2fs -O "^has_journal" /dev/sdXn Use the journal to optimize performanceThe Fast commits for ext4 article introduction summarizes succinctly why and how the mount options Note The
journal_async_commit mount option does not work with the default mount option data=ordered, therefore explicitly mount ext4_device with a different mode; see ext4(5) § data=.A further option is to to use a newer journal format, see #Enabling fast_commit. External journal deviceIf using the non-default # mke2fs -O journal_dev /dev/journal_device To assign # tune2fs -J device=/dev/journal_device /dev/ext4_device Replace Add the /etc/fstab /dev/ext4_device / ext4 defaults,x-systemd.requires=/dev/journal_device 0 1 This prevents issues if Note Both the
UUID and the devnum of the journal device are saved to the ext4 filesystem. When loading the journal device, only the devnum is used, causing issues as the devnum changes when disks are rearranged. Linux will refuse to mount the filesystem if the devnum points to the wrong device, but the below workarounds may still be helpful:
Ignore the saved devnum and force loading of the journal by path using the /etc/fstab /dev/ext4_device / ext4 defaults,x-systemd.requires=/dev/journal_device,journal_path=/dev/journal_device 0 1
/etc/e2fsck.conf [problems]
# PR_0_EXTERNAL_JOURNAL_HINT: Superblock hint for external superblock should be xxxx
0x000033 = {
# Tell e2fsck that if this problem is encountered, it can be fixed but should
# not be considered corruption, the filesystem should still be marked clean.
not_a_fix = true
}
Tips and tricksUsing file-based encryptionSince Linux 4.1, ext4 natively supports file encryption, see the fscrypt article. Encryption is applied at the directory level, and different directories can use different encryption keys. This is different from both dm-crypt, which is block-device level encryption, and from eCryptfs, which is a stacked cryptographic filesystem. Enabling metadata checksums in existing filesystemsWhen a filesystem has been created with e2fsprogs 1.43 (2016) or later, metadata checksums are enabled by default. Existing filesystems may be converted to enable metadata checksum support. To read more about metadata checksums, see the ext4 wiki. Tip Use
dumpe2fs to check the features that are enabled on the filesystem:
# dumpe2fs -h /dev/path/to/disk Note The filesystem must not be mounted.
First the partition needs to be checked and optimized using # e2fsck -Df /dev/path/to/disk Convert the filesystem to 64-bit: # resize2fs -b /dev/path/to/disk Finally enable checksums support: # tune2fs -O metadata_csum /dev/path/to/disk To verify: # dumpe2fs -h /dev/path/to/disk | grep features: Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum Maintenance when using LVMThe e2scrub tool checks metadata of the ext4 filesystem, if it is used in LVM logical volumes. The volume group must have 256MiB unallocated space for this check, because the tool creates a snapshot to check. As noted by the e2scrub(8) manual the tool does not repair errors, but report them and marks the filesystem to require an e2fsck (see e2fsck(8)) run prior to the next mount. The check can be automated, for example by enabling the packaged If the minimum 256MiB unallocated space is missing, see LVM#Resizing the logical volume and file system in one go. Enabling fast_commitThe ext4 "fast commits" feature introduces a new, lighter-weight journaling method. It is expected to significantly increase the performance of the ext4 filesystem,[6] To enable the feature on a new filesystem, include To enable the feature on an existing file system, run: # tune2fs -O fast_commit /dev/drivepartition To query the current configuration: # tune2fs -l /dev/drivepartition | grep features To disable the feature on an existing file system, run: # tune2fs -O '^fast_commit' /dev/drivepartition Warning Enabling this feature can cause system corruption in case of a powercut, see this BBS thread.
Enabling case-insensitive modeWarning
ext4 can be used in case-insensitive mode, which can increase the performance of applications and games running in Wine. This feature does not affect the entire file system, only directories that have the case-insensitive attribute enabled. First, enable the feature in the file system: # tune2fs -O casefold /dev/path/to/disk Enable the case-insensitive attribute in any directory: $ chattr +F /mnt/partition/case-insensitive-directory Note that the directory must be empty, and moving subdirectories from elsewhere will not cause them to inherit the attribute, so plan ahead accordingly. Resize filesystemThe resize2fs(8) program can resize ext2, ext3, or ext4 file systems. It can be used to enlarge or shrink an unmounted file system located on device. To resize an ext4 filesystem to a specific size: # resize2fs /dev/partition size If size parameter is not specified, it will default to the size of the partition. Make sure to prepare the required partition size beforehand (in case of inflating) with your favorite partitioning tool. See also
Retrieved from "https://wiki.archlinux.org/index.php?title=Ext4&oldid=876860" |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |