用過諸多種雲以后,發現有個通病,就是新買的數據盤在機器中找不到。本篇總結一下此類問題的解決方法,望各位點贊,有問題評論區見
一、雲服務和物理機一樣,你買了雲服務器的數據盤以后,就相當於把數據盤直接安裝硬盤到物理機上。
二、查看硬盤是否正確安裝。
使用“fdisk -l”命令查看硬盤代號。
root@Whel000010010:/home/share# fdisk -l Disk /dev/sda: 500.1 GB, 500107862016 bytes 255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors Units = 扇區 of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk identifier: 0x000aab9b 設備 啟動 起點 終點 塊數 Id 系統 /dev/sda1 * 2048 488282111 244140032 83 Linux /dev/sda2 488284158 976771071 244243457 5 擴展 Partition 2 does not start on physical sector boundary. /dev/sda5 488284160 820314111 166014976 83 Linux /dev/sda6 820316160 976771071 78227456 82 Linux 交換 / Solaris WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted. Disk /dev/sdb: 3000.6 GB, 3000592982016 bytes 255 heads, 63 sectors/track, 364801 cylinders, total 5860533168 sectors Units = 扇區 of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk identifier: 0x00000000 設備 啟動 起點 終點 塊數 Id 系統 /dev/sdb1 1 4294967295 2147483647+ ee GPT Partition 1 does not start on physical sector boundary.
可以看到我新增了的硬盤標識為sdb。
三、將硬盤分區。
1、當硬盤小於等於2T時,可以用fdisk。
fdisk /dev/sdb 1、查看幫助。 輸入:m 2、新建分區。 輸入:n 3、創建邏輯分區 輸入:p 4、輸入分區號以及指定分區大小 依照提示,回車表示默認。 5、檢查分區情況(此時還未執行分區操作) Command(m for help):p 6、保存退出 Command(m for help):w
這個是小盤分區的方式
2、當硬盤大於2T時,用parted命令。
選擇要分區的硬盤:parted /dev/sdb
使用print 對磁盤信息進行查看:
可以看到磁盤還沒有進行分區。
create the GPT disklabel – in other words, create the partitioning tables to support GPT:
建立GPT的磁盤標簽,換句話說就是創建磁盤分區表支持GPT
使用(parted) mklabel gpt
創建分區,並分配合適的大小
create a partition:創建一個分區,這個步驟總是有錯,選擇cancle.
這一步就用到了對齊的概念。
然而其實我並不是只想要一個分區,所以我們將上面的分區刪除,然后重新進行分區:
使用rm 編號 命令進行刪除。
從圖中打印的信息可以看到上面的分區已經刪除,回到之前未進行分區的狀態。
使用mkpart primary 0% n%創建主分區,n為要分的分區占整個磁盤的百分比.(mkpart extended創建擴展分區).
例如我這里想要把這個8T的硬盤分成三塊,其中前兩塊分別占2T,最后一塊占4T,則可以寫為:
mkpart primary 0% 25%
mkpart primary 26% 50%
mkpart primary 51% 100%
可用print 命令對分區進行查看。
分區格式化
可 將硬盤格式化為ext4格式,具體各格式的區別見ext2、ext3與ext4的區別
將三塊分區分別進行格式化。硬盤比較大時時間可能也較長等待ing。
真實案例走一波:
1. 第一步:查看磁盤狀態:
1 [root@wrhelpc0e2urb:/root]# 2 #-> fdisk -l 3 4 Disk /dev/sdc: 4000.8 GB, 4000787030016 bytes, 7814037168 sectors 5 Units = sectors of 1 * 512 = 512 bytes 6 Sector size (logical/physical): 512 bytes / 512 bytes 7 I/O size (minimum/optimal): 512 bytes / 512 bytes 8 9 WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion. 10 11 Disk /dev/sdd: 256.1 GB, 256060514304 bytes, 500118192 sectors 12 Units = sectors of 1 * 512 = 512 bytes 13 Sector size (logical/physical): 512 bytes / 512 bytes 14 I/O size (minimum/optimal): 512 bytes / 512 bytes 15 Disk label type: gpt 16 Disk identifier: 2AA8840C-1246-42C0-BC74-BB6BC3E245B3 17 18 19 # Start End Size Type Name 20 1 2048 1050623 512M EFI System EFI System Partition 21 2 1050624 2099199 512M Microsoft basic 22 3 2099200 453070847 215G Linux LVM 23 4 453070848 500117503 22.4G Linux swap 24 25 Disk /dev/sda: 4000.8 GB, 4000787030016 bytes, 7814037168 sectors 26 Units = sectors of 1 * 512 = 512 bytes 27 Sector size (logical/physical): 512 bytes / 512 bytes 28 I/O size (minimum/optimal): 512 bytes / 512 bytes 29 30 31 Disk /dev/sdb: 4000.8 GB, 4000787030016 bytes, 7814037168 sectors 32 Units = sectors of 1 * 512 = 512 bytes 33 Sector size (logical/physical): 512 bytes / 512 bytes 34 I/O size (minimum/optimal): 512 bytes / 512 bytes 35 36 37 Disk /dev/mapper/vg00-lv00: 230.9 GB, 230896435200 bytes, 450969600 sectors 38 Units = sectors of 1 * 512 = 512 bytes 39 Sector size (logical/physical): 512 bytes / 512 bytes 40 I/O size (minimum/optimal): 512 bytes / 512 bytes
2. 第二步:開始分區
1 [root@wrhelpc0e2urb:/root]# 2 #-> parted /dev/sda 3 GNU Parted 3.1 4 Using /dev/sda 5 Welcome to GNU Parted! Type 'help' to view a list of commands. 6 (parted) p 7 Error: /dev/sda: unrecognised disk label 8 Model: ATA ST4000NM0033-9ZM (scsi) 9 Disk /dev/sda: 4001GB 10 Sector size (logical/physical): 512B/512B 11 Partition Table: unknown 12 Disk Flags: 13 (parted) mktable gpt 14 (parted) p 15 Model: ATA ST4000NM0033-9ZM (scsi) 16 Disk /dev/sda: 4001GB 17 Sector size (logical/physical): 512B/512B 18 Partition Table: gpt 19 Disk Flags: 20 21 Number Start End Size File system Name Flags 22 23 (parted) mkpart 24 Partition name? []? 1 25 File system type? [ext2]? ext4 26 Start? 0% 27 End? 100% 28 (parted) p 29 Model: ATA ST4000NM0033-9ZM (scsi) 30 Disk /dev/sda: 4001GB 31 Sector size (logical/physical): 512B/512B 32 Partition Table: gpt 33 Disk Flags: 34 35 Number Start End Size File system Name Flags 36 1 1049kB 4001GB 4001GB 1 37 38 (parted) quit 39 Information: You may need to update /etc/fstab. 40 41 [root@wrhelpc0e2urb:/root]#
四、格式化分區。
1 [root@wrhelpc0e2urb:/root]# 2 #-> mkfs.ext4 /dev/sda1 3 mke2fs 1.42.9 (28-Dec-2013) 4 Filesystem label= 5 OS type: Linux 6 Block size=4096 (log=2) 7 Fragment size=4096 (log=2) 8 Stride=0 blocks, Stripe width=0 blocks 9 244195328 inodes, 976754176 blocks 10 48837708 blocks (5.00%) reserved for the super user 11 First data block=0 12 Maximum filesystem blocks=3124756480 13 29809 block groups 14 32768 blocks per group, 32768 fragments per group 15 8192 inodes per group 16 Superblock backups stored on blocks: 17 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 18 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 19 102400000, 214990848, 512000000, 550731776, 644972544 20 21 Allocating group tables: done 22 Writing inode tables: done 23 Creating journal (32768 blocks): done 24 Writing superblocks and filesystem accounting information: done
mkfs.ext4 /dev/sdb1
五、將硬盤掛載到文件夾下。
1、手動掛載。
新建一個文件夾:mkdir /bioinfo1
掛載:mount /dev/sdb1 /bioinfo1
2、開機自動掛載。
輸入:vi /etc/fstab
編輯完fstab的內容后,不必重啟執行該命令也可自動掛載:,mount -a
在最后加入:
/dev/sdb1 /bioinfo1 ext4 defaults 1 1
更換為 Linux 系統后,比如更換為 Centos,對於 NTFS 格式的數據盤默認是無法識別的,可以通過 ntfs-3g 進行識別。
-
執行如下命令安裝 ntfs-3g:
yum install -y ntfs-3g -
安裝成功后通過如下命令進行掛載,結果如下:
mount -t ntfs-3g /dev/xvdb5 /mnt
-
為保證開機能自動掛載,在 /etc/fstab 里面添加如下配置:
只讀方式掛載:echo "/dev/xvdb5 /mnt ntfs-3g ro,umask=0222,defaults 0 0" >> /etc/fstab
讀寫方式掛載:echo "/dev/xvdb6 /mnt ntfs-3g rw,umask=0000,defaults 0 0" >>/etc/fstab
** 說明:** Ubuntu 系統已經自帶了ntfs-3g 模塊,可以直接參閱上述步驟 2、3 進行掛載操作即可。
方法2
Linux 通過網絡掛載 windows 下 NTFS 文件格式。Linux 系統通過內網 IP 掛載 Windows 系統共享目錄命令是:mount -t cifs -o username="Administrator",passwd="xxxxx" //10.x.x.x/test /mnt
其中 x 內容表示隱藏,跟進實際情況填寫即可。

如果 mount 有異常的報錯,核實是否有安裝 cifs 組件。如果沒有安裝,則執行* **yum install cifs-utils -y *進行安裝然后重試。

