filesystem:increase_the_size_of_an_ext2_ext3_or_ext4_filesystem
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
filesystem:increase_the_size_of_an_ext2_ext3_or_ext4_filesystem [2019/11/29 12:07] – removed peter | filesystem:increase_the_size_of_an_ext2_ext3_or_ext4_filesystem [2020/07/15 20:50] (current) – old revision restored (2016/07/07 12:20) 95.91.41.38 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Filesystem - Increase the size of an ext2, ext3 or ext4 filesystem ====== | ||
+ | |||
+ | To increase the size of an ext2, ext3 or ext4 filesystem so as to completely fill a block device | ||
+ | |||
+ | Increasing the usable capacity of a filesystem on a resizeable block device (such as a partition or logical volume) is a two-step process: | ||
+ | |||
+ | - Increase the size of the block device. | ||
+ | - Increase the size of the filesystem to fill the block device. | ||
+ | |||
+ | The method for the first step depends on the type of block device, and the method for the second step depends on the type of filesystem. | ||
+ | |||
+ | **NOTE**: | ||
+ | |||
+ | Resizing is performed using the **resize2fs** command, however there are some preparatory steps that you can take which will reduce the risk of data loss: | ||
+ | |||
+ | * Ensure that you have an up to date backup. | ||
+ | * Unmount the filesystem. | ||
+ | * Check the filesystem. | ||
+ | |||
+ | **NOTE**: | ||
+ | |||
+ | |||
+ | ===== Ensure that you have an up to date backup of the filesystem ===== | ||
+ | |||
+ | Extending a filesystem is a moderately high-risk operation, so if you take backups of the data at all then this is a good time to perform one. | ||
+ | |||
+ | Optionally, unmount the filesystem | ||
+ | |||
+ | Modern versions of the Linux kernel can expand an ext3 or ext4 filesystem while it is mounted. | ||
+ | |||
+ | <code bash> | ||
+ | umount / | ||
+ | </ | ||
+ | |||
+ | At the time of writing, current (2.6-series) kernels did not support online resizing of ext2 filesystems. | ||
+ | |||
+ | ===== Check the filesystem ===== | ||
+ | |||
+ | One factor that would increase the risk of failure is if there are pre-existing errors in the filesystem. For non-mounted filesystems, | ||
+ | |||
+ | <code bash> | ||
+ | fsck -f / | ||
+ | </ | ||
+ | |||
+ | **resize2fs** will refuse to run if it thinks the filesystem ought to be checked first, however there is no harm in running fsck regardless provided that you are confident the filesystem is not mounted. | ||
+ | |||
+ | For mounted filesystems you should definitely not do this, otherwise fsck may itself cause data loss. | ||
+ | |||
+ | |||
+ | ===== Resize the filesystem ===== | ||
+ | |||
+ | Use the **resize2fs** command to resize the filesystem: | ||
+ | |||
+ | <code bash> | ||
+ | resize2fs / | ||
+ | </ | ||
+ | |||
+ | You can specify the required final size of the filesystem, but there is no need to in this instance because it defaults to the size of the device. | ||
+ | |||
+ | The amount of time taken by resize2fs to enlarge a filesystem is broadly comparable to that taken by **mkfs** to create a new one. The example described here took about a minute during testing, but this will obviously vary with the speed of the hardware. | ||
+ | |||
+ | You can request a progress bar using the -p option. | ||
+ | |||
+ | When resize2fs has finished it should report the new size of the filesystem in blocks: | ||
+ | |||
+ | < | ||
+ | The filesystem on / | ||
+ | </ | ||
+ | |||
+ | Note that resize2fs does not change the block size, even if a freshly created filesystem on the same device would default to a larger size. For this reason, recreation may be a better option if you need to turn a very small filesystem into a very large one. | ||
+ | |||
+ | |||
+ | ===== Testing ===== | ||
+ | |||
+ | You can obtain an approximate value for the new size of the filesystem using the **df** command once it has been remounted. | ||
+ | |||
+ | < | ||
+ | Filesystem | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | The number of 1k blocks reported (123854820 in this case) is slightly less than the full size of the device (125829120). | ||
+ | |||
+ | <code bash> | ||
+ | dumpe2fs -h / | ||
+ | </ | ||
+ | |||
+ | The output is quite lengthy, but should contain the following information: | ||
+ | |||
+ | < | ||
+ | Inode count: | ||
+ | Block count: | ||
+ | Reserved block count: | ||
+ | Free blocks: | ||
+ | Free inodes: | ||
+ | First block: | ||
+ | Block size: 4096 | ||
+ | Fragment size: 4096 | ||
+ | </ | ||
+ | |||
+ | The block count should be the same as the value reported by **resize2fs**. | ||
+ | |||
+ | |||
+ | ===== See also ===== | ||
+ | |||
+ | * [[LVM: | ||
+ | * [[Filesystem: | ||
filesystem/increase_the_size_of_an_ext2_ext3_or_ext4_filesystem.1575029260.txt.gz · Last modified: 2020/07/15 10:30 (external edit)