1. 程式人生 > >Linux新增新磁碟及掛載

Linux新增新磁碟及掛載

目錄

檢視磁碟

以root使用者登入,執行fdisk -lu檢視所有磁碟資訊
這裡寫圖片描述

建立分割槽

進入磁碟/dev/sdb命令: fdisk /dev/sdb 輸入m 檢視命令幫助如下:

[email protected]:/# fdisk /dev/sdb 

Welcome to fdisk (util-linux 2.29.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.
Created a
new DOS disklabel with disk identifier 0x886fa276. Command (m for help): m Help: DOS (MBR) a toggle a bootable flag b edit nested BSD disklabel c toggle the dos compatibility flag Generic d delete a partition F list free unpartitioned space l list known partition types n add
a new partition p print the partition table t change a partition type v verify the partition table i print information about a partition Misc m print this menu u change display/entry units x extra functionality (experts only) Script I load disk layout from sfdisk script file O dump disk layout to sfdisk script file Save & Exit w write table to disk and exit q quit without saving changes Create a new label g create a new empty GPT partition table G create a new empty SGI (IRIX) partition table o create a new empty DOS partition table s create a new empty Sun partition table

輸入n 進行分割槽:

這裡寫圖片描述

一定記得輸入w才能儲存分割槽更改

fdisk -l 新增分割槽為/dev/sdb1

這裡寫圖片描述

格式化

# mkfs.ext4 /dev/sdb1
這裡寫圖片描述

掛載

mount 命令可以將分割槽掛載到目錄下

建立/opt/app目錄

# mkdir /opt/app

掛載

# mount /dev/sdb1 /opt/app

檢視

# df -h
這裡寫圖片描述

配置開機自動掛載

vim /etc/fstab

後面追加一行:

/dev/sdb1(磁碟分割槽) /opt/app(掛載目錄) ext4(檔案格式)defaults 0 0