溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Linux下新建分區(qū)并格式化的方法

發(fā)布時間:2021-09-16 20:36:26 來源:億速云 閱讀:607 作者:chen 欄目:系統(tǒng)運維

這篇文章主要講解了“Linux下新建分區(qū)并格式化的方法”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“Linux下新建分區(qū)并格式化的方法”吧!

在學(xué)習(xí)磁盤管理時,使用fdisk將剩余的容量繼續(xù)分區(qū)。卻發(fā)現(xiàn)新建完分區(qū)后,無法通過partprobe重載分區(qū)。

具體操作如下所示:

1、使用fdisk新建分區(qū)

(。。。。)分區(qū)操作記錄沒有保存下來,執(zhí)行w后,出現(xiàn)下列信息

Disk /dev/sda: 21.5 GB, 21474836480 bytes  255 heads, 63 sectors/track, 2610 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: 0x000b604c Device Boot Start End Blocks Id System  /dev/sda1 * 1 523 4194304 83 Linux  Partition 1 does not end on cylinder boundary.  /dev/sda2 523 784 2097152 82 Linux swap / Solaris  Partition 2 does not end on cylinder boundary.  /dev/sda3 784 2610 14672345 5 Extended  /dev/sda5 784 1421 5121671 83 LinuxCommand (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 16: 設(shè)備或資源忙.  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.

保存新建分區(qū),提示“設(shè)備或資源忙”,當(dāng)時就在/dev/sda硬盤上做的操作,以為該提示為正?,F(xiàn)象,所以忽略了,繼續(xù)下一步操作。

2、通過partprobe重載分區(qū)表,避免重啟系統(tǒng)

[root@stduy /]# partprobe   Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (設(shè)備或資源忙). As a result, it may not reflect all of your changes until after reboot.  Warning: 無法以讀寫方式打開 /dev/sr0 (只讀文件系統(tǒng))。/dev/sr0 已按照只讀方式打開。  Warning: 無法以讀寫方式打開 /dev/sr0 (只讀文件系統(tǒng))。/dev/sr0 已按照只讀方式打開。  Error: 無效的分區(qū)表 - /dev/sr0 出現(xiàn)遞歸分區(qū)。

重載分區(qū)出現(xiàn)的上述信息中,當(dāng)時對于警告提示“設(shè)備或資源忙,需要重啟系統(tǒng)才能使更改生效”直接忽略,以為是正?,F(xiàn)象。但是對于錯誤信息“Error: 無效的分區(qū)表 - /dev/sr0 出現(xiàn)遞歸分區(qū)?!本陀悬c茫然了,不過,既然提示“無效的分區(qū)表”,那我查下分區(qū)信息。

3、使用fdisk -l 命令查看分區(qū)信息

[root@stduy /]# fdisk -l  Disk /dev/sda: 21.5 GB, 21474836480 bytes  255 heads, 63 sectors/track, 2610 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: 0x000b604c Device Boot Start End Blocks Id System  /dev/sda1 * 1 523 4194304 83 Linux  Partition 1 does not end on cylinder boundary.  /dev/sda2 523 784 2097152 82 Linux swap / Solaris  Partition 2 does not end on cylinder boundary.  /dev/sda3 784 2610 14672345 5 Extended  /dev/sda5 784 1421 5121671 83 Linux

查看分區(qū)信息,正常啊,并且剛才新建的擴展分區(qū)/dev/sda3和邏輯分區(qū)/dev/sda5都在。于是直接對新建的分區(qū)/dev/sda5進行格式化。

4、格式化新建的邏輯分區(qū)/dev/sda5

[root@stduy /]# mkfs -t ext3 /dev/sda5  mke2fs 1.41.12 (17-May-2010)

無法對 /dev/sda5 進行 stat 調(diào)用 --- 沒有那個文件或目錄
The device apparently does not exist; did you specify it correctly?

格式化時,提示“沒有那個文件或目錄”。這就奇怪了,操作是根據(jù)參考書上一步一步來的,怎么就不行了呢?于是百度Linux下新建分區(qū)的一些信息,希望可以的找到類似的錯誤,借鑒解決辦法。找了一圈下來,倒是有個類似的錯誤,但是沒有給出解決辦法。

重新分析新建分區(qū)并重載分區(qū)表的過程,對于“設(shè)備或資源忙”的提示,因為當(dāng)時就是在/dev/sda這塊硬盤上操作的,提示“設(shè)備或資源忙”應(yīng)該是正常的,重啟下應(yīng)該就可以了。但是重啟后,還是找不到/dev/sda5,但是fdisk -l 查看是有的。于是懷疑是不是重載分區(qū)表時的“Error: 無效的分區(qū)表 - /dev/sr0 出現(xiàn)遞歸分區(qū)?!卞e誤信息導(dǎo)致的呢?

查看了下/dev下的sr0

[root@stduy dev]# ls -lh | grep sr0  lrwxrwxrwx. 1 root root 3 8月 5 00:12 cdrom -> sr0  lrwxrwxrwx. 1 root root 3 8月 5 00:12 cdrw -> sr0  lrwxrwxrwx. 1 root root 3 8月 5 00:12 dvd -> sr0  lrwxrwxrwx. 1 root root 3 8月 5 00:12 dvdrw -> sr0  lrwxrwxrwx. 1 root root 3 8月 5 00:12 scd0 -> sr0  brw-rw----. 1 root cdrom 11, 0 8月 5 00:12 sr0

從上面的結(jié)果看,sr0是光驅(qū)設(shè)備,百度了下/dev/sr0這個設(shè)備,也所是光驅(qū)。于是管它重載分區(qū)表失敗是不是由于“Error: 無效的分區(qū)表 - /dev/sr0 出現(xiàn)遞歸分區(qū)?!币鸬模劝压怛?qū)移除了再說,反正是虛擬機上。

