linux分区 挂盘,linux分区与格式化磁盘挂载磁盘与自动挂载详细教程
新購了一臺服務器,加了一塊磁盤,隨手寫一下操作過程。
服務器環境 centos7 64位
使用fdisk命令查看所有能被linux識別的磁盤,例如fdisk -l列出所有磁盤
掛載磁盤步驟:
1.要掛載新磁盤需要先建一個文件夾用來掛載新磁盤,例如mkdir ./wwwroot
用fdisk -l 查到一個新磁盤
Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 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
2.給新磁盤分區,我就直接分成一個區;
fdisk /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 0x9dc66e42.
Command (m for help): m #輸入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)
Command (m for help): n #輸入n表示我們要添加一個新分區
Partition type:
p? ?primary (0 primary, 0 extended, 4 free)
e? ?extended
Select (default p): #這里直接回車或者輸入p表示要建立一個主分區 默認就是p建立主分區
Using default response p
Partition number (1-4, default 1): #分區號默認為1,如果該磁盤已有分區這里顯示會是2-4,default 2 這里直接默認就行,系統已經計算好了的
First sector (2048-419430399, default 2048):? #這里是輸入分區的起始扇區,也直接回車就行了;
Using default value 2048
#這里直接加車的話就是把這個磁盤所有空間分為一個區,如果你想給第一個分區分80G 那么請輸入 +80G
#Last sector, +sectors or +size{K,M,G} (2048-419430399, default 419430399): +80G
Last sector, +sectors or +size{K,M,G} (2048-419430399, default 419430399):? #我這里是一個數據盤我就直接全部分了,直接回車
Using default value 419430399
Partition 1 of type Linux and of size 200 GiB is set #提示分區1的大小設置為200G
#這里接下來又會回到最開始分區的時候
Command (m for help): m #我們輸入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)
Command (m for help): p #然后輸入p我們打印一下這個磁盤的分區表看一下
Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 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: 0x9dc66e42
Device Boot? ? ? Start? ? ? ? ?End? ? ? Blocks? ?Id? System
/dev/vdb1? ? ? ? ? ? 2048? ?419430399? ?209714176? ?83? Linux
#看到分區信息,這個時候分區表還在內存中,并沒有寫入磁盤;
#輸入w,寫入分區表到磁盤
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
#寫入分區表成功 讓調用ioctl()加載分區表 這東西不好用,個人感覺太復雜因為我也沒用過還是用下面的一個命令來完成這個偉大的任務
partprobe /dev/vdb#用這個命令重新加載磁盤分區表
ls -l /sbin/mkfs.* #查看支持的文件系統
#這里我就用ext4文件系統
/sbin/mkfs.ext4 /dev/vdb1 #/dev/vdb1這個分區就是我們剛才分的200G的那個
#格式化完成,接下來掛載一下就OK了
mount /dev/vdb1 /wwwroot
[root@xxx /]# df
Filesystem? ? ?1K-blocks? ? Used Available Use% Mounted on
/dev/vda1? ? ? ?41151808 1467808? 37570568? ?4% /
devtmpfs? ? ? ? ?8124356? ? ? ?0? ?8124356? ?0% /dev
tmpfs? ? ? ? ? ? 8133860? ? ? ?0? ?8133860? ?0% /dev/shm
tmpfs? ? ? ? ? ? 8133860? ? ?332? ?8133528? ?1% /run
tmpfs? ? ? ? ? ? 8133860? ? ? ?0? ?8133860? ?0% /sys/fs/cgroup
tmpfs? ? ? ? ? ? 1626776? ? ? ?0? ?1626776? ?0% /run/user/0
/dev/vdb1? ? ? 206291944? ?61464 195728388? ?1% /wwwroot
掛載成功,然后就是設置自動掛載,這樣以后重啟服務器就自動掛載了
#在設置自動掛載前,查詢一下uuid使用blkid命令
[root@xxxxx /]# blkid
/dev/vda1: UUID="eb448abb-3012-4d8d-bcde-94434d586a31" TYPE="ext4"
/dev/vdb1: UUID="7a7502e2-2cb5-4cc6-b594-361c60ae8092" TYPE="ext4"
vi /etc/fstab #編輯這個文件離開入下面這一行
##當然可以用uuid來掛載,這樣的話以后增加減少磁盤都不會有問題。
#UUID=7a7502e2-2cb5-4cc6-b594-361c60ae8092? /wwwroot ext4 defaults 0 0
/dev/vdb1? /wwwroot ext4 defaults 0 0
#/dev/vdb1 這個是分區 /wwwroot 這個是要掛載的目錄
#最后最重要的一步就是要檢查一下有沒有問題
運行mount -a
如果沒有報錯那就一切正常,重啟一下服務器。
運行df 查看就能看到咯。
最后總結一下流程
1.先查看磁盤fdisk -l 找到要掛載的磁盤 上例中要分區的磁盤是/dev/vdb
2.給磁盤分區 fdisk /dev/vdb? 根據提示進行分區與格式化,分區完后不要忘了寫入分區表
3.格式化分區/sbin/mkfs.ext4 /dev/vdb1
4.掛載分區前要先創建一個掛載點(就是一個目錄),掛載分區mount /dev/vdb1 /wwwroot
5.設置自動掛載vi /etc/fstab
6.這個最重要一定要先檢查是否有錯再重啟mount -a運行后沒有任可信息顯示那就表示一切正常了,否則就要根據錯誤提示解決問題,如果不解決錯誤就直接重啟的話,可能造成開不了機的嚴重后果,服務器開不了機的后果自己想想.
總結
以上是生活随笔為你收集整理的linux分区 挂盘,linux分区与格式化磁盘挂载磁盘与自动挂载详细教程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux mrtg 进程名称,Linu
- 下一篇: linux怎么把磁盘的东西拷贝,[Lin