3月29日第22天課堂筆記

第四章 磁盤分區(qū)知識與Linux系統(tǒng)分區(qū)實踐

1悼瓮、fdisk命令分區(qū)

fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b907d

Device Boot Start End Blocks Id System
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-2097151, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +150M
Partition 1 of type Linux and of size 150 MiB is set

Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p):
Using default response p
Partition number (2-4, default 2):
First sector (309248-2097151, default 309248):
Using default value 309248
Last sector, +sectors or +size{K,M,G} (309248-2097151, default 2097151): +150M
Partition 2 of type Linux and of size 150 MiB is set

Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p):
Using default response p
Partition number (3,4, default 3):
First sector (616448-2097151, default 616448):
Using default value 616448
Last sector, +sectors or +size{K,M,G} (616448-2097151, default 2097151): +150M
Partition 3 of type Linux and of size 150 MiB is set

Command (m for help): N
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e):
Using default response e
Selected partition 4
First sector (923648-2097151, default 923648):
Using default value 923648
Last sector, +sectors or +size{K,M,G} (923648-2097151, default 2097151):
Using default value 2097151
Partition 4 of type Extended and of size 573 MiB is set

Command (m for help): P

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b907d

Device Boot Start End Blocks Id System
/dev/sdb1 2048 309247 153600 83 Linux
/dev/sdb2 309248 616447 153600 83 Linux
/dev/sdb3 616448 923647 153600 83 Linux
/dev/sdb4 923648 2097151 586752 5 Extended
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@yuzhiwei/]# cat /proc/partitions
major minor #blocks name

11 0 4481024 sr0
8 0 20971520 sda
8 1 204800 sda1
8 2 2048000 sda2
8 3 18717696 sda3
8 16 1048576 sdb
8 17 153600 sdb1
8 18 153600 sdb2
8 19 153600 sdb3
8 20 1 sdb4
8 21 153600 sdb5

分區(qū)完成后使用partprobe /dev/sdb 命令將分區(qū)信息通知內(nèi)核

2隙疚、parted命令分區(qū)

分區(qū)前先看一下分區(qū)格式土铺,fdisk命令分區(qū)用dos分區(qū)格式,parted命令分區(qū)使用gpt分區(qū)格式绒北。
[root@yuzhiwei/]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags

(parted) mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be
lost. Do you want to continue?
Yes/No? y
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags

(parted) mkpart primary 0 480
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 17.4kB 480MB 480MB primary

(parted) mkpart primary 481 580
(parted) mkpart logic 581 600
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 17.4kB 480MB 480MB primary
2 481MB 580MB 98.6MB primary
3 581MB 600MB 18.9MB logic

parted命令分區(qū)時沒有擴展分區(qū),只有主分區(qū)和邏輯分區(qū)。

3沿后、文件系統(tǒng)

3.1、什么是文件系統(tǒng)朽砰?
計算機存儲和組織數(shù)據(jù)的方法或者機制尖滚,落地是一個軟件喉刘。
3.2、為什么需要文件系統(tǒng)漆弄?
磁盤睦裳、物理介質(zhì)幻枉、磁粒子物理元素样刷。硬件需要軟件驅(qū)動使用爹橱,磁盤需要文件系統(tǒng)驅(qū)動落蝙。
文件系統(tǒng)實現(xiàn)通過磁盤管理規(guī)劃贡这、存取數(shù)據(jù)巷燥。
3.3倔撞、文件系統(tǒng)有哪些類型寸士?
Windows:NTFS渤愁、fat32牵祟、msdos
Linux:ext2、ext3(C5)猴伶、ext4(C6)课舍、xfs(C7)、btrfs
3.4他挎、創(chuàng)建文件系統(tǒng)
首先用上面的命令創(chuàng)建分區(qū)
首先對分區(qū)進行格式化筝尾,其實關(guān)鍵就是生成一定數(shù)量的Inode和Block。
[root@yuzhiwei/]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
38456 inodes, 153600 blocks
7680 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33816576
19 block groups
8192 blocks per group, 8192 fragments per group
2024 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
也可以指定指定塊大小和inode大小進行格式化
[root@oldboyedu ~]# mkfs -t ext4 -b 4096 -I 512 /dev/sdb3
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
38400 inodes, 38400 blocks
1920 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=39845888
2 block groups
32768 blocks per group, 32768 fragments per group
19200 inodes per group
Superblock backups stored on blocks:
32768

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