把虛擬機上的光驅(qū)設(shè)備移除后,重新啟動系統(tǒng),再重新新建分區(qū),并重新執(zhí)行partprobe命令重載分區(qū)表,錯誤信息“Error: 無效的分區(qū)表 - /dev/sr0 出現(xiàn)遞歸分區(qū)。”沒有了,只是警告提示“設(shè)備或資源忙”還在。這時直接格式化新建的邏輯分區(qū)/dev/sda5還是提示“沒有那個文件或目錄”。于是重啟系統(tǒng),再格式化/dev/sda5,這回成功了。

也就是,之前新建分區(qū)格式化失敗,是由于虛擬機的光驅(qū)/dev/sr0設(shè)備導(dǎo)致了分區(qū)表遞歸。另外由于是在同一塊硬盤上操作,所以必須要重啟系統(tǒng)才能使新建的分區(qū)寫入分區(qū)表生效。

那鳥哥的私房菜中,說的預(yù)留一塊容量用于分區(qū)練習(xí),鳥哥是怎么成功的呢?

于是又找了一些Linux磁盤管理相關(guān)的視頻和資料,發(fā)現(xiàn),他們使用fdisk新建分區(qū)都是使用的多塊硬盤實現(xiàn)的。再重新回去看鳥哥的私房菜,發(fā)現(xiàn)鳥哥預(yù)留的硬盤是/dev/hdc,那么鳥哥的環(huán)境中肯定還有/dev/hda和/dev/hdb,那么鳥哥試驗也是在多快硬盤的基礎(chǔ)上完成的。

那我再給虛擬機分配一塊硬盤試試。于是關(guān)閉系統(tǒng),在虛擬機上又給系統(tǒng)分配了一塊5G的虛擬磁盤空間。再開機進入系統(tǒng)重新對新加的磁盤空間進行分區(qū)、格式化等操作。

步驟還是和上面一樣,分區(qū)、重載分區(qū)表、查看分區(qū)、格式化,這里不再按步驟,直接給出完成的操作記錄。

[root@stduy ~]# fdisk -l   Disk /dev/sda: 21.5 GB, 21474836480 bytes  255 heads, 63 sectors/track, 2610 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: 0x000b604c   Device Boot Start End Blocks Id System  /dev/sda1 * 1 523 4194304 83 Linux  Partition 1 does not end on cylinder boundary.  /dev/sda2 523 784 2097152 82 Linux swap / Solaris  Partition 2 does not end on cylinder boundary.  /dev/sda3 784 2610 14672345 5 Extended  /dev/sda5 784 2610 14672313+ 83 Linux   Disk /dev/sdb: 5368 MB, 5368709120 bytes  255 heads, 63 sectors/track, 652 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   [root@stduy ~]# fdisk /dev/sdb  Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel  Building a new DOS disklabel with disk identifier 0x851e79cc.  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): p   Disk /dev/sdb: 5368 MB, 5368709120 bytes  255 heads, 63 sectors/track, 652 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: 0x851e79cc   Device Boot Start End Blocks Id System   Command (m for help): n  Command action  e extended  p primary partition (1-4)  p  Partition number (1-4): 1  First cylinder (1-652, default 1):   Using default value 1  Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652):   Using default value 652   Command (m for help): p   Disk /dev/sdb: 5368 MB, 5368709120 bytes  255 heads, 63 sectors/track, 652 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: 0x851e79cc   Device Boot Start End Blocks Id System  /dev/sdb1 1 652 5237158+ 83 Linux   Command (m for help): w  The partition table has been altered!   Calling ioctl() to re-read partition table.  Syncing disks.  [root@stduy ~]# partprobe /dev/sdb  [root@stduy ~]# mkfs -t ext4 /dev/sdb1  mke2fs 1.41.12 (17-May-2010)

文件系統(tǒng)標(biāo)簽=操作系統(tǒng):Linux塊大小=4096 (log=2)分塊大小=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks327680 inodes, 1309289 blocks65464 blocks (5.00%) reserved for the super user
***個數(shù)據(jù)塊=0Maximum filesystem blocks=134217728040 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736
正在寫入inode表: 完成

Creating journal (32768 blocks): 完成  Writing superblocks and filesystem accounting information: 完成  This filesystem will be automatically checked every 36 mounts or180 days, whichever comes first.   Use tune2fs -c or -i to override.

這回不管是新建分區(qū),還是重載分區(qū)表都沒有警告或錯誤提示了。成功實現(xiàn)在不重啟系統(tǒng)的情況下添加硬盤并對新增硬盤進行分區(qū)、格式化等操作。

感謝各位的閱讀,以上就是“Linux下新建分區(qū)并格式化的方法”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對Linux下新建分區(qū)并格式化的方法這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI