1吼砂、運行fdisk -l命令查看實例是否有數(shù)據(jù)盤。如果執(zhí)行命令后因俐,沒有發(fā)現(xiàn)/dev/vdb周偎,表示您的實例沒有數(shù)據(jù)盤,無需格式化數(shù)據(jù)盤澳眷,請忽略本文后續(xù)內(nèi)容蛉艾。
如果您的數(shù)據(jù)盤顯示的是dev/xvd?衷敌,表示您使用的是非 I/O 優(yōu)化實例逢享。
其中?是 a?z 的任一個字母吴藻。
2、創(chuàng)建一個單分區(qū)數(shù)據(jù)盤侧但,依次執(zhí)行以下命令:
運行fdisk /dev/vdb:對數(shù)據(jù)盤進(jìn)行分區(qū)航罗。
輸入n并按回車鍵:創(chuàng)建一個新分區(qū)。
輸入p并按回車鍵:選擇主分區(qū)柏锄。因為創(chuàng)建的是一個單分區(qū)數(shù)據(jù)盤复亏,所以只需要創(chuàng)建主分區(qū)。
輸入分區(qū)編號并按回車鍵抬闷。因為這里僅創(chuàng)建一個分區(qū)耕突,可以輸入 1。
輸入第一個可用的扇區(qū)編號:按回車鍵采用默認(rèn)值 1炕泳。
輸入最后一個扇區(qū)編號:因為這里僅創(chuàng)建一個分區(qū)上祈,所以按回車鍵采用默認(rèn)值雇逞。
輸入wq并按回車鍵,開始分區(qū)节仿。
[root@iXXXXXXX~]# fdisk /dev/vdb
Devicecontains neitheravalid DOS partitiontable, nor Sun, SGI or OSF disklabel
Buildinganew DOS disklabel with disk identifier 0x5f46a8a2.
Changes will remain in memory only, untilyou decidetowritethem.
Afterthat,ofcourse, the previous content won'tberecoverable.
Warning: invalid flag0x0000of partitiontable4 willbe corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
? switchoff themode(command'c') andchangedisplayunitsto
? sectors (command'u').
Command (m forhelp): n
Command action
e? extended
p? primary partition (1-4)
p
Partitionnumber(1-4): 1
First cylinder (1-41610, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-41610, default 41610):
Using default value41610
Command (mforhelp):wq
Thepartitiontablehasbeen altered!
Calling ioctl()tore-readpartition table.
Syncing disks.
3廊宪、查看新的分區(qū):運行命令fdisk -l。如果出現(xiàn)以下信息箭启,說明已經(jīng)成功創(chuàng)建了新分區(qū) /dev/vdb1。
[root@iXXXXXXX ~]# fdisk -l
Disk /dev/vda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00053156
Device Boot? ? ? Start? ? ? ? End? ? ? Blocks? Id? System
/dev/vda1? *? ? ? ? ? 1? ? ? ? 5222? ? 41942016? 83? Linux
Disk /dev/vdb: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x5f46a8a2
Device Boot? ? ? Start? ? ? ? End? ? ? Blocks? Id? System
/dev/vdb1? ? ? ? ? ? ? 1? ? ? 41610? ? 20971408+? 83? Linux
4放妈、在新分區(qū)上創(chuàng)建一個文件系統(tǒng):運行命令mkfs.ext3 /dev/vdb1荐操。
本示例要創(chuàng)建一個 ext3 文件系統(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@iXXXXXXX~]# mkfs.ext3 /dev/vdb1
mke2fs 1.41.12 (17-May-2010)
Filesystemlabel=
OStype: Linux
Blocksize=4096 (log=2)
Fragmentsize=4096 (log=2)
Stride=0 blocks, Stripewidth=0 blocks
1310720 inodes, 5242852 blocks
262142 blocks(5.00%) reserved for the super user
Firstdatablock=0
Maximumfilesystemblocks=4294967296
160 block groups
32768 blocks pergroup, 32768 fragments per group
8192 inodes pergroup
Superblockbackups storedonblocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Writing inode tables: done
Creatingjournal (32768blocks): done
Writing superblocks andfilesystem accounting information: done
This filesystem will be automatically checkedevery37 mounts or
180 days, whichever comes first.? Use tune2fs -c or -itooverride.
5罢维、(建議)備份etc/fstab:運行命令cp /etc/fstab /etc/fstab.bak肺孵。
6、向/etc/fstab寫入新分區(qū)信息:運行命令echo /dev/vdb1 /mnt ext3 defaults 0 0 >> /etc/fstab吓肋。
說明:Ubuntu 12.04 不支持 barrier瑰艘,所以對該系統(tǒng)正確的命令是:echo '/dev/vdb1 /mnt ext3 barrier=0 0 0' >> /etc/fstab肤舞。
如果需要把數(shù)據(jù)盤單獨掛載到某個文件夾均蜜,比如單獨用來存放網(wǎng)頁囤耳,請將以上命令 /mnt 替換成所需的掛載點路徑。
7慰安、查看/etc/fstab中的新分區(qū)信息:運行命令cat /etc/fstab聪铺。
[root@iXXXXXXX ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Feb 23 07:28:22 2017
#
#Accessible filesystems, by reference, are maintained under'/dev/disk'
#See man pages fstab(5), findfs(8), mount(8) and/or blkid(8)formore info
#
UUID=3d083579-f5d9-4df5-9347-8d27925805d4 /? ? ? ? ? ? ? ? ? ? ? ext4? ? defaults? ? ? ? 1 1
tmpfs? ? ? ? ? ? ? ? ? /dev/shm? ? ? ? ? ? ? ? tmpfs? defaults? ? ? ? 0 0
devpts? ? ? ? ? ? ? ? ? /dev/pts? ? ? ? ? ? ? ? devpts? gid=5,mode=620? 0 0
sysfs? ? ? ? ? ? ? ? ? /sys? ? ? ? ? ? ? ? ? ? sysfs? defaults? ? ? ? 0 0
proc? ? ? ? ? ? ? ? ? ? /proc? ? ? ? ? ? ? ? ? proc? ? defaults? ? ? ? 0 0
/dev/vdb1 /mnt ext3 defaults 0 0
8铃剔、掛載文件系統(tǒng):運行命令mount /dev/vdb1 /mnt。
9凤类、查看目前磁盤空間和使用情況:運行命令df -h普气。如果出現(xiàn)新建文件系統(tǒng)的信息,說明掛載成功夷磕,可以使用新的文件系統(tǒng)了仔沿。
掛載操作完成后,不需要重啟實例即可開始使用新的文件系統(tǒng)绵跷。
[root@iXXXXXXX ~]# mount /dev/vdb1 /mnt
[root@iXXXXXXX ~]# df -h
Filesystem? ? ? Size? Used Avail Use% Mounted on
/dev/vda1? ? ? ? 40G? 6.6G? 31G? 18% /
tmpfs? ? ? ? ? 499M? ? 0? 499M? 0% /dev/shm
/dev/vdb1? ? ? ? 20G? 173M? 19G? 1% /mnt