歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 配置VMware掛載新加入的磁盤

配置VMware掛載新加入的磁盤

日期:2017/2/28 13:44:36   编辑:Linux教程

在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)
Copyright © Linux教程網 All Rights Reserved