分區(qū)工具及操作

1、fdisk 分區(qū)工具介紹

1.linux下最常用的分區(qū)工具,一般是裝完系統(tǒng)后進(jìn)行分區(qū)。

2.多數(shù)都是系統(tǒng)ISO里面的工具分,或者raid里分小磁盤。

3.fdisk只能root權(quán)限用戶使用

4.fdisk適合對裝系統(tǒng)后的剩余空間進(jìn)行分區(qū)

5.fdisk支持mbr分區(qū)表

2、fdisk分區(qū)都的實(shí)質(zhì)

用fdisk分區(qū)的實(shí)質(zhì),就是0磁頭0磁道1扇區(qū)的前446字節(jié)之后的64字節(jié)的分區(qū)表信息。

問題:可以使用fdisk分區(qū)的磁盤大小必須小于2T,如果大于2T分區(qū)就用parted(gpt)。

3、指定虛擬文件系統(tǒng)(dd)

參數(shù):

if 代表輸入文件。如果不指定if,默認(rèn)就會從stdin中讀取輸入。

of 代表輸出文件。如果不指定of,默認(rèn)就會將stdout作為默認(rèn)輸出。

bs 代表字節(jié)為單位的塊大小。

count 代表被復(fù)制的塊數(shù)。

/dev/zero 是一個(gè)字符設(shè)備,會不斷返回0值字節(jié)(\0)。

組合使用例子:

?dd if=/dev/sda of=/dev/sdc bs=512 count=10240

? ? 來源? ? ? 生成文件系統(tǒng) ? block大小 ?? 塊個(gè)數(shù)

4、fdisk命令使用

1.磁盤分區(qū):

[root@oldboyedu ~]# fdisk /dev/sdb ? #<==開始給sdb磁盤分區(qū)

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.

Device does not contain a recognized partition table

Building a new DOS disklabel with disk identifier 0xbc9b0906.

Command (m for help): m? #<==查看分區(qū)的幫助信息。

Command action

? a? toggle a bootable flag ? ? #<====切換可啟動標(biāo)志

? b? edit bsd disklabel ? ? ? ? ? #<-==編輯bsd磁盤標(biāo)簽

? c? toggle the dos compatibility flag? #<=====切換DOS兼容標(biāo)志

? d? delete a partition? ? ? ? ? ? #<==刪除一個(gè)分區(qū)。

? g? create a new empty GPT partition table #<=====創(chuàng)建一個(gè)新的空GPT分區(qū)表

? G? create an IRIX (SGI) partition table? #<=====創(chuàng)建一個(gè)IRIX(SGI)分區(qū)表

? l? list known partition types ?? #<====列出已知的分區(qū)類型

? m? print this menu? ? ? ? ? ? ? #<==查看分區(qū)的幫助信息。

? n? add a new partition? ? ? ? ? #<==添加一個(gè)新分區(qū)。

? o? create a new empty DOS partition table ? #<===創(chuàng)建一個(gè)新的空DOS分區(qū)表

? p? print the partition table? ? #<==查看分區(qū)結(jié)果信息。

? q? quit without saving changes? #<==退出不保存。

? s? create a new empty Sun disklabel ?? #<===創(chuàng)建一個(gè)新的空sun磁盤標(biāo)簽

? t? change a partition's system id ? ? #<====更改分區(qū)的系統(tǒng)id

? u? change display/entry units ? ? ?? #<====? 改變 ?? 單位

? v? verify the partition table ? ?? #<==查看分區(qū)表

? w? write table to disk and exit? #<==保存并退出。

? x? extra functionality (experts only) ?? #<====額外功能

上面是fdisk命令創(chuàng)建分區(qū)一些選項(xiàng)內(nèi)容,可根據(jù)自己需要來調(diào)整分區(qū)數(shù)量容量大小

[root@oldboyedu ~]# ls -l /dev/sdb* ? ? ?? #<===查看創(chuàng)建好的分區(qū)

brw-rw---- 1 root disk 8, 16 Mar 29 11:31 /dev/sdb

