读书人

Linux停添加新硬盘,分区及挂载

发布时间: 2013-08-22 10:08:34 作者: rapoo

Linux下添加新硬盘,分区及挂载

1:查看挂载好的硬盘

? ?

[root@localhost ~]# fdisk -l#-------------- 第一块硬盘 /dev/xvda --------------------------Disk /dev/xvda: 214.7 GB, 214748364800 bytes255 heads, 63 sectors/track, 26108 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000af342    Device Boot      Start         End      Blocks   Id  System/dev/xvda1   *           1          64      512000   83  LinuxPartition 1 does not end on cylinder boundary./dev/xvda2              64       26109   209202176   8e  Linux LVMDisk /dev/xvdd: 118 MB, 118593536 bytes255 heads, 63 sectors/track, 14 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/VolGroup-lv_root: 53.7 GB, 53687091200 bytes255 heads, 63 sectors/track, 6527 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/VolGroup-lv_swap: 2113 MB, 2113929216 bytes255 heads, 63 sectors/track, 257 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/VolGroup-lv_home: 158.4 GB, 158418862080 bytes255 heads, 63 sectors/track, 19259 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000#-------------- 第二块硬盘 /dev/xvdb --------------------------Disk /dev/xvdb: 53.7 GB, 53687091200 bytes255 heads, 63 sectors/track, 6527 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000#-------------- 第三块硬盘 /dev/xvdc --------------------------Disk /dev/xvdc: 63.4 GB, 63350767616 bytes255 heads, 63 sectors/track, 7701 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000

?

2:硬盘分区

上面很清楚,是三块硬盘。

第一块已经在使用了,第二,第三块还为分区。那我们下面来格式化(格式化命令: fdisk 挂载盘)

?

?

#fdisk /dev/xvdb 格式化这块硬盘[root@localhost ~]# fdisk /dev/xvdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0x40a24247.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').# fdisk 如果你不熟悉的话,就输入m,就是menu的意思。所有的fdisk命令尽收眼底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)#主分区我已经有了,这里我就做逻辑分区吧。 e#这里没有什么意思,就是分几个区,每个区大小事多少。我这里就一个区,大小全部。具体操作见下面Partition number (1-4): 1First cylinder (1-6527, default 1): Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527): Using default value 6527#其实到这里,分区并没完成。 需要写入。 这里w 对照上面的菜单看Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.# 不用说了,到此已经创建完成了。

?

比较一下分区前后的硬盘信息 还是用fdisk -l

?

#这里是分区前的信息Disk /dev/xvdc: 63.4 GB, 63350767616 bytes255 heads, 63 sectors/track, 7701 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000

?

?

?

# 这里是分区后的信息Disk /dev/xvdb: 53.7 GB, 53687091200 bytes255 heads, 63 sectors/track, 6527 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x40a24247    Device Boot      Start         End      Blocks   Id  System/dev/xvdb1               1        6527    52428096    5  Extended

?

?

3:格式化分区

输入fdisk -l 查看以前的新创建的分区。 然后用mkfs -t ext3 -c [新分区] 进行格式化。

#查询硬盘上的分区Disk /dev/xvdc: 63.4 GB, 63350767616 bytes255 heads, 63 sectors/track, 7701 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x210fa633    Device Boot      Start         End      Blocks   Id  System/dev/xvdc1               1        7701    61858251   83  Linux

?

格式化/dev/xvdc1

[root@localhost ~]# mkfs -t ext3 -c /dev/xvdc1mke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks3866624 inodes, 15464562 blocks773228 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=4294967296472 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, 11239424Checking for bad blocks (read-only test): done                                Writing inode tables: done                            Creating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 25 mounts or180 days, whichever comes first.  Use tune2fs -c or -i to override.

?

4:挂载

我们现在来看一下硬盘的目录信息 df -h

[root@localhost ~]# df -hFilesystem            Size  Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root                       50G  1.1G   46G   3% /tmpfs                 497M     0  497M   0% /dev/shm/dev/xvda1            485M   32M  428M   7% /boot/dev/mapper/VolGroup-lv_home                      146G  3.4G  135G   3% /home

?

挂载:

将/dev/xvdc1 挂载到 /disk2 下[root@localhost /]# mkdir /disk2[root@localhost /]# mount /dev/xvdc1 /disk2

?

我们现在再来看一下硬盘的目录信息

[root@localhost /]# df -hFilesystem            Size  Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root                       50G  1.1G   46G   3% /tmpfs                 497M     0  497M   0% /dev/shm/dev/xvda1            485M   32M  428M   7% /boot/dev/mapper/VolGroup-lv_home                      146G  3.4G  135G   3% /home/dev/xvdc1             59G  180M   55G   1% /disk2

?

到此挂载就完成了。如果你重启机器以后,你会发现。disk2的目录又没了。不得重新挂载一次;当然这个肯定不是长久的解决方法

[root@localhost /]# vi /etc/fstab增加一行:/dev/xvdc1/disk2ext3defaults0 0

?

现在才真正的完成了。

?

?

?

?

?

?

?

?

?

?

读书人网 >UNIXLINUX

热点推荐