然后進行掛載并查看掛載結(jié)果
[root@yuzhiwei/]# mount /dev/sdb1 /mnt
[root@yuzhiwei/]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 18G 1.7G 17G 10% /
devtmpfs 900M 5.0M 895M 1% /dev
tmpfs 910M 0 910M 0% /dev/shm
tmpfs 910M 9.6M 901M 2% /run
tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/sda1 197M 116M 82M 59% /boot
tmpfs 182M 0 182M 0% /run/user/0
/dev/sdb1 142M 1.6M 130M 2% /mnt
[root@yuzhiwei/]# cat /proc/mounts
rootfs / rootfs rw 0 0
/dev/sdb1 /mnt ext4 rw,relatime,data=ordered 0 0

以上掛載命令只是臨時掛載到/mnt
如何開機自動掛載办桨?
/etc/fstab 開機自動掛載
幾列筹淫? 6列

[root@oldboyedu ~]# cat /etc/fstab
UUID=3a3a295f-88f8-456d-94dc-1a3eeb517c02 / xfs defaults 0 0
UUID=fd2e0ca7-32be-425f-86a2-85c02b9ec5ea /boot xfs defaults 0 0
UUID=79a3924b-739e-48dc-ab0c-0444b9ac6591 swap swap defaults 0 0
設(shè)備 掛載點 文件系統(tǒng)類型 默認掛載選項 是否備份 是否開機磁盤檢查
/dev/sdb2 /opt xfs defaults 0 0

umount -lf 命令可以強制卸載掛載

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市呢撞,隨后出現(xiàn)的幾起案子损姜,更是在濱河造成了極大的恐慌,老刑警劉巖殊霞,帶你破解...
    沈念sama閱讀 221,820評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件摧阅,死亡現(xiàn)場離奇詭異,居然都是意外死亡绷蹲,警方通過查閱死者的電腦和手機棒卷,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,648評論 3 399
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來祝钢,“玉大人比规,你說我怎么就攤上這事±褂ⅲ” “怎么了蜒什?”我有些...
    開封第一講書人閱讀 168,324評論 0 360
  • 文/不壞的土叔 我叫張陵,是天一觀的道長疤估。 經(jīng)常有香客問我灾常,道長霎冯,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,714評論 1 297
  • 正文 為了忘掉前任岗憋,我火速辦了婚禮肃晚,結(jié)果婚禮上锚贱,老公的妹妹穿的比我還像新娘仔戈。我一直安慰自己,他們只是感情好拧廊,可當(dāng)我...
    茶點故事閱讀 68,724評論 6 397
  • 文/花漫 我一把揭開白布监徘。 她就那樣靜靜地躺著,像睡著了一般吧碾。 火紅的嫁衣襯著肌膚如雪凰盔。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,328評論 1 310
  • 那天倦春,我揣著相機與錄音户敬,去河邊找鬼。 笑死睁本,一個胖子當(dāng)著我的面吹牛尿庐,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播呢堰,決...
    沈念sama閱讀 40,897評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼抄瑟,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了枉疼?” 一聲冷哼從身側(cè)響起皮假,我...
    開封第一講書人閱讀 39,804評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎骂维,沒想到半個月后惹资,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,345評論 1 318
  • 正文 獨居荒郊野嶺守林人離奇死亡航闺,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,431評論 3 340
  • 正文 我和宋清朗相戀三年褪测,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片来颤。...
    茶點故事閱讀 40,561評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡汰扭,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出福铅,到底是詐尸還是另有隱情萝毛,我是刑警寧澤,帶...
    沈念sama閱讀 36,238評論 5 350
  • 正文 年R本政府宣布滑黔,位于F島的核電站笆包,受9級特大地震影響环揽,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜庵佣,卻給世界環(huán)境...
    茶點故事閱讀 41,928評論 3 334
  • 文/蒙蒙 一歉胶、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧巴粪,春花似錦通今、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,417評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至派哲,卻和暖如春臼氨,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背芭届。 一陣腳步聲響...
    開封第一講書人閱讀 33,528評論 1 272
  • 我被黑心中介騙來泰國打工储矩, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人褂乍。 一個月前我還...
    沈念sama閱讀 48,983評論 3 376
  • 正文 我出身青樓持隧,卻偏偏與公主長得像,于是被迫代替她去往敵國和親树叽。 傳聞我的和親對象是個殘疾皇子舆蝴,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,573評論 2 359

推薦閱讀更多精彩內(nèi)容