brw-rw---- 1 root disk 8, 17 Mar 29 11:31 /dev/sdb1

brw-rw---- 1 root disk 8, 18 Mar 29 11:31 /dev/sdb2

2.然后來格式化ext4文件系統(tǒng)

[root@oldboyedu ~]# mkfs -t ext4 /dev/sdb1 ? ??#<====格式化ext4文件系統(tǒng) mkfs.ext4

其實(shí)關(guān)鍵就是生成一定數(shù)量的Inode和Block。

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

25688 inodes, 102400 blocks

5120 blocks (5.00%) reserved for the super user

First data block=1

Maximum filesystem blocks=33685504

13 block groups

8192 blocks per group, 8192 fragments per group

1976 inodes per group

Superblock backups stored on blocks:

8193, 24577, 40961, 57345, 73729

以下省略。。。。。

3.臨時(shí)掛載

[root@oldboyedu ~]# mount /dev/sdb1 /mnt ? #臨時(shí)掛載到/mnt

[root@oldboyedu ~]# df -h ? ?? #查看掛載結(jié)果

Filesystem? ? ? Size? Used Avail Use% Mounted on

/dev/sda3? ? ? ? 19G? 1.9G? 18G? 10% /

devtmpfs? ? ? ? 980M? 5.0M? 975M? 1% /dev

tmpfs? ? ? ? ? 991M? ? 0? 991M? 0% /dev/shm

tmpfs? ? ? ? ? 991M? 18M? 973M? 2% /run

tmpfs? ? ? ? ? 991M? ? 0? 991M? 0% /sys/fs/cgroup

/dev/sda1? ? ? 253M? 136M? 118M? 54% /boot

tmpfs? ? ? ? ? 199M? ? 0? 199M? 0% /run/user/0

tmpfs? ? ? ? ? 199M? ? 0? 199M? 0% /run/user/1000

/dev/sdb1? ? ? ? 93M? 1.6M? 85M? 2% /mnt ? ? ? #<====已掛載。

[root@oldboyedu ~]# cat /proc/mounts ? ? ? ? #<==查看掛載結(jié)果

rootfs / rootfs rw 0 0

sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0

proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0

configfs /sys/kernel/config configfs rw,relatime 0 0

/dev/sda3 / xfs rw,relatime,attr2,inode64,noquota 0 0

systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=32,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=19277 0 0

hugetlbfs /dev/hugepages hugetlbfs rw,relatime 0 0

debugfs /sys/kernel/debug debugfs rw,relatime 0 0

mqueue /dev/mqueue mqueue rw,relatime 0 0

/dev/sda1 /boot xfs rw,relatime,attr2,inode64,noquota 0 0

tmpfs /run/user/0 tmpfs rw,nosuid,nodev,relatime,size=202812k,mode=700 0 0

tmpfs /run/user/1000 tmpfs rw,nosuid,nodev,relatime,size=202812k,mode=700,uid=1000,gid=1000 0 0

/dev/sdb1 /mnt ext4 rw,relatime,data=ordered 0 0 ? ? ?? #<==已掛載。

[root@oldboyedu ~]# touch /mnt/oldboy ? ? ?? #<==測試。

[root@oldboyedu ~]# ls /mnt

lost+found? oldboy

[root@oldboyedu ~]# umount /mnt ?? #<===刪除掛載點(diǎn)

掛載成功就可以訪問了,這就是全部的分區(qū)過程,這是臨時(shí)掛載,也可以加入到開機(jī)自動掛載,/etc/fstab 是開機(jī)自動掛載文件,也可以放到/etc/rc.local 實(shí)現(xiàn)掛載,但不完美,所以不推薦。

5、fsck 命令 (磁盤檢查和修復(fù))

參數(shù) ?? -a ?? 修復(fù)磁盤

注意事項(xiàng):

1、正常的磁盤不能操作。

2、卸載掛載點(diǎn)在操作

