參考:http://help.aliyun.com/knowledge_detail/5974154.html?spm=5176.788314850.3.2.hUqwXohtml
一、在阿里雲上購買了服務器,又另外買了一塊數據盤,這個時候就須要對數據盤進行分區和格式化。node
二、使用ssh鏈接到雲服務器,查看數據盤。服務器
1)在沒有分區和格式化數據盤以前,使用 「df –h」命令,是沒法看到數據盤的,以下:ssh
[root@iZ94jj63a3sZ ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 20G 1.4G 18G 8% / tmpfs 3.9G 0 3.9G 0% /dev/shm [root@iZ94jj63a3sZ ~]#
2)使用 「fdisk -l」 命令查看ide
[root@iZ94jj63a3sZ ~]# fdisk -l Disk /dev/xvda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 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: 0x00078f9c Device Boot Start End Blocks Id System /dev/xvda1 * 1 2611 20970496 83 Linux Disk /dev/xvdb: 64.4 GB, 64424509440 bytes 255 heads, 63 sectors/track, 7832 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: 0x00000000 [root@iZ94jj63a3sZ ~]#
可以看到 Disk /dev/xvdb: 64.4 GB, 64424509440 bytes 這就是要分區和格式化的數據盤ui
3)友情提示:若您執行fdisk -l命令,發現沒有 /dev/xvdb 代表您的雲服務無數據盤,那麼您無需進行掛載,此時該教程對您不適用阿里雲
三、對數據盤進行分區spa
1)執行「fdisk -S 56 /dev/xvdb」命令,對數據盤進行分區;code
2)根據提示,依次輸入「n」,「p」 ,「1」,兩次回車,「wq」,分區就開始了,很快就會完成。orm
[root@iZ94jj63a3sZ ~]# fdisk -S 56 /dev/xvdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x94d1a2b8. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-8811, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-8811, default 8811): Using default value 8811 Command (m for help): wq The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@iZ94jj63a3sZ ~]#
四、查看新的分區
使用「fdisk -l」命令能夠看到,新的分區xvdb1已經創建完成了。
[root@iZ94jj63a3sZ ~]# fdisk -l Disk /dev/xvda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 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: 0x00078f9c Device Boot Start End Blocks Id System /dev/xvda1 * 1 2611 20970496 83 Linux Disk /dev/xvdb: 64.4 GB, 64424509440 bytes 255 heads, 56 sectors/track, 8811 cylinders Units = cylinders of 14280 * 512 = 7311360 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x94d1a2b8 Device Boot Start End Blocks Id System /dev/xvdb1 1 8811 62910512 83 Linux [root@iZ94jj63a3sZ ~]#
五、格式化新分區
以ext4爲例:使用「mkfs.ext4 /dev/xvdb1」命令對新分區進行格式化,格式化的時間根據硬盤大小有所不一樣。
[root@iZ94jj63a3sZ ~]# mkfs.ext4 /dev/xvdb1 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 3932160 inodes, 15727628 blocks 786381 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 480 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, 7962624, 11239424 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 26 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@iZ94jj63a3sZ ~]#
六、添加分區信息
使用「echo '/dev/xvdb1 /mnt ext4 defaults 0 0' >> /etc/fstab」(不含引號)命令寫入新分區信息。
而後使用「cat /etc/fstab」命令查看,出現如下信息就表示寫入成功。
[root@iZ94jj63a3sZ ~]# echo '/dev/xvdb1 /mnt ext4 defaults 0 0' >> /etc/fstab [root@iZ94jj63a3sZ ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Thu Aug 14 21:16:42 2014 # # 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=94e4e384-0ace-437f-bc96-057dd64f42ee / ext4 defaults,barrier=0 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/xvdb1 /mnt ext4 defaults 0 0 [root@iZ94jj63a3sZ ~]#
七、掛載新分區
使用「mount -a」命令掛載新分區,而後用「df -h」命令查看,出現如下信息就說明掛載成功,能夠開始使用新的分區了。
[root@iZ94jj63a3sZ ~]# mount -a [root@iZ94jj63a3sZ ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 20G 1.5G 18G 8% / tmpfs 3.9G 0 3.9G 0% /dev/shm /dev/xvdb1 60G 180M 56G 1% /mnt [root@iZ94jj63a3sZ ~]#