linux 挂载新的硬盘

1.先查看新的盘所在位置 运行命令

fdisk -l

返回如下

Disk /dev/xvda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 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 identifier: 0x000d7b57

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1            2048     8386559     4192256   82  Linux swap / Solaris
/dev/xvda2   *     8386560    83886079    37749760   83  Linux

Disk /dev/xvde: 322.1 GB, 322122547200 bytes
255 heads, 63 sectors/track, 39162 cylinders, total 629145600 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 identifier: 0x00000000

Disk /dev/xvde doesn't contain a valid partition table

2.发现我们的那块硬盘是/dev/xvde,运行格式化命令对硬盘进行格式化

fdisk /dev/xvde

在格式化的过程中,要依次输入 m(查看帮助) n(添加一个新的分区) p(主分区) 1 w(保存)

整个过程如下

szvphicpra16181:/opt # fdisk /dev/xvde
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building 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): m
Command 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): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4, default 1): 1
First sector (2048-629145599, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-629145599, default 629145599):
Using default value 629145599

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

3.经过格式化分区表之后,在用fdisk -l 命令发现已经有分区表了

szvphicpra16181:/opt # fdisk -l

Disk /dev/xvda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 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 identifier: 0x000d7b57

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1            2048     8386559     4192256   82  Linux swap / Solaris
/dev/xvda2   *     8386560    83886079    37749760   83  Linux

Disk /dev/xvde: 322.1 GB, 322122547200 bytes
129 heads, 6 sectors/track, 812849 cylinders, total 629145600 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 identifier: 0xad312bcf

    Device Boot      Start         End      Blocks   Id  System
/dev/xvde1            2048   629145599   314571776   83  Linux

采用ext3格式进行格式化 运行如下命令,与结果如下:

szvphicpra16181:/opt # mkfs -t ext3 -c /dev/xvde1
mke2fs 1.41.9 (22-Aug-2009)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
19660800 inodes, 78642944 blocks
3932147 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
2400 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, 20480000, 23887872, 71663616

Checking for bad blocks (read-only test): done
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.

4.最后将对应的硬盘mount到相关的目录下

szvphicpra16181:/opt # mount /dev/xvde1 /opt/
mount: warning: /opt/ seems to be mounted read-only.

5.通过df -h 命令可以看到 目录中硬盘的挂载情况

szvphicpra16181:/opt # df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda2       36G   17G   19G  47% /
udev            7.8G  120K  7.8G   1% /dev
tmpfs           7.8G   72K  7.8G   1% /dev/shm
/dev/xvde1      296G  191M  281G   1% /opt

6.想要系统启动时,自动挂载该硬盘,则需要如下操作:

#vi  /etc/fstab

在最后一行添加

/dev/xvde1           /opt            ext3       defaults              1 2

猜你喜欢

转载自my.oschina.net/u/1473861/blog/1619474