[root@oldboyedu ~]# fsck -a /dev/sdb1 ?? #<===修復(fù)磁盤

[root@oldboyedu ~]# e2fsck /dev/sdb1 ? ? #<===同上

6、mkfs 格式化

參數(shù):

-t ? ? 指定類型

-b ? ? 指定block大小

-I ? ? ? 指定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


7、parted分區(qū):

1.無法支持超過2TB的硬盤的分區(qū)(或單個(gè)分區(qū)超過2TB).

2.如果大于2TB推薦GPT分區(qū)概念

3.GPT分區(qū)表很好的解決了MBR無法逾越2TB的分區(qū)方式,但是傳統(tǒng)的fdisk命令無法支持gpt分區(qū)方式。

8、簡單舉例(改成gpt分區(qū)):

[root@oldboyedu ~]# parted /dev/sdb #交互式開始分區(qū)

GNU Parted 3.1

Using /dev/sdb

Welcome to GNU Parted! Type 'help' to view a list of commands.

(parted) help

(parted) mklabel gpt? #修改分區(qū)格式為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? Yes ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

(parted) p? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

Model: VMware, VMware Virtual S (scsi)

Disk /dev/sdb: 1074MB

Sector size (logical/physical): 512B/512B

Partition Table: gpt? #修改結(jié)果

(parted) mkpart primary 0 480? #創(chuàng)建第一個(gè)主分區(qū)480M。

Warning: The resulting partition is not properly aligned for best performance.

Ignore/Cancel? Ignore #忽略提示。? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

(parted) mkpart primary 481 580 #創(chuàng)建第二個(gè)主分區(qū)100M。

Warning: You requested a partition from 481MB to 580MB (sectors 939453..1132812).

The closest location we can manage is 481MB to 481MB (sectors 940031..940031).

Is this still acceptable to you?

Yes/No? Y? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

Warning: The resulting partition is not properly aligned for best performance.

Ignore/Cancel? I #忽略提示。? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

(parted) mkpart logic 581 600 #創(chuàng)建一個(gè)20M邏輯分區(qū)。

(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

3? ? ? 481MB? 481MB? 512B? ? ? ? ? ? ? ? primary

2? ? ? 481MB? 580MB? 98.6MB? ? ? ? ? ? ? primary

4? ? ? 581MB? 600MB? 18.9MB? ? ? ? ? ? ? logic

(parted) rm 4? #刪除? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

(parted) p ? ? ? ? ?

問題需求:剛買的服務(wù)器 4塊2T 剛買,要做RAID5,裝系統(tǒng)怎么搞定?

方法1:Raid制作視頻,Raid里可以支持RAID5后,6T,允許你把6T分成虛擬磁盤。

? ? ? 200G分成第一個(gè)虛擬磁盤剩下不分留著裝系統(tǒng)后(parted)。

方法2:裝系統(tǒng)過程中有這個(gè)功能,系統(tǒng)鏡像支持GPT格式分區(qū),很隱蔽。

方法3:引導(dǎo)工具,進(jìn)入然后用parted分區(qū)。

9、修改分區(qū)格式:

(parted) mklabel msdos ? ? #<====可以改你需要的分區(qū)格式(這里改回dos)

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: msdos

Disk Flags:

內(nèi)容總結(jié):

文件系統(tǒng):

1、什么是文件系統(tǒng)

計(jì)算機(jī)存儲和組織數(shù)據(jù)的方法或機(jī)制。

2、為什么需要文件系統(tǒng)?

磁盤、物理介質(zhì)、磁粒子物理元素。硬件需要軟件驅(qū)動使用,磁盤需要文件系統(tǒng)驅(qū)動。

文件系統(tǒng)實(shí)現(xiàn)通過磁盤管理規(guī)劃、存取數(shù)據(jù)。

3、文件系統(tǒng)有哪些種類?

windows :NTFS? \Fat32\ Msdos

Linux: ext2 ? ext3 ? ext4(c6)

4、創(chuàng)建文件系統(tǒng)實(shí)踐:

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容