【CentOS 7筆記20】,磁盤格式化#

shallow丿ovenode


CentOS 7支持的文件系統

[root@localhost ~]# cat /etc/filesystems
	xfs
	ext4
	ext3
	ext2
	nodev proc
	nodev devpts
	iso9660
	vfat
	hfs
	hfsplus
[root@localhost ~]# df -h
	Filesystem      Size  Used Avail Use% Mounted on
	/dev/sda3        28G  845M   27G   3% /
	devtmpfs        909M     0  909M   0% /dev
	tmpfs           914M     0  914M   0% /dev/shm
	tmpfs           914M  8.6M  905M   1% /run
	tmpfs           914M     0  914M   0% /sys/fs/cgroup
	/dev/sda1       197M   75M  123M  38% /boot

/和/boot爲xfs格式 以前的版本爲ext四、ext三、ext2居多,到CentOS 7爲xfs格式 格式化爲ext也會默認爲xfslinux

已用的磁盤的文件系統

[root@localhost ~]# mount
	proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
	sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
	devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=929824k,nr_inodes=232456,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 (rw,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/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
	cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
	cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
	cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
	cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
	cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls)
	cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
	cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
	cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
	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=32,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
	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)

[root@localhost ~]# mount | grep /dev/sd
	/dev/sda3 on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
	/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

mke2fs建立Linux文件系統

經常使用

mke2fs -t #指定要創建文件系統的分區
mke2fs -b #指定塊大小,單位字節
mke2fs -m #指定預留空間的大小,默認預留空間爲5%

擴展

[root@localhost ~]# touch 1.txt
[root@localhost ~]# ls -lh 1.txt 
	-rw-r--r--. 1 root root 0 Nov  3 09:26 1.txt
[root@localhost ~]# echo 「1」 >  1.txt
[root@localhost ~]# ls -lh 1.txt 
	-rw-r--r--. 1 root root 2 Nov  3 09:26 1.txt
[root@localhost ~]# du -sh 1.txt	#指的是佔用塊空間,當一個文件寫入字符,不管多大都佔用一個塊空間
	4.0K	1.txt
[root@localhost ~]# du -sb 1.txt 
	2	1.txt

[root@localhost ~]# echo "2" >> 1.txt 
[root@localhost ~]# ls -lh 1.txt 
	-rw-r--r--. 1 root root 4 Nov  3 13:57 1.txt
[root@localhost ~]# du -sh 1.txt 
	4.0K	1.txt

mke2fs和mkfs

[root@localhost ~]# mke2fs -t 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
	65536 inodes, 262144 blocks
	13107 blocks (5.00%) reserved for the super user
	First data block=0
	Maximum filesystem blocks=268435456
	8 block groups
	32768 blocks per group, 32768 fragments per group
	8192 inodes per group
	Superblock backups stored on blocks: 
		32768, 98304, 163840, 229376

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

[root@localhost ~]# 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
	65536 inodes, 262144 blocks
	13107 blocks (5.00%) reserved for the super user
	First data block=0
	Maximum filesystem blocks=268435456
	8 block groups
	32768 blocks per group, 32768 fragments per group
	8192 inodes per group
	Superblock backups stored on blocks: 
		32768, 98304, 163840, 229376

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

mke2fs -b指定塊大小

指定塊大小,102四、204八、409六、8192以指數形式增長 當分區存入文件1KB左右,能夠指定分區塊爲1024或2048 而當存入文件如:高清圖片,無損音樂等文件時,指定分區塊爲4096或更高,能夠達到讀寫的最大值。less

[root@localhost ~]# mke2fs -b 8192 /dev/sdb1
	Warning: blocksize 8192 not usable on most systems.
	mke2fs 1.42.9 (28-Dec-2013)
	mke2fs: 8192-byte blocks too big for system (max 4096)
	Proceed anyway? (y,n) n

[root@localhost ~]# 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
	65536 inodes, 524288 blocks
	26214 blocks (5.00%) reserved for the super user
	First data block=0
	Maximum filesystem blocks=536870912
	32 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

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

mke2fs -m指定預留空間的大小

在指定的分區時,會預留5%的空間給root用戶 當指定分區空間越大時,5%的空間會顯得浪費,這時候可使用-m來自定義預留空間的大小ide

[root@localhost ~]# mke2fs -m 0.1 /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
	65536 inodes, 262144 blocks
	262 blocks (0.10%) reserved for the super user
	First data block=0
	Maximum filesystem blocks=268435456
	8 block groups
	32768 blocks per group, 32768 fragments per group
	8192 inodes per group
	Superblock backups stored on blocks: 
		32768, 98304, 163840, 229376

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

[root@localhost ~]# blkid /dev/sdb1
	/dev/sdb1: UUID="a87162cd-ceeb-4153-9843-896bfdc82ede" TYPE="ext2"

當在格式化分區時,沒有指定文件系統時,文件系統默認爲ext2ui

mke2fs -i

默認爲4個塊對比一個inode,4個塊就是16K
大多數狀況,inode必定是夠用的。 由於默認格式化的時候,至關於4個塊(16k)對應一個inode,試問,你的系統難道全部文件都小於16k麼?
雖然有這樣的場景,可是不多。
既然是這樣,inode增多跟提高磁盤空間利用有什麼關係呢。
應該是,當磁盤使用場景爲不少小文件(小於4k)時,把塊設置1k或者2k是能提高空間利用率的。prototype

[root@localhost ~]# mke2fs -i 8192 -t 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
	131072 inodes, 262144 blocks
	13107 blocks (5.00%) reserved for the super user
	First data block=0
	Maximum filesystem blocks=268435456
	8 block groups
	32768 blocks per group, 32768 fragments per group
	16384 inodes per group
	Superblock backups stored on blocks: 
		32768, 98304, 163840, 229376

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

原來inode和塊空間是1比4,如今1比2,也就是說inode增長了debug

[root@localhost ~]# mke2fs -i 4096 -b 4096 -t 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
	262144 inodes, 262144 blocks
	13107 blocks (5.00%) reserved for the super user
	First data block=0
	Maximum filesystem blocks=268435456
	8 block groups
	32768 blocks per group, 32768 fragments per group
	32768 inodes per group
	Superblock backups stored on blocks: 
		32768, 98304, 163840, 229376

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

mkfs建立Linux文件系統

經常使用

mkfs -t #指定要創建文件系統的分區
mkfs -b #指定塊大小,單位字節
mkfs -c #在創建文件系統前檢測分區是否存在磁盤壞道

使用mkfs和mke2fs -t的方法是同樣3d

[root@localhost ~]# mke2fs -t xfs /dev/sdb1
	mke2fs 1.42.9 (28-Dec-2013)

	Your mke2fs.conf file does not define the xfs filesystem type.
	Aborting...

[root@localhost ~]# mkfs.xfs -f /dev/sdb1
	meta-data=/dev/sdb1              isize=256    agcount=4, agsize=65536 blks
		=                       sectsz=512   attr=2, projid32bit=1
		=                       crc=0
	data	=                       bsize=4096   blocks=262144, imaxpct=25
		=                       sunit=0      swidth=0 blks
	naming	=version 2              bsize=4096   ascii-ci=0 ftype=0
	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

可是使用mount命令是找到/dev/sdb1,說明尚未掛載分區code

對比

[root@localhost ~]# mkfs.xfs -m 1 /dev/sdb1
	unknown option -m 1
	Usage: mkfs.xfs
	/* blocksize */		[-b log=n|size=num]
	/* metadata */		[-m crc=[0|1]
	/* data subvol */	[-d agcount=n,agsize=n,file,name=xxx,size=num,
				    (sunit=value,swidth=value|su=num,sw=num|noalign),
				    sectlog=n|sectsize=num
	/* force overwrite */	[-f]
	/* inode size */	[-i log=n|perblock=n|size=num,maxpct=n,attr=0|1|2,
				    projid32bit=0|1]
	/* no discard */	[-K]
	/* log subvol */	[-l agnum=n,internal,size=num,logdev=xxx,version=n
				    sunit=value|su=num,sectlog=n|sectsize=num,
				    lazy-count=0|1]
	/* label */		[-L label (maximum 12 characters)]
	/* naming */		[-n log=n|size=num,version=2|ci,ftype=0|1]
	/* no-op info only */	[-N]
	/* prototype file */	[-p fname]
	/* quiet */		[-q]
	/* realtime subvol */	[-r extsize=num,size=num,rtdev=xxx]
	/* sectorsize */	[-s log=n|size=num]
	/* version */		[-V]
				devicename
	<devicename> is required unless -d name=xxx is given.
	<num> is xxx (bytes), xxxs (sectors), xxxb (fs blocks), xxxk (xxx KiB),
	      xxxm (xxx MiB), xxxg (xxx GiB), xxxt (xxx TiB) or xxxp (xxx PiB).
	<value> is xxx (512 byte blocks).

[root@localhost ~]# mkfs.ext4 -m 1 /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
	65536 inodes, 262144 blocks
	2621 blocks (1.00%) reserved for the super user
	First data block=0
	Maximum filesystem blocks=268435456
	8 block groups
	32768 blocks per group, 32768 fragments per group
	8192 inodes per group
	Superblock backups stored on blocks: 
		32768, 98304, 163840, 229376

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

mkfs.ext4和mke2fs -t ext4支持的參數都是一致的orm

blkid查詢設備所採用的文件系統類型

[root@localhost ~]# blkid /dev/sdb1
	/dev/sdb1: UUID="d1194491-e0d3-478d-a5b4-9826fab80564" TYPE="xfs"

[root@localhost ~]# blkid
	/dev/sdb1: UUID="d1194491-e0d3-478d-a5b4-9826fab80564" TYPE="xfs" 
	/dev/sr0: UUID="2017-10-27-14-49-48-00" LABEL="20171027_144209" TYPE="iso9660" 
	/dev/sda1: UUID="f50883db-5558-4813-8053-67e97169c609" TYPE="xfs" 
	/dev/sda2: UUID="d0344494-65f1-4279-a595-76801470be33" TYPE="swap" 
	/dev/sda3: UUID="915e2a85-8d48-4667-9001-eae59adccb98" TYPE="xfs"

sr0是sr0是scsi/ata/sata接口的第一光驅設備,s= scsi,r= rom 只讀的,0表示總線上的第一個sr設備,第二個就是sr1

相關文章
相關標籤/搜索