1.先查看新的盘所在位置 运行命令
fdisk -l
返回如下
Disk /dev/xvda: 42.9 GB, 42949672960 bytes255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000d7b57 Device Boot Start End Blocks Id System/dev/xvda1 2048 8386559 4192256 82 Linux swap / Solaris/dev/xvda2 * 8386560 83886079 37749760 83 LinuxDisk /dev/xvde: 322.1 GB, 322122547200 bytes255 heads, 63 sectors/track, 39162 cylinders, total 629145600 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/xvde doesn't contain a valid partition table
2.发现我们的那块硬盘是/dev/xvde,运行格式化命令对硬盘进行格式化
fdisk /dev/xvde
在格式化的过程中,要依次输入 m(查看帮助) n(添加一个新的分区) p(主分区) 1 w(保存)
整个过程如下
szvphicpra16181:/opt # fdisk /dev/xvdeDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0xad312bcf.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)Command (m for help): mCommand action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition 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): nCommand action e extended p primary partition (1-4)pPartition number (1-4, default 1): 1First sector (2048-629145599, default 2048):Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-629145599, default 629145599):Using default value 629145599Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.
3.经过格式化分区表之后,在用fdisk -l 命令发现已经有分区表了
szvphicpra16181:/opt # fdisk -lDisk /dev/xvda: 42.9 GB, 42949672960 bytes255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000d7b57 Device Boot Start End Blocks Id System/dev/xvda1 2048 8386559 4192256 82 Linux swap / Solaris/dev/xvda2 * 8386560 83886079 37749760 83 LinuxDisk /dev/xvde: 322.1 GB, 322122547200 bytes129 heads, 6 sectors/track, 812849 cylinders, total 629145600 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xad312bcf Device Boot Start End Blocks Id System/dev/xvde1 2048 629145599 314571776 83 Linux
采用ext3格式进行格式化 运行如下命令,与结果如下:(或者运行mkfs.ext3 /dev/vdb命令)
szvphicpra16181:/opt # mkfs -t ext3 /dev/xvde1mke2fs 1.41.9 (22-Aug-2009)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)19660800 inodes, 78642944 blocks3932147 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=42949672962400 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616Checking for bad blocks (read-only test): doneWriting inode tables: doneCreating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 26 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.
4.最后将对应的硬盘mount到相关的目录下
szvphicpra16181:/opt # mount /dev/xvde1 /opt/mount: warning: /opt/ seems to be mounted read-only.
5.通过df -h 命令可以看到 目录中硬盘的挂载情况
szvphicpra16181:/opt # df -hFilesystem Size Used Avail Use% Mounted on/dev/xvda2 36G 17G 19G 47% /udev 7.8G 120K 7.8G 1% /devtmpfs 7.8G 72K 7.8G 1% /dev/shm/dev/xvde1 296G 191M 281G 1% /opt
6.想要系统启动时,自动挂载该硬盘,则需要如下操作:
先找到磁盘的UUID
#sudo blkid/dev/xvda1: UUID="74be72d4-821a-4003-aabe-eead374660c4" TYPE="ext3"/dev/xvda2: UUID="12a0fbec-7a65-425d-89cd-b0f50b191a07" TYPE="swap"/dev/xvde: UUID="ed4b9a47-dab3-4820-9c8b-f82acb4629b1" TYPE="ext3"/dev/mapper/docker-202:1-1345069-pool: UUID="760c5e93-e079-4f5a-8d2e-319404a7935e" TYPE="xfs"#vi /etc/fstab
在最后一行添加
UUID=ed4b9a47-dab3-4820-9c8b-f82acb4629b1 /opt ext3 defaults 1 2