最後更新: 2020-07-26
介紹
resize2fs - ext2/ext3/ext4 file system resizer
目錄
Expand with parted
Step
- parted
- resize2fs
parted: Resize partition first
(parted) select /dev/md0
(parted) resize 1 0 20G
如果 parted 不支援 resize, 那就要 rm 後再 mkpart
過程
parted /dev/sda (parted) print Number Start End Size Type File system Flags 1 S E M primary T (parted) rm 1 (parted) mkpart primary T S NewSize (parted) quit
* ext3, ext4 support online resize (du 時會見到它(fs)會不斷變大)
* 正確要 enlarge or shrink an unmounted file system
在 resize 前, 它會建議
resize2fs 1.42 (29-Nov-2011) Please run 'e2fsck -f /dev/lxc/vps1' first.
行一次 fsck:
e2fsck -f /dev/sda3
e2fsck 1.41.14 (22-Dec-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /: 869865/9797632 files (0.6% non-contiguous), 3491321/19565161 blocks
Example
當沒有指定 device 的 size, 那 resize2fs 會把 partition 擴到最大
resize2fs /dev/sda3 2500M
resize2fs /dev/sda3 25G
單位:
- 'M'
- 'G'
Useful opts:
- -p Prints out a percentage completion bars
- -P Print the minimum size of the filesystem
Estimated minimum size of the filesystem: 15916657
- -M Shrink the filesystem to the minimum size.
減容量(LVM)
Step
- Shrinking the filesystem
- Shrinking the block device(Partition)
umount /dev/mapper/vg3t-backup
# resize2fs 必須要你 e2fsck
e2fsck -f /dev/mapper/vg3t-backup
# Shrinking to size 300G
resize2fs /dev/mapper/vg3t-backup 300G
# count X size = 300G
dumpe2fs -h /dev/mapper/vg3t-backup
Block count: 78643200 Block size: 4096
lvreduce -L300G /dev/mapper/vg3t-backup
WARNING: Reducing active logical volume to 300.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce backup? [y/n]: y
lvdisplay vg3t/backup