首頁 > 桌上型電腦

Linux下新增新硬碟,分割區並設定啟動自動掛載

2019-12-18 00:43:54

Linux下的分割區相對Windows而言要稍微複雜一點,下面就由我給大家帶來在Linux下新新增硬碟,分割區並實現系統啟動時自動掛載的過程

1

檢查發現系統上目前並沒有掛載新的硬碟,如下圖所示:


2

新增硬碟後我們啟動電腦並再次檢查,我們可以看到最下面多了一行「Disk /dev/sdb doesn't contain a valid partition table」,告訴我們有一塊新的硬碟,但是還沒有分割區;如下圖所示:


3

根據以上提示開始對新的硬碟進行分割區操作,由於截圖比較麻煩所以呢我把命裡copy出來了,需要操作的部分我會標記出來[root@Linux ~]#?fdisk /dev/sdb?? ??? ?//根據提示,對新硬碟進行分割區操作Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel. Changes will remain in memory only,until you decide to write them. After that, of course,
the previouscontent won't be recoverable.The number of cylinders for this disk is set to 2610.There is nothing wrong with that, but this is larger than 1024,and could in certain setups cause problems with:1) software that runs at boot time (e.g., old versions of LILO)2) booting and partitioning software from other OSs?? (e.g., DOS FDISK, OS/2 FDISK)Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)Command (m for help):?h?? ? ? ? ? ? ?//幫助資訊h: unknown commandCommand 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?? ??? ?//輸入 n,新建分割區Command action?? e?? extended?? ??? ??? ? ? ? ? ? ? ??//新建邏輯分割區?? p?? primary partition (1-4)?? ??//新建主分割區p?? ??? ??? ??? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??//輸入 p,建立主分割區Partition number (1-4):?1?? ?????//一共可以分4個主分割區,輸入 1,建立第一個主分割區First cylinder (1-2610, default 1):?//選擇該分割區的起始磁碟數,如無特殊需求強烈建議選擇預設,也就是預設用1 來分割區(直接按回車)Using default value 1Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610):?//定義該分割區的大小,如果按預設(直接回車),就是使用全部可用儲存空間;如果要分成一個 1G 的空間,輸入 +1024m 即可,1G=1024m演算法以此類推Using default value 2610Command (m for help):?w?? ????//寫入分割區資訊,其實就是儲存分割區資訊The partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.
nothing wrong with that, but this is larger than 1024,and could in certain setups cause problems with:1) software that runs at boot time (e.g., old versions of LILO)2) booting and partitioning software from other OSs?? (e.g., DOS FDISK, OS/2 FDISK)Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)Command (m for help):?h?? ? ? ? ? ? ?//幫助資訊h: unknown commandCommand 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?? ??? ?//輸入 n,新建分割區Command action?? e?? extended?? ??? ??? ? ? ? ? ? ? ??//新建邏輯分割區?? p?? primary partition (1-4)?? ??//新建主分割區p?? ??? ??? ??? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??//輸入 p,建立主分割區Partition number (1-4):?1?? ?????//一共可以分4個主分割區,輸入 1,建立第一個主分割區First cylinder (1-2610, default 1):?//選擇該分割區的起始磁碟數,如無特殊需求強烈建議選擇預設,也就是預設用1 來分割區(直接按回車)Using default value 1Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610):?//定義該分割區的大小,如果按預設(直接回車),就是使用全部可用儲存空間;如果要分成一個 1G 的空間,輸入 +1024m 即可,1G=1024m演算法以此類推Using default value 2610Command (m for help):?w?? ????//寫入分割區資訊,其實就是儲存分割區資訊The partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.

4

完成以上操作後我們可以看到新新增的硬碟已經存在分割區了


5

下面對分割區進行格式化操作:[root@Linux ~]#?mkfs -t ext3 -c?/dev/sdb1?? ?//對分割區使用 ext3 格式化,如果建立了多個分割區,顯示 /dev/sdb2、/dev/sdb3 等,以此類推,重複輸入這條命令,就可以進行其它分割區的格式化操作了。因為新硬碟加了-c引數,要先檢測磁碟壞軌,因此,這個過程全有些長,需要耐心等待……注意這裡的時間長短時根據你的硬碟大小來實現的,如果硬碟大時間就會久一些,否則就會小短一些mke2fs 1.39 (29-May-2006)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragmen
t size=4096 (log=2)1310720 inodes, 5241198 blocks131029?blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=0160 block groups32768 blocks per group, 32768 fragments per group16384 inodes per groupSuperblock backups stored on blocks:???????? 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Checking for bad blocks (read-only test): done ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Writing inode tables: done ? ? ? ? ? ? ? ? ? ? ? ? ? ?Creating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 32 mounts or180 days, whichever comes first.? Use tune2fs -c or -i to override.
data block=0Maximum filesystem blocks=0160 block groups32768 blocks per group, 32768 fragments per group16384 inodes per groupSuperblock backups stored on blocks:???????? 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Checking for bad blocks (read-only test): done ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Writing inode tables: done ? ? ? ? ? ? ? ? ? ? ? ? ? ?Creating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 32 mounts or180 days, whichever comes first.? Use tune2fs -c or -i to override.

6

開始對分割區進行掛載使用,首先建立一個用於掛載的目錄


7

將分割區掛載到www目錄下


8

輸入vim /etc/fstab進行編輯,並在該檔案內輸入以下內容,然後在:wq儲存並退出,重新啟動驗證即可



IT145.com E-mail:sddin#qq.com