Day 22
作者:翟玉龍
歸檔:課堂筆記
2019/3/08
fdisk分區(qū)工具介紹
fdisk_Partitinon table manipulator for Linux
Linux 下最常用的分區(qū)工具渤早,一般是裝完系統(tǒng)后進(jìn)行分區(qū)湖雹,裝系統(tǒng)之前的分區(qū)
多數(shù)都是系統(tǒng)ISO里面的工具分,或者Raid里分小磁盤
fdisk只能root權(quán)限用戶使用
fdisk適合 于對(duì)裝系統(tǒng)后的剩余空間進(jìn)行分區(qū),例如稼锅,安裝系統(tǒng)時(shí)沒有全部分區(qū),或者安裝系統(tǒng)后添加新磁盤
fdisk支持mbr分區(qū)表(2TB以內(nèi))
dd?if=/dev/sda?of=/dev/sdc????bs=512????count=10240
來源??????生成文件系統(tǒng)???block大小??塊個(gè)數(shù)
[root@oldboyedu?~]#?dd?if=/dev/sda?of=/dev/sdc????bs=512????count=10240
10240+0?records?in
10240+0?records?out
5242880?bytes?(5.2?MB)?copied,?0.0810606?s,?64.7?MB/s
[root@oldboyedu?~]#?ls?-l?/dev/sdc
-rw-r--r--?1?root?root?5242880?Mar?29?09:55?/dev/sdc
[root@oldboyedu?~]#?file?/dev/sdc
/dev/sdc:?x86?boot?sector;?partition?1:?ID=0x83,?active,?starthead?32,?startsector?2048,?524288?sectors;?partition?2:?ID=0x82,?starthead?194,?startsector?526336,?1572864?sectors;?partition?3:?ID=0x83,?starthead?170,?startsector?2099200,?39843840?sectors,?code?offset?0x63
[root@oldboyedu?~]#?cat?/proc/partitions
major?minor??#blocks??name
8???????16????1048576?sdb
8???????17?????153600?sdb1
8???????18?????153600?sdb2
8???????19?????153600?sdb3
8???????20??????????1?sdb4
8???????21?????153600?sdb5
8???????22?????153600?sdb6
8???????23?????153600?sdb7
8????????0???20971520?sda
8????????1?????262144?sda1
8????????2?????786432?sda2
8????????3???19921920?sda3
11????????0????1048575?sr0
parted的操作都是實(shí)時(shí)的
也就是說你執(zhí)行了一個(gè)分區(qū)的命令贤斜,他就實(shí)實(shí)在在的分區(qū)了
而不是像fdisk那樣懂酱,需要執(zhí)行w命令寫入所做的修改,所以進(jìn)行parted的測(cè)試千萬注意不能在生產(chǎn)環(huán)境中G衙ā狈蚤!
簡(jiǎn)述:parted是一個(gè)磁盤分區(qū)管理工具
這比fdisk更加靈活,功能也更加豐富划纽,同時(shí)還支持GUID分區(qū)表
這在IA64平臺(tái)上管理磁盤時(shí)非常有用脆侮,它同時(shí)支持交互模式和非交互模式,它除了能夠進(jìn)行分區(qū)的添加刪除等常見操作外勇劣,還可以移動(dòng)分區(qū)靖避,制作文件系統(tǒng),調(diào)整文件系統(tǒng)大小比默,
復(fù)制文件系統(tǒng)
問題需求:剛買的服務(wù)器幻捏,4塊2T,剛買命咐,要做RAID5 裝系統(tǒng)怎么搞定
方法1:?Raid里可以支持Raid5后篡九,6T 允許你把6t 分成虛擬磁盤
200G分成第一個(gè)虛擬磁盤剩下的不分留著裝系統(tǒng)后(parted)
方法2:裝系統(tǒng),系統(tǒng)鏡像醋奠,支持GPT格式分區(qū)榛臼,很隱蔽
方法3.引導(dǎo)工具進(jìn)入然后用類似parted分區(qū)
文件系統(tǒng):
什么是文件系統(tǒng)?
?? ?是計(jì)算機(jī)存儲(chǔ)和組織數(shù)據(jù)的方法或者機(jī)制窜司。落地是一個(gè)軟件
為什么需要文件系統(tǒng)沛善?
??? 磁盤,物理介質(zhì)例证,磁粒子物理元素路呜。硬件是需要軟件驅(qū)動(dòng)使用,磁盤需要文件系統(tǒng)驅(qū)動(dòng)。
文件系統(tǒng)實(shí)現(xiàn)通過磁盤幫助管理者規(guī)劃胀葱,存取數(shù)據(jù)
文件系統(tǒng)類型
??? Windows:NTFS漠秋,fat32,msdos
??? Linux:ext2抵屿,ext3(C5)庆锦,ext4(C6),Xfs(C7)
創(chuàng)建文件系統(tǒng)實(shí)踐:
文件系統(tǒng)原理(ext4文件系統(tǒng))
企業(yè)中如何選擇文件系統(tǒng)
如何優(yōu)化文件系統(tǒng)
[root@zyl? 19:31:19 ~]# mkfs -t ext4 /dev/sdb1
格式化ext4文件系統(tǒng)其實(shí)關(guān)鍵就是生成一定數(shù)量的inode和block
mke2fs 1.42.9(28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024(log=0)
Fragmentsize=1024 (log=0)
Stride=0 blocks,Stripe width=0 blocks
25688 inodes,102400 blocks
5120 blocks(5.00%) reserved for the super user
First datablock=1
Maximumfilesystem blocks=33685504
13 block groups
8192 blocks pergroup, 8192 fragments per group
1976 inodes pergroup
Superblockbackups stored on blocks:
?????????????????????????????????????????????????????????????????? 8193,24577, 40961, 57345, 73729
Allocating grouptables: done???????????????????????????
Writing inodetables: done???????????????????????????
Creating journal(4096 blocks): done
[root@zyl? 19:34:37 ~]# mount -t ext4 /dev/sdb1 /mnt?? 臨時(shí)掛載到mnt
[root@zyl? 19:38:54 ~]# touch /mnt/oldboy?? 測(cè)試掛載
[root@zyl? 19:39:08 ~]# df -h????????????? 查看掛載結(jié)果
[root@zyl? 19:39:13 ~]# cat /proc/mounts???? 查看掛載結(jié)果
umount? 卸載
先格式化在掛載
[root@zyl? 19:57:49 /]# mkfs.xfs /dev/sdb2????? 格式化xfs文件系統(tǒng)
meta-data=/dev/sdb2????? ????????isize=512??? agcount=4, agsize=6400 blks
???????? =?????????????????????? sectsz=512?? attr=2, projid32bit=1
???????? =?????????????????????? crc=1??????? finobt=0, sparse=0
data???? =?????????????????????? bsize=4096?? blocks=25600, imaxpct=25
???????? =?????????????????????? sunit=0????? swidth=0 blks
naming?? =version 2????????????? bsize=4096?? ascii-ci=0 ftype=1
log????? =internal log?????????? bsize=4096?? blocks=855, version=2
???????? =?????????????????????? sectsz=512?? sunit=0 blks, lazy-count=1
realtime=none?????????????????? extsz=4096?? blocks=0, rtextents=0
[root@oldboyedu?~]#?mount?-t?xfs?/dev/sdb2?/opt???? 指定文件類型
You?have?new?mail?in?/var/spool/mail/root
[root@oldboyedu?~]#?df?-h|grep?opt??????
查看掛載
/dev/sdb2????????97M??5.3M???92M???6%?/opt
[root@oldboyedu?~]#?touch?/opt/oldgirl????
測(cè)試
[root@oldboyedu?~]#?ls?/opt
oldgirl
開機(jī)自動(dòng)掛載:/etc/fstab
root@zyl? 20:03:53 /etc]# cat ./fstab
#
# /etc/fstab
# Created byanaconda on Sat Mar? 2 01:44:04 2019
#
# Accessiblefilesystems, by reference, are maintained under '/dev/disk'
# See man pagesfstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=4d410023-5d68-4bd3-8380-3adde2724c42??? ?/???????????xfs???? defaults????? ?0?0
UUID=0c1ad319-d952-46b2-8b61-f62707755ab2????/boot??????? ?xfs????defaults?????? 0?0
UUID=bfcae4fe-e625-4e22-9354-7b645da955b?????? 8 swap??????? ??swap???defaults??? 0?0
第一列設(shè)備
第二列掛載點(diǎn)
第三列文件類型
第四列默認(rèn)掛載選項(xiàng)
第五列是否備份
第六列是否開機(jī)磁盤檢查
開機(jī)自動(dòng)掛載兩種方法:
1.將要掛載的設(shè)備寫入/etc/fstab
[root@zyl? 20:12:28 ~]# cat /etc/fstab
#
# /etc/fstab
# Created byanaconda on Sat Mar? 2 01:44:04 2019
#
# Accessiblefilesystems, by reference, are maintained under '/dev/disk'
# See man pagesfstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=4d410023-5d68-4bd3-8380-3adde2724c42/?????????????????????? xfs???? defaults??????? 0 0
UUID=0c1ad319-d952-46b2-8b61-f62707755ab2/boot?????????????????? xfs???? defaults??????? 0 0
UUID=bfcae4fe-e625-4e22-9354-7b645da955b8swap??????????????????? swap??? defaults??????? 0 0
/dev/sdb2???????????????????????????????? /opt??????????????????? xfs???? defaults??????? 0 0
?[root@zyl?20:12:21 ~]# df
Filesystem???? 1K-blocks??? Used Available Use% Mounted on
/dev/sda3?????? 18707456 1901952? 16805504?11% /
devtmpfs????????? 920868?????? 0???920868?? 0% /dev
tmpfs???????????? 931612?????? 0???931612?? 0% /dev/shm
tmpfs???????????? 931612??? 9748???921864?? 2% /run
tmpfs???????????? 931612?????? 0???931612?? 0% /sys/fs/cgroup
/dev/sdb2????????? 98980??? 5344????93636?? 6% /opt
第二種:
放入/etc/rc.local實(shí)現(xiàn)自動(dòng)掛載,但是不推薦
/sbin/mount -t xfs/dev/sbd2 /opt
查看文件系統(tǒng)內(nèi)部細(xì)節(jié):
fsck 磁盤檢查和修復(fù)
1轧葛、正常的磁盤不能操作搂抒。
2、卸載掛載點(diǎn)在操作
[root@oldboyedu~]# fsck -a /dev/sdb1
fsck fromutil-linux 2.23.2
/dev/sdb1: clean,12/25688 files, 8896/102400 blocks
[root@oldboyedu~]# mount /dev/sdb1 /mnt
[root@oldboyedu~]# fsck -a /dev/sdb1
fsck fromutil-linux 2.23.2
/dev/sdb1 ismounted.
e2fsck: Cannotcontinue, aborting.
[root@oldboyedu~]# e2fsck /dev/sdb1
e2fsck 1.42.9(28-Dec-2013)
/dev/sdb1: clean,12/25688 files, 8896/102400 blocks
[root@oldboyedu~]# fsck -a /dev/sdb1
fsck fromutil-linux 2.23.2
/dev/sdb1: clean,12/25688 files, 8896/102400 blocks
[root@oldboyedu~]# xfs_repair /dev/sdb2
xfs_repair:/dev/sdb2 contains a mounted filesystem
xfs_repair:/dev/sdb2 contains a mounted and writable filesystem
fatal error --couldn't initialize XFS library
[root@oldboyedu~]# umount /opt
[root@oldboyedu~]# xfs_repair /dev/sdb2
Phase 1 - findand verify superblock...
Phase 2 - usinginternal log
??????? - zero log...
??????? - scan filesystem freespace and inodemaps...
??????? - found root inode chunk
Phase 3 - foreach AG...
??????? - scan and clear agi unlinked lists...
??????? - process known inodes and performinode discovery...
??????? - agno = 0
??????? - agno = 1
??????? - agno = 2
??????? - agno = 3
??????? - process newly discovered inodes...
Phase 4 - checkfor duplicate blocks...
??????? - setting up duplicate extent list...
??????? - check for inodes claiming duplicateblocks...
??????? - agno = 0
??????? - agno = 1
??????? - agno = 2
??????? - agno = 3
Phase 5 - rebuildAG headers and trees...
??????? - reset superblock...
Phase 6 - checkinode connectivity...
??????? - resetting contents of realtime bitmapand summary inodes
??????? - traversing filesystem ...
???? ???-traversal finished ...
??????? - moving disconnected inodes tolost+found ...
Phase 7 - verifyand correct link counts...
done
swap作用?內(nèi)存不夠時(shí)當(dāng)做內(nèi)存用
將來JAVA服務(wù)尿扯,內(nèi)存泄漏求晶,
swap將會(huì)被占用,操作系統(tǒng)性能下降
[root@zyl? 20:36:23 ~]# free -m
????????????? total??????? used??????? free????? shared?buff/cache?? available
Mem:??????? ???1819????????100??????? 1539?????????? 9???????? 179??????? 1547
Swap:????????? 1999?????????? 0??????? 1999
增加swap分區(qū)衷笋,增加100M
fdisk?????dos分區(qū)? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?umount卸載
parted??gpt格式分區(qū)???????=====》mkfs??格式化分區(qū)====>? ? ?mount臨時(shí)掛載
mklabel?primary?主分區(qū)?????????????????按文件系統(tǒng)類型????????????????/etc/fstab?開機(jī)自啟
mklabel?logic?邏輯??????????????????????????ext4?C6?xfsC7
fdisk?-l???查看有幾個(gè)硬盤
blkid??UID和文件系統(tǒng)類型