linux系統(tǒng)分區(qū)格式化和掛載數(shù)據(jù)盤的示例分析

這篇文章給大家介紹linux系統(tǒng)分區(qū)格式化和掛載數(shù)據(jù)盤的示例分析,內(nèi)容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

創(chuàng)新互聯(lián)從2013年成立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務公司,擁有項目做網(wǎng)站、網(wǎng)站建設(shè)網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元包河做網(wǎng)站,已為上家服務,為包河各地企業(yè)和個人服務,聯(lián)系電話:13518219792

使用【管理終端】,或遠程連接工具,輸入用戶名 root 和密碼登錄到linux系統(tǒng)。

1、運行fdisk -l命令查看數(shù)據(jù)盤。在沒有分區(qū)和格式化數(shù)據(jù)盤之前,使用 “df –h”命令,是無法看到數(shù)據(jù)盤的,可以使用“fdisk -l”命令查看。

執(zhí)行命令后,如果不存在 /dev/vdb,表示沒有數(shù)據(jù)盤。確認數(shù)據(jù)盤是否已掛載。

2、依次執(zhí)行以下命令以創(chuàng)建一個單分區(qū)數(shù)據(jù)盤:

(1)運行fdisk -u /dev/vdb:分區(qū)數(shù)據(jù)盤。

(2)輸入p:查看數(shù)據(jù)盤的分區(qū)情況。本示例中,數(shù)據(jù)盤沒有分區(qū)。

(3)輸入n:創(chuàng)建一個新分區(qū)。

(4)輸入p:選擇分區(qū)類型為主分區(qū)。

說明 本示例中創(chuàng)建一個單分區(qū)數(shù)據(jù)盤,所以只需要創(chuàng)建主分區(qū)。如果要創(chuàng)建四個以上分區(qū),您應該創(chuàng)建至少一個擴展分區(qū),即選擇 e(extended)。

(5)輸入分區(qū)編號并按回車鍵。本示例中,僅創(chuàng)建一個分區(qū),輸入1。

(6)輸入第一個可用的扇區(qū)編號:按回車鍵采用默認值2048。

(7)輸入最后一個扇區(qū)編號:本示例僅創(chuàng)建一個分區(qū),按回車鍵采用默認值。

(8)輸入p:查看該數(shù)據(jù)盤的規(guī)劃分區(qū)情況。

(9)輸入w:開始分區(qū),并在分區(qū)后退出。

[root@ecshost~ ]# fdisk -u /dev/vdb
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.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x3e60020e.
 
Command (m for help): p
Disk /dev/vdb: 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: 0x3e60020e
Device Boot Start End Blocks Id System
 
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
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 Linux and of size 20 GiB is set
 
Command (m for help): p
 
Disk /dev/vdb: 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: 0x3e60020e
Device Boot Start End Blocks Id System
/dev/vdb1 2048 41943039 20970496 83 Linux
 
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.

3、運行命令fdisk -lu /dev/vdb 查看新分區(qū)。

如果出現(xiàn)以下信息,表示新分區(qū)/dev/vdb1創(chuàng)建成功。

[root@ecshost~ ]# fdisk -lu /dev/vdb
 
Disk /dev/vdb: 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: 0x3e60020e
 
Device Boot Start End Blocks Id System
/dev/vdb1 2048 41943039 20970496 83 Linux

4、運行命令mkfs.ext4 /dev/vdb1在新分區(qū)上創(chuàng)建一個文件系統(tǒng)。

本示例中,創(chuàng)建一個ext4文件系統(tǒng)。您也可以根據(jù)自己的需要,選擇創(chuàng)建其他文件系統(tǒng),例如:如果您需要在 Linux、Windows和Mac系統(tǒng)之間共享文件,可以使用mkfs.vfat創(chuàng)建VFAT文件系統(tǒng)。

說明 創(chuàng)建文件系統(tǒng)所需時間取決于數(shù)據(jù)盤大小。

[root@ecshost~ ]# mkfs.ext4 /dev/vdb1
 
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
1310720 inodes, 5242624 blocks
262131 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2153775104
160 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, 2654208,
4096000
 
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

5、(建議)運行命令cp /etc/fstab /etc/fstab.bak備份etc/fstab文件。

6、運行命令echo /dev/vdb1 /data0 ext4 defaults 0 0 >> /etc/fstab向/etc/fstab寫入新分區(qū)信息。

說明 Ubuntu 12.04系統(tǒng)不支持barrier,您需要運行命令 echo '/dev/vdb1 /data0 ext4 barrier=0 0 0' >> /etc/fstab。

如要把數(shù)據(jù)盤單獨掛載到某個文件夾,例如單獨用來存放網(wǎng)頁,則將命令中/data0替換成所需的掛載點路徑。

7、運行命令cat /etc/fstab查看/etc/fstab中的新分區(qū)信息。

[root@ecshost~ ]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Dec 12 07:53:08 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=d67c3b17-255b-4687-be04-f29190d37396 / ext4 defaults 1 1
/dev/vdb1 /mnt ext4 defaults 0 0

8、運行命令mount /dev/vdb1 /data0掛載文件系統(tǒng)。

9、運行命令df -h 查看目前磁盤空間和使用情況。

出現(xiàn)新建文件系統(tǒng)的信息,表示掛載成功。

<div><br class="Apple-interchange-newline">[root@ecshost~ ]# df -h

Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 1.6G 36G 5% /
devtmpfs 234M 0 234M 0% /dev
tmpfs 244M 0 244M 0% /dev/shm
tmpfs 244M 484K 244M 1% /run
tmpfs 244M 0 244M 0% /sys/fs/cgroup
tmpfs 49M 0 49M 0% /run/user/0
/dev/vdb1 20G 45M 19G 1% /mnt</div>
12345678910    [root@ecshost~ ]# df -h Filesystem Size Used Avail Use% Mounted on/dev/vda1 40G 1.6G 36G 5% /devtmpfs 234M 0 234M 0% /devtmpfs 244M 0 244M 0% /dev/shmtmpfs 244M 484K 244M 1% /runtmpfs 244M 0 244M 0% /sys/fs/cgrouptmpfs 49M 0 49M 0% /run/user/0/dev/vdb1 20G 45M 19G 1% /mnt

10、最后 reboot,重啟服務器。

關(guān)于linux系統(tǒng)分區(qū)格式化和掛載數(shù)據(jù)盤的示例分析就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

當前名稱:linux系統(tǒng)分區(qū)格式化和掛載數(shù)據(jù)盤的示例分析
文章起源:http://muchs.cn/article6/pdgdig.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)虛擬主機、標簽優(yōu)化、網(wǎng)站設(shè)計、小程序開發(fā)、建站公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化