在Linux上對固態硬盤進行分區、格式化和掛載的步驟如下:
-
插入固態硬盤:將固態硬盤插入計算機的SATA或M.2接口。
-
確認固態硬盤被識別:打開終端,輸入以下命令查看硬盤是否被系統識別
fdisk -l
查找硬盤列表中的固態硬盤,它通常會以 “/dev/sdX” 的形式出現,其中 “X” 是字母(如 /dev/sda、/dev/sdb 等)。
分區
- 使用 fdisk 創建分區
sudo fdisk /dev/sdX
或sudo fdisk /dev/nvme0n1
彈出如下互動:
Welcome to fdisk (util-linux 2.35.1).
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 0x4121f825.Command (m for help):
進入 fdisk,按照引導進行以下操作:
Command (m for help): g # 創建GPT分區表(或輸入o創建MBR分區表,推薦GPT)
Command (m for help): n # 新建分區p primary (0 primary, 0 extended, 4 free)e extended (container for logical partitions)
Select (default p):Using default response p.Partition number (1-128): 1 # 分區號(默認1)
First sector: 回車 # 起始扇區(默認2048)
Last sector: 回車 # 結束扇區(默認全部空間,也可指定如+100G)
Command (m for help): t # 更改類型(GPT無需此步,MBR可選83-Linux)
Command (m for help): w # 寫入并退出(分區生效)
?格式化
將分區格式化為?EXT4?文件系統(推薦):
sudo mkfs.ext4 /dev/nvme0n1p1 # 替換p1為實際分區號
root@AM64x-Tronlong:~# mkfs.ext4 /dev/nvme0n1p1
mke2fs 1.45.7 (28-Jan-2021)
Discarding device blocks: done
Creating filesystem with 244190390 4k blocks and 61054976 inodes
Filesystem UUID: fd7587c6-5183-4dbc-9479-0f36dc8702cb
Superblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,102400000, 214990848Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: doneroot@AM64x-Tronlong:~#
(可選其他文件系統如NTFS/FAT32:sudo mkfs.ntfs /dev/nvme0n1p1
)
mkfs.ext4 /dev/nvme0n1 //會直接在整塊固態硬盤上創建 EXT4 文件系統,//系統警告:直接格式化整個磁盤會破壞現有分區表
直接在整塊固態硬盤上創建 EXT4 文件系統?
root@AM64x-Tronlong:~# mkfs.ext4 /dev/nvme0n1
mke2fs 1.45.7 (28-Jan-2021)
Found a dos partition table in /dev/nvme0n1
Proceed anyway? (y,N) y
Discarding device blocks: done
Creating filesystem with 244190646 4k blocks and 61054976 inodes
Filesystem UUID: c378915e-fd9f-481a-b927-d2187d0f7034
Superblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,102400000, 214990848Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done
?
掛載
創建掛載點?:
輸入以下命令創建一個用于掛載分區的目錄,可以選擇一個合適的位置和名稱:
sudo mkdir /my_data/ #你覺得合適的路徑
掛載分區:?
使用以下命令將格式化后的分區掛載到剛才創建的掛載點上:?
sudo mount /dev/nvme0n1p1 /my_data/
驗證掛載:
df -h | grep nvme
# 應顯示:
/dev/nvme0n1p1 916G 28K 870G 1% /my_data
?設置開機自動掛載:
修改?/etc/fstab
?文件:系統核心配置文件,全稱為?File System Table(文件系統表)
sudo nano /etc/fstab
或 vi /etc/fstab
在文件末尾添加:
/dev/nvme0n1p1 /my_data ext4 defaults 0 2
?保存后驗證配置:
sudo mount -a # 無報錯即表示配置正確
確保將 “/dev/sdX” 替換為實際的分區設備文件路徑,將 “/mnt/mydrive” 替換為你選擇的掛載點路徑。
現在,你的固態硬盤已經分區、格式化,并成功掛載到指定的掛載點上了。你可以通過訪問掛載點來管理和使用這個分區
?