如何使用fdisk与parted对不同容量硬盘分区
一、簡介
通常我們用的比較多的一般都是fdisk工具來進行分區,但是現在由于磁盤越來越廉價,而且磁盤空間越來越大;而fdisk工具他對分區是有大小限制的,它只能劃分小于2T的磁盤。如果使用fdisk對大于2T的磁盤分區,雖然可以分區,但僅識別2T的空間,所以磁盤容量超過2T的話,就使用Parted工具來實現對GPT磁盤進行分區操作。
GPT格式的磁盤相當于原來MBR磁盤中原來保留4個partition table的4*16個字節,只留第一個16個字節,類似于擴展分區,真正的partitiontable在512字節之后,GPT磁盤沒有四個主分區的限制。
下面是實際演練,分別使用fdisk與parted對不同容量硬盤進行分區。
二、fdisk分區(2T容量以下硬盤使用)
1、查看當前磁盤情況
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | df?-h Filesystem????????????Size??Used?Avail?Use%?Mounted?on /dev/sda3?????????????133G???31G???96G??25%?/ tmpfs??????????????????16G??9.9G??5.9G??63%?/dev/shm /dev/sda1?????????????504M???43M??436M???9%?/boot /dev/sda5?????????????2.7T??2.4T??204G??93%?/data /dev/sdb1?????????????2.7T??2.4T??204G??93%?/data [root@bidw?tmp]#?fdisk?-l Disk?/dev/sda:?299.4?GB,?299439751168?bytes 255?heads,?63?sectors/track,?36404?cylinders Units?=?cylinders?of?16065?*?512?=?8225280?bytes Sector?size?(logical/physical):?512?bytes?/?512?bytes I/O?size?(minimum/optimal):?512?bytes?/?512?bytes Disk?identifier:?0x000ccf41 ???Device?Boot??????Start?????????End??????Blocks???Id??System /dev/sda1???*???????????1??????????66??????524288???83??Linux Partition?1?does?not?end?on?cylinder?boundary. /dev/sda2??????????????66????????1371????10485760???82??Linux?swap?/?Solaris /dev/sda3????????????1371???????18888???140704768???83??Linux /dev/sda4???????????18888???????36405???140705792????5??Extended /dev/sda5???????????18888???????36405???140704768???83??Linux WARNING:?GPT?(GUID?Partition?Table)?detected?on?'/dev/sdb'!?The?util?fdisk?doesn't?support?GPT.?Use?GNU?Parted. Disk?/dev/sdb:?2999.0?GB,?2998960914432?bytes 255?heads,?63?sectors/track,?364602?cylinders Units?=?cylinders?of?16065?*?512?=?8225280?bytes Sector?size?(logical/physical):?512?bytes?/?512?bytes I/O?size?(minimum/optimal):?512?bytes?/?512?bytes Disk?identifier:?0x00000000 ???Device?Boot??????Start?????????End??????Blocks???Id??System /dev/sdb1???????????????1??????267350??2147483647+??ee??GPT Disk?/dev/sdc:?1999.8?GB,?1999844147200?bytes 81?heads,?63?sectors/track,?765421?cylinders Units?=?cylinders?of?5103?*?512?=?2612736?bytes Sector?size?(logical/physical):?512?bytes?/?512?bytes I/O?size?(minimum/optimal):?512?bytes?/?512?bytes Disk?identifier:?0x42d69282 |
可以看到/dev/sdc是需要分區的
2、使用fdisk進行分區
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | [root@bidw?tmp]#?fdisk?/dev/sdc Device?contains?neither?a?valid?DOS?partition?table,?nor?Sun,?SGI?or?OSF?disklabel Building?a?new?DOS?disklabel?with?disk?identifier?0xc1b09294. Changes?will?remain?in?memory?only,?until?you?decide?to?write?them. After?that,?of?course,?the?previous?content?won't?be?recoverable. Warning:?invalid?flag?0x0000?of?partition?table?4?will?be?corrected?by?w(rite) WARNING:?DOS-compatible?mode?is?deprecated.?It's?strongly?recommended?to ?????????switch?off?the?mode?(command?'c')?and?change?display?units?to ?????????sectors?(command?'u'). Command?(m?for?help):?m Command?action ???a???toggle?a?bootable?flag ???b???edit?bsd?disklabel ???c???toggle?the?dos?compatibility?flag ???d???delete?a?partition ???l???list?known?partition?types ???m???print?this?menu ???n???add?a?new?partition ???o???create?a?new?empty?DOS?partition?table ???p???print?the?partition?table ???q???quit?without?saving?changes ???s???create?a?new?empty?Sun?disklabel ???t???change?a?partition's?system?id ???u???change?display/entry?units ???v???verify?the?partition?table ???w???write?table?to?disk?and?exit ???x???extra?functionality?(experts?only) Command?(m?for?help):?n Command?action ???e???extended ???p???primary?partition?(1-4) p Partition?number?(1-4):?1 First?cylinder?(1-243133,?default?1):? Using?default?value?1 Last?cylinder,?+cylinders?or?+size{K,M,G}?(1-243133,?default?243133):? Using?default?value?243133 Command?(m?for?help):?w The?partition?table?has?been?altered! Calling?ioctl()?to?re-read?partition?table. WARNING:?Re-reading?the?partition?table?failed?with?error?22:?Invalid?argument. The?kernel?still?uses?the?old?table.?The?new?table?will?be?used?at the?next?reboot?or?after?you?run?partprobe(8)?or?kpartx(8) Syncing?disks. |
3、格式化為ext4系統
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | [root@bidw?tmp]#?mkfs.ext4?/dev/sdc1 mke2fs?1.41.12?(17-May-2010) Filesystem?label= OS?type:?Linux Block?size=4096?(log=2) Fragment?size=4096?(log=2) Stride=0?blocks,?Stripe?width=0?blocks 122060800?inodes,?488242944?blocks 24412147?blocks?(5.00%)?reserved?for?the?super?user First?data?block=0 Maximum?filesystem?blocks=4294967296 14900?block?groups 32768?blocks?per?group,?32768?fragments?per?group 8192?inodes?per?group Superblock?backups?stored?on?blocks:? ????32768,?98304,?163840,?229376,?294912,?819200,?884736,?1605632,?2654208,? ????4096000,?7962624,?11239424,?20480000,?23887872,?71663616,?78675968,? ????102400000,?214990848 Writing?inode?tables:?done???????????????????????????? Creating?journal?(32768?blocks):?done Writing?superblocks?and?filesystem?accounting?information:?done This?filesystem?will?be?automatically?checked?every?37?mounts?or 180?days,?whichever?comes?first.??Use?tune2fs?-c?or?-i?to?override. |
然后查看磁盤情況
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | [root@bidw?tmp]#?fdisk?-l Disk?/dev/sda:?299.4?GB,?299439751168?bytes 255?heads,?63?sectors/track,?36404?cylinders Units?=?cylinders?of?16065?*?512?=?8225280?bytes Sector?size?(logical/physical):?512?bytes?/?512?bytes I/O?size?(minimum/optimal):?512?bytes?/?512?bytes Disk?identifier:?0x000ccf41 ???Device?Boot??????Start?????????End??????Blocks???Id??System /dev/sda1???*???????????1??????????66??????524288???83??Linux Partition?1?does?not?end?on?cylinder?boundary. /dev/sda2??????????????66????????1371????10485760???82??Linux?swap?/?Solaris /dev/sda3????????????1371???????18888???140704768???83??Linux /dev/sda4???????????18888???????36405???140705792????5??Extended /dev/sda5???????????18888???????36405???140704768???83??Linux WARNING:?GPT?(GUID?Partition?Table)?detected?on?'/dev/sdb'!?The?util?fdisk?doesn't?support?GPT.?Use?GNU?Parted. Disk?/dev/sdb:?2999.0?GB,?2998960914432?bytes 255?heads,?63?sectors/track,?364602?cylinders Units?=?cylinders?of?16065?*?512?=?8225280?bytes Sector?size?(logical/physical):?512?bytes?/?512?bytes I/O?size?(minimum/optimal):?512?bytes?/?512?bytes Disk?identifier:?0x00000000 ???Device?Boot??????Start?????????End??????Blocks???Id??System /dev/sdb1???????????????1??????267350??2147483647+??ee??GPT Disk?/dev/sdc:?1999.8?GB,?1999844147200?bytes 81?heads,?63?sectors/track,?765421?cylinders Units?=?cylinders?of?5103?*?512?=?2612736?bytes Sector?size?(logical/physical):?512?bytes?/?512?bytes I/O?size?(minimum/optimal):?512?bytes?/?512?bytes Disk?identifier:?0x42d69282 ???Device?Boot??????Start?????????End??????Blocks???Id??System /dev/sdc1???????????????1??????765634??1953513560???83??Linux |
可以看到/dev/sdc1已經格式化完成
4、掛載
| 1 2 3 4 5 6 7 8 9 | [root@bidw?tmp]#?mount?/dev/sdc1?/u01 [root@bidw?tmp]#?df?-h Filesystem????????????Size??Used?Avail?Use%?Mounted?on /dev/sda3?????????????133G???32G???95G??25%?/ tmpfs??????????????????16G??9.9G??5.9G??63%?/dev/shm /dev/sda1?????????????504M???43M??436M???9%?/boot /dev/sda5?????????????2.7T??2.4T??204G??93%?/data /dev/sdb1?????????????2.7T??2.4T??204G??93%?/data /dev/sdc1?????????????1.8T??196M??1.7T???1%?/u01 |
可以看到/dev/sdc1已經掛載到/u01目錄
5、把掛載信息放入fstab里
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | [root@bidw?tmp]#?cat?/etc/fstab? "/etc/fstab"?19L,?979C# #?/etc/fstab #?Created?by?anaconda?on?Sat?Dec?29?12:06:41?2012 # #?Accessible?filesystems,?by?reference,?are?maintained?under?'/dev/disk' #?See?man?pages?fstab(5),?findfs(8),?mount(8)?and/or?blkid(8)?for?more?info # UUID=bcc682b0-5a55-4df8-8f7f-2ebfca7e0bf9?/?ext4????defaults?1?1 UUID=f75b95fb-78cf-4070-b629-a5b1983edc83?/boot?ext4????defaults?1?2 UUID=5743454b-f226-4c7c-8ad4-bf8db690572b?/data?xfs?????defaults?1?2 UUID=e9ea4e7a-d959-4c63-a562-dc059d58ac08?swap?swap????defaults?0?0 tmpfs?/dev/shm?tmpfs???defaults,size=16G?0?0 devpts?/dev/pts?devpts??gid=5,mode=620??0?0 sysfs?/sys?sysfs???defaults?0?0 proc?/proc?proc????defaults?0?0 /dev/sdb1?/data?ext3???????defaults??0???0 |
然后對最新的配置生效一下
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | [root@bidw?tmp]#?mount?-a [root@bidw?tmp]#?mount /dev/sda3?on?/?type?ext4?(rw) proc?on?/proc?type?proc?(rw) sysfs?on?/sys?type?sysfs?(rw) devpts?on?/dev/pts?type?devpts?(rw,gid=5,mode=620) tmpfs?on?/dev/shm?type?tmpfs?(rw,size=16G) /dev/sda1?on?/boot?type?ext4?(rw) /dev/sda5?on?/data?type?xfs?(rw) /dev/sdb1?on?/data?type?ext3?(rw) none?on?/proc/sys/fs/binfmt_misc?type?binfmt_misc?(rw) none?on?/sys/kernel/config?type?configfs?(rw) sunrpc?on?/var/lib/nfs/rpc_pipefs?type?rpc_pipefs?(rw) /dev/sdc1?on?/u01?type?ext4?(rw) |
6、測試一下新分區對象
| 1 2 3 4 5 6 7 8 9 10 11 | [root@bidw?tmp]#?cd?/u01 [root@bidw?u01]#?ll total?16 drwx------?2?root?root?16384?Jul?21?09:49?lost+found [root@bidw?u01]#?touch?test [root@bidw?u01]#?ll total?16 drwx------?2?root?root?16384?Jul?21?09:49?lost+found -rw-r--r--?1?root?root?????0?Jul?21?10:03?test [root@bidw?u01]#?rm?test rm:?remove?regular?empty?file?`test'??y |
三、parted分區(2T容量以上硬盤使用)
1、查看分區情況
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | root@ip-10-10-27-116:/home 02:36:30?#?fdisk?-l Disk?/dev/sda:?999.7?GB,?999653638144?bytes 255?heads,?63?sectors/track,?121534?cylinders Units?=?cylinders?of?16065?*?512?=?8225280?bytes Sector?size?(logical/physical):?512?bytes?/?512?bytes I/O?size?(minimum/optimal):?512?bytes?/?512?bytes Disk?identifier:?0x00045789 ???Device?Boot??????Start?????????End??????Blocks???Id??System /dev/sda1???*???????????1?????????131?????1048576???83??Linux Partition?1?does?not?end?on?cylinder?boundary. /dev/sda2?????????????131????????4309????33554432???82??Linux?swap?/?Solaris /dev/sda3????????????4309??????121535???941620224???83??Linux Disk?/dev/sdb:?2999.0?GB,?2998960914432?bytes 255?heads,?63?sectors/track,?364602?cylinders Units?=?cylinders?of?16065?*?512?=?8225280?bytes Sector?size?(logical/physical):?512?bytes?/?512?bytes I/O?size?(minimum/optimal):?512?bytes?/?512?bytes Disk?identifier:?0x00000000 |
可以看到/dev/sdb是需要分區的,磁盤容量為3t,fdisk沒辦法分區,只能使用parted進行gpt分區了
下面是當前已經在用的磁盤情況
| 1 2 3 4 5 6 | root@ip-10-10-27-116:/home 02:38:04?#?df?-h Filesystem????????????Size??Used?Avail?Use%?Mounted?on /dev/sda3?????????????884G??2.0G??838G???1%?/ tmpfs??????????????????32G?????0???32G???0%?/dev/shm /dev/sda1????????????1008M???56M??902M???6%?/boot |
2、使用parted進行分區
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | root@ip-10-10-27-116:/home 02:38:06?#?parted?/dev/sdb GNU?Parted?2.1 Using?/dev/sdb Welcome?to?GNU?Parted!?Type?'help'?to?view?a?list?of?commands. (parted)?p???????????????????????????????????????????????????????????????? Error:?/dev/sdb:?unrecognised?disk?label?????????????????????????????????? (parted)?mklabel?gpt?????????????????????????????????????????????????????? (parted)?mkpart?primary?0%?100%??????????????????????????????????????????? (parted)?print???????????????????????????????????????????????????????????? Model:?DELL?PERC?H710P?(scsi) Disk?/dev/sdb:?2999GB Sector?size?(logical/physical):?512B/512B Partition?Table:?gpt Number??Start???End?????Size????File?system??Name?????Flags ?1??????1049kB??2999GB??2999GB???????????????primary (parted)?quit????????????????????????????????????????????????????????????? Information:?You?may?need?to?update?/etc/fstab. |
| 1 2 3 4 5 6 7 8 9 10 11 | 介紹一下各個命令的意思 p? 是打印磁盤信息,查看分區的情況,找到起始和結束位置。 mklabel?gpt 是進行gpt類型分區 mkpart?primary?0%?100% 是primary指分區類型為主分區,0是分區開始位置,100%是分區結束位置。相同的命令為:mkpart?primary?0-1?或者是:mkpart??primary?0??XXXXXX結束的空間 print 打印當前分區,查看分區設置是否正確 quit 退出 |
在看看當前已用硬盤情況,可用看到/dev/sdb還是沒有掛載
| 1 2 3 4 5 6 7 | root@ip-10-10-27-116:/home 02:44:05?#?df?-h Filesystem????????????Size??Used?Avail?Use%?Mounted?on /dev/sda3?????????????884G??2.0G??838G???1%?/ tmpfs??????????????????32G?????0???32G???0%?/dev/shm /dev/sda1????????????1008M???56M??902M???6%?/boot root@ip-10-10-27-116:/home |
看看磁盤分區情況
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 02:44:07?#?fdisk?-l Disk?/dev/sda:?999.7?GB,?999653638144?bytes 255?heads,?63?sectors/track,?121534?cylinders Units?=?cylinders?of?16065?*?512?=?8225280?bytes Sector?size?(logical/physical):?512?bytes?/?512?bytes I/O?size?(minimum/optimal):?512?bytes?/?512?bytes Disk?identifier:?0x00045789 ???Device?Boot??????Start?????????End??????Blocks???Id??System /dev/sda1???*???????????1?????????131?????1048576???83??Linux Partition?1?does?not?end?on?cylinder?boundary. /dev/sda2?????????????131????????4309????33554432???82??Linux?swap?/?Solaris /dev/sda3????????????4309??????121535???941620224???83??Linux WARNING:?GPT?(GUID?Partition?Table)?detected?on?'/dev/sdb'!?The?util?fdisk?doesn't?support?GPT.?Use?GNU?Parted. Disk?/dev/sdb:?2999.0?GB,?2998960914432?bytes 255?heads,?63?sectors/track,?364602?cylinders Units?=?cylinders?of?16065?*?512?=?8225280?bytes Sector?size?(logical/physical):?512?bytes?/?512?bytes I/O?size?(minimum/optimal):?512?bytes?/?512?bytes Disk?identifier:?0x00000000 ???Device?Boot??????Start?????????End??????Blocks???Id??System /dev/sdb1???????????????1??????267350??2147483647+??ee??GPT |
可用看到/dev/sdb1已經進行了gpt類型分區
3、格式化為ext4系統
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 02:44:12?#?mkfs.ext4?/dev/sdb1 mke2fs?1.41.12?(17-May-2010) Filesystem?label= OS?type:?Linux Block?size=4096?(log=2) Fragment?size=4096?(log=2) Stride=0?blocks,?Stripe?width=0?blocks 183042048?inodes,?732167680?blocks 36608384?blocks?(5.00%)?reserved?for?the?super?user First?data?block=0 Maximum?filesystem?blocks=4294967296 22344?block?groups 32768?blocks?per?group,?32768?fragments?per?group 8192?inodes?per?group Superblock?backups?stored?on?blocks:? ????32768,?98304,?163840,?229376,?294912,?819200,?884736,?1605632,?2654208,? ????4096000,?7962624,?11239424,?20480000,?23887872,?71663616,?78675968,? ????102400000,?214990848,?512000000,?550731776,?644972544 Writing?inode?tables:?done???????????????????????????? Creating?journal?(32768?blocks):?done Writing?superblocks?and?filesystem?accounting?information:?done This?filesystem?will?be?automatically?checked?every?30?mounts?or 180?days,?whichever?comes?first.??Use?tune2fs?-c?or?-i?to?override. root@ip-10-10-27-116:/home 02:47:23?#?df?-h Filesystem????????????Size??Used?Avail?Use%?Mounted?on /dev/sda3?????????????884G??2.0G??838G???1%?/ tmpfs??????????????????32G?????0???32G???0%?/dev/shm /dev/sda1????????????1008M???56M??902M???6%?/boot |
4、掛載
創建掛載目錄data
| 1 2 3 4 5 6 7 8 9 10 11 12 | root@ip-10-10-27-116:/home 02:49:38?#?mkdir?/data 然后掛載/dev/sdb1到/data目錄 root@ip-10-10-27-116:/home 02:50:36?#?mount?/dev/sdb1?/data root@ip-10-10-27-116:/home 02:50:41?#?df?-h Filesystem????????????Size??Used?Avail?Use%?Mounted?on /dev/sda3?????????????884G??2.0G??838G???1%?/ tmpfs??????????????????32G?????0???32G???0%?/dev/shm /dev/sda1????????????1008M???56M??902M???6%?/boot /dev/sdb1?????????????2.7T??201M??2.6T???1%?/data |
5、加入fstab
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | root@ip-10-10-27-116:/home 02:51:39?#?cat?/etc/fstab? # #?/etc/fstab #?Created?by?anaconda?on?Wed?Aug?27?13:39:16?2014 # #?Accessible?filesystems,?by?reference,?are?maintained?under?'/dev/disk' #?See?man?pages?fstab(5),?findfs(8),?mount(8)?and/or?blkid(8)?for?more?info # UUID=1bc74b58-1fbe-4f65-9790-d02abc23d461?/???????????????????????ext4????defaults????????1?1 UUID=ebbbaa89-e509-4fef-8763-be6eed9408c7?/boot???????????????????ext4????defaults????????1?2 UUID=98417724-a1c5-4f9a-9750-85beda11e4e1?swap????????????????????swap????defaults????????0?0 tmpfs???????????????????/dev/shm????????????????tmpfs???defaults????????0?0 devpts??????????????????/dev/pts????????????????devpts??gid=5,mode=620??0?0 sysfs???????????????????/sys????????????????????sysfs???defaults????????0?0 proc????????????????????/proc???????????????????proc????defaults????????0?0 /dev/sdb1???????????????/data???????????????????ext4??? defaults??????? 0?0 |
生效一下
| 1 2 3 4 5 6 7 8 | 02:51:43?#?mount?-a root@ip-10-10-27-116:/home 02:51:45?#?df?-h Filesystem????????????Size??Used?Avail?Use%?Mounted?on /dev/sda3?????????????884G??2.0G??838G???1%?/ tmpfs??????????????????32G?????0???32G???0%?/dev/shm /dev/sda1????????????1008M???56M??902M???6%?/boot /dev/sdb1?????????????2.7T??201M??2.6T???1%?/data |
6、測試
| 1 2 3 4 5 6 7 8 9 10 | 11:04:13?#?cd?/data root@ip-10-10-27-116:/data 11:06:44?#?echo?"this?is?test">test root@ip-10-10-27-116:/data 11:06:52?#?cat?test this?is?test root@ip-10-10-27-116:/data 11:06:54?#?rm?test rm:?remove?regular?file?`test'??y root@ip-10-10-27-116:/data |
其實本文主要介紹的就是如何對不同容量的硬盤使用不同方法進行分區,并對每一步驟都有解釋,希望對各位有幫助。
?本文轉自 reinxu 51CTO博客,原文鏈接:http://blog.51cto.com/dl528888/1547325,如需轉載請自行聯系原作者
總結
以上是生活随笔為你收集整理的如何使用fdisk与parted对不同容量硬盘分区的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DEDECMS最新5.7版在Window
- 下一篇: 重建包含快照的vmdk描述文件。