码迷,mamicode.com
首页 > 其他好文 > 详细

磁盘格式化

时间:2018-04-11 10:41:17      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:磁盘格式化

一、磁盘格式化(上)
1、centos7系统支持的文件系统格式有:
[root@linux-01 ~]# cat /etc/filesystems
xfs //系统默认支持的系统格式,例如/ /boot分区都是xfs格式
ext4 //centos6系统默认的文件系统格式
ext3 //centos6系统之前的文件系统格式
ext2 //更早之前的版本
nodev proc
nodev devpts
iso9660
vfat
hfs
hfsplus
*

2、查看一个分区的文件系统是什么格式:使用mount命令
[root@linux-01 ~]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=490012k,nr_inodes=122503,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,seclabel,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_prio,net_cls)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/sda3 on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=30,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=12732)
mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=99972k,mode=700)

3、 mke2fs命令:指定文件系统格式
-t选项:指定格式化后文件系统的格式
-b:指定块大小
例:
[root@linux-01 ~]# mke2fs -b 2048 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
196608 inodes, 1572864 blocks
78643 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=538968064
96 block groups
16384 blocks per group, 16384 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104

Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done

4、使用ls -l命令和du -sh命令查看空文件的大小显示都一样为0字节
例:
[root@linux-01 ~]# ls -l
total 8
-rw-r--r--. 1 root root 65 Mar 29 01:12 11.txt
drwxr-xr-x. 2 root root 32 Mar 30 06:49 123
-rwx------. 1 root root 0 Mar 28 08:20 2.txt
-rw-------. 1 root root 2331 Mar 28 09:02 anaconda-ks.cfg.1
[root@linux-01 ~]# du -sh 2.txt
0 2.txt
但是如果文件有内容,但实际小于4KB的文件,ls -l显示文件的真实大小,du -sh命令显示为4KB,因为这个文件单独占用了一个块,这个块大小最小为4KB,du -sb命令和ls -l命令查看到的文件大小是一致的
例:
[root@linux-01 ~]# echo 1 > 2.txt //为2.txt追加一个字符串
[root@linux-01 ~]# ls -l
total 12
-rw-r--r--. 1 root root 65 Mar 29 01:12 11.txt
drwxr-xr-x. 2 root root 32 Mar 30 06:49 123
-rwx------. 1 root root 2 Apr 10 22:22 2.txt //ls -l命令显示文件大小为2字节
-rw-------. 1 root root 2331 Mar 28 09:02 anaconda-ks.cfg.1
[root@linux-01 ~]# du -sh 2.txt
4.0K 2.txt //du -sh命令显示大小为4KB
[root@linux-01 ~]# du -sb 2.txt //du -sb命令显示大小为2字节
2 2.txt

5、将分区格式化为ext4格式的文件系统:使用mke2fs命令
[root@linux-01 ~]# mke2fs -t ext4 /dev/sdb1 或者 mkfs.ext4 /dev/sdb1 //效果一样
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
196608 inodes, 786432 blocks
39321 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=805306368
24 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912

Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

6、将sdb1分区格式设置为xfs文件系统:
[root@linux-01 ~]# mkfs.xfs -f /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=196608 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=786432, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

7、查看没有挂载到挂载点的分区:
[root@linux-01 ~]# blkid /dev/sdb1
/dev/sdb1: UUID="961b34ec-4b1d-402a-ada7-b6766130220c" TYPE="xfs"

二、磁盘格式化(下)
1、 mkfs.ext4 == mk2fs -t ext4 (目前唯一不足的是mk2fs -t 不支持xfs格式)

2、-m选项:指定这个分区预留的空间大小
技术分享图片
3、mke2fs -i命令:-i选项指定多少个字节对应一个inode(如果需要更多indoe,将-i后面的数字改小,最低1个块对应1个indoe)
技术分享图片
blocks数是inodes数的2倍,之前blocks数是inodes数的4倍

磁盘格式化

标签:磁盘格式化

原文地址:http://blog.51cto.com/13669226/2096766

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!