首頁 > 軟體

設定VMware掛載新加入的磁碟

2020-06-16 17:23:31

在VMware虛擬機器設定中增加磁碟後,啟動Linux,使用root登入。

首先檢視未分割區的磁碟,使用下面命令:

## 檢視未使用的磁碟
fdisk -l

 

磁碟/dev/sdb後面沒有任何分割區,是新掛載的磁碟

輸入下面命令來開始對磁碟/dev/sdb進行分割區

## 開始格式化磁碟 ##
fdisk /dev/sdb

有如下提示:

[root@localhost dev]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


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
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   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) 

首選使用n來建立一個擴充套件分割區,輸入選項n:

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 

選擇建立擴充套件分割區,輸入選項e,然後選擇擴充套件分割區編號、起始位置和大小,我們選擇整個磁碟只建立一個擴充套件分割區:

Select (default p): e
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): 
Using default value 41943039
Partition 1 of type Extended and of size 20 GiB is set

擴充套件分割區建立好後,可以在此基礎上進行建立邏輯分割區,我們建立2個邏輯分割區並分別設定為10G:

Command (m for help): n     
Partition type:
   p   primary (0 primary, 1 extended, 3 free)
   l   logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (4096-41943039, default 4096): 
Using default value 4096
Last sector, +sectors or +size{K,M,G} (4096-41943039, default 41943039): +10G
Partition 5 of type Linux and of size 10 GiB is set

Command (m for help): n  
Partition type:
   p   primary (0 primary, 1 extended, 3 free)
   l   logical (numbered from 5)
Select (default p): l
Adding logical partition 6
First sector (20977664-41943039, default 20977664): 
Using default value 20977664
Last sector, +sectors or +size{K,M,G} (20977664-41943039, default 41943039): 
Using default value 41943039
Partition 6 of type Linux and of size 10 GiB is set

最後使用選項p來檢視分好的分割區:

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x40e44e64

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    41943039    20970496    5  Extended
/dev/sdb5            4096    20975615    10485760   83  Linux
/dev/sdb6        20977664    41943039    10482688   83  Linux 

為磁碟分配好分割區後,需要使用選項w來進行儲存:

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

在執行partprobe命令來重新讀取分割區資訊,如果有警告可以忽略。

## 重新讀取分割區資訊 ##
partprobe

然後需要對磁碟進行格式化,使用mkfs將磁碟格式化為ext4格式(注意擴充套件分割區不能進行格式化)

mkfs -t ext4 /dev/sdb5
mke2fs
1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 655360 inodes, 2621440 blocks 131072 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2151677952 80 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 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done 

然後我們建立兩個目錄來掛載這兩個邏輯分割區:

## 然後建立目錄 ##
mkdir /disk5 /disk6

## 使用mount命令來掛載目錄 ##
mount /dev/sdb5 /disk5
mount /dev/sdb6 /disk6


最後使用mount命令來檢視掛載情況

[root@localhost dev]# ## 使用mount命令來檢視掛載情況 ##
[root@localhost dev]# mount | grep "sdb"
/dev/sdb5 on /disk5 type ext4 (rw,relatime,seclabel,data=ordered)
/dev/sdb6 on /disk6 type ext4 (rw,relatime,seclabel,data=ordered)

本文永久更新連結地址http://www.linuxidc.com/Linux/2017-01/139596.htm


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