CentOS使用mkfs.ext4快速格式化大容量硬盘

  • Post author:
  • Post category:其他


昨天(2014-09-16)屁民瑞威为了测试一个系统,给2台虚拟机各分配了1.5TB的存储空间。但是当使用fdisk创建分区后,使用mkfs.ext4格式化文件系统时,那个速度之慢,为了不搞坏硬盘,没有取消格式化,最终其中一台虚拟机等了几个小时才完成格式化。在这期间就想有没有类似windows的快速格式化选项。

通过mkfs.ext4 –help没有看出所以然来,网上有兄弟指出可以通过mkfs.ext4  -T largefile /dev/xxx这个方式快速格式化硬盘。man mkfs.ext4一路找可以看到这样的信息:

-T usage-type[,...]
              Specify  how  the filesystem is going to be used, so that mke2fs
              can choose optimal filesystem  parameters  for  that  use.   The
              usage  types that are supported are defined in the configuration
              file /etc/mke2fs.conf(5).  The user  may  specify  one  or  more
              usage types using a comma separated list.

              If  this  option  is is not specified, mke2fs will pick a single
              default usage type based on the size of  the  filesystem  to  be
              created.   If  the  filesystem  size  is less than or equal to 3
              megabytes, mke2fs will use the filesystem type floppy.   If  the
              filesystem  size is greater than 3 but less than or equal to 512
              megabytes, mke2fs(8) will use the filesystem small.   Otherwise,
              mke2fs(8) will use the default filesystem type default.for  that  use.   The
              usage  types that are supported are defined in the configuration
              file /etc/mke2fs.conf(5).  The user  may  specify  one  or  more
              usage types using a comma separated list.

              If  this  option  is is not specified, mke2fs will pick a single
              default usage type based on the size of  the  filesystem  to  be
              created.   If  the  filesystem  size  is less than or equal to 3
              megabytes, mke2fs will use the filesystem type floppy.   If  the
              filesystem  size is greater than 3 but less than or equal to 512
              megabytes, mke2fs(8) will use the filesystem small.   Otherwise,
              mke2fs(8) will use the default filesystem type default.

– T usage – type [ , . . . ]

Specify   how   the filesystem is going to be used , so that mke2fs

can choose optimal filesystem   parameters   for    that   use .    The

usage   types that are supported are defined in the configuration

file / etc / mke2fs . conf ( 5 ) .    The user   may   specify   one   or    more

usage types using a comma separated list .

If    this    option   is is not specified , mke2fs will pick a single

default usage type based on the size of   the   filesystem   to    be

created .    If    the   filesystem   size   is less than or equal to 3

megabytes , mke2fs will use the filesystem type floppy .    If    the

filesystem   size is greater than 3 but less than or equal to 512

megabytes , mke2fs ( 8 ) will use the filesystem small .    Otherwise ,

mke2fs ( 8 ) will use the default filesystem type default .

然后查看/etc/mke2fs.conf

[defaults]
  base_features = sparse_super,filetype,resize_inode,dir_index,ext_attr
  blocksize = 4096
  inode_size = 256
  inode_ratio = 16384

[fs_types]
  ext3 = {
    features = has_journal
  }
  ext4 = {
    features = has_journal,extent,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize
    inode_size = 256
  }
  ext4dev = {
    features = has_journal,extent,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize
    inode_size = 256
    options = test_fs=1
  }
  small = {
    blocksize = 1024
    inode_size = 128
    inode_ratio = 4096
  }
  floppy = {
    blocksize = 1024
    inode_size = 128
    inode_ratio = 8192
  }
  news = {
    inode_ratio = 4096
  }
  largefile = {
    inode_ratio = 1048576
    blocksize = -1
  }
  largefile4 = {
    inode_ratio = 4194304
    blocksize = -1
  }
  hurd = {
       blocksize = 4096
       inode_size = 128
  }  base_features = sparse_super,filetype,resize_inode,dir_index,ext_attr
  blocksize = 4096
  inode_size = 256
  inode_ratio = 16384

[fs_types]
  ext3 = {
    features = has_journal
  }
  ext4 = {
    features = has_journal,extent,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize
    inode_size = 256
  }
  ext4dev = {
    features = has_journal,extent,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize
    inode_size = 256
    options = test_fs=1
  }
  small = {
    blocksize = 1024
    inode_size = 128
    inode_ratio = 4096
  }
  floppy = {
    blocksize = 1024
    inode_size = 128
    inode_ratio = 8192
  }
  news = {
    inode_ratio = 4096
  }
  largefile = {
    inode_ratio = 1048576
    blocksize = -1
  }
  largefile4 = {
    inode_ratio = 4194304
    blocksize = -1
  }
  hurd = {
       blocksize = 4096
       inode_size = 128
  }

[ defaults ]

base_features = sparse_super , filetype , resize_inode , dir_index , ext_attr

blocksize = 4096

inode_size = 256

inode_ratio = 16384

[ fs_types ]

ext3 = {

features = has _ journal

}

ext4 = {

features = has_journal , extent , huge_file , flex_bg , uninit_bg , dir_nlink ,extra_isize

inode_size = 256

}

ext4dev = {

features = has_journal , extent , huge_file , flex_bg , uninit_bg , dir_nlink ,extra_isize

inode_size = 256

options = test_fs = 1

}

small = {

blocksize = 1024

inode_size = 128

inode_ratio = 4096

}

floppy = {

blocksize = 1024

inode_size = 128

inode_ratio = 8192

}

news = {

inode_ratio = 4096

}

largefile = {

inode_ratio = 1048576

blocksize = – 1

}

largefile4 = {

inode_ratio = 4194304

blocksize = – 1

}

hurd = {

blocksize = 4096

inode_size = 128

}

测试mkfs.ext4  -T largefile /dev/xxx这个方式,几乎在几分钟完成快速格式化。