Chinaunix首页 | 论坛 | 博客
  • 博客访问: 424238
  • 博文数量: 58
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 623
  • 用 户 组: 普通用户
  • 注册时间: 2013-04-26 18:48
个人简介

在生存面前,那纯洁的理想,原来是那么脆弱不堪!

文章分类

全部博文(58)

文章存档

2022年(1)

2021年(1)

2019年(3)

2018年(6)

2017年(6)

2016年(14)

2015年(10)

2014年(16)

2013年(1)

我的朋友

分类: 系统运维

2014-12-12 17:26:54

1,首先查看实际磁盘个数和大小。
    1.1,#fdisk -l         (如果是虚拟机,则是# ls /dev/vd*)

点击(此处)折叠或打开

  1. [root@nagios ~]# fdisk -l | grep sd
    Disk /dev/sdb: 300.0 GB, 300000000000 bytes
    /dev/sdb1               1       26109   209720511   83  Linux
    /dev/sdb2           26110       36472    83240797+  83  Linux
    Disk /dev/sda: 300.0 GB, 300000000000 bytes
    /dev/sda1   *           1          64      512000   83  Linux
    /dev/sda2              64       36473   292455424   8e  Linux LVM
    其中sda1,和sda2 不死磁盘,而是sda磁盘的分区。
    所以看出,有两个磁盘,分别是300G和500G。

2,使用fdisk进行分区。
    fdisk 加"磁盘路劲"参数 ,进去根据提示,敲m显示帮助信息。

点击(此处)折叠或打开

  1. [root@nagios ~]# fdisk  /dev/sda

    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').
  2. 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)
           其中重要的几个,p输出磁盘分区表,n添加磁盘分区,d删除磁盘分区,t改变分区格式,l列出每种分区格式的ID值。
3,举例创建一个linux分区。

点击(此处)折叠或打开

  1. [root@localhost ~]# fdisk /dev/vdb
  2. Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
  3. Building a new DOS disklabel with disk identifier 0xc8542e4a.
  4. Changes will remain in memory only, until you decide to write them.
  5. After that, of course, the previous content won't be recoverable.

  6. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

  7. WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
  8.          switch off the mode (command 'c') and change display units to
  9.          sectors (command 'u').

  10. Command (m for help): p

  11. Disk /dev/vdb: 322.1 GB, 322122547200 bytes
  12. 16 heads, 63 sectors/track, 624152 cylinders
  13. Units = cylinders of 1008 * 512 = 516096 bytes
  14. Sector size (logical/physical): 512 bytes / 512 bytes
  15. I/O size (minimum/optimal): 512 bytes / 512 bytes
  16. Disk identifier: 0xc8542e4a

  17.    Device Boot Start End Blocks Id System

  18. Command (m for help): n
  19. Command action
  20.    e extended
  21.    p primary partition (1-4)
  22. p
  23. Partition number (1-4): 1
  24. First cylinder (1-624152, default 1):
  25. Using default value 1
  26. Last cylinder, +cylinders or +size{K,M,G} (1-624152, default 624152): +100G

  27. Command (m for help): p

  28. Disk /dev/vdb: 322.1 GB, 322122547200 bytes
  29. 16 heads, 63 sectors/track, 624152 cylinders
  30. Units = cylinders of 1008 * 512 = 516096 bytes
  31. Sector size (logical/physical): 512 bytes / 512 bytes
  32. I/O size (minimum/optimal): 512 bytes / 512 bytes
  33. Disk identifier: 0xc8542e4a

  34.    Device Boot Start End Blocks Id System
  35. /dev/vdb1 1 208052 104858176+ 83 Linux

  36. Command (m for help): w
  37. The partition table has been

  38. Calling ioctl() to re-read partition table.
  39. Syncing disks.
  40. [root@localhost ~]#
  第13行: 输入p,显示所有分区,看到还没有建立分区。
  第24行: 输入n,新建分区。
  第28行:要求选择主分区还是扩展分区,这里选择主分区。
  第31行:要求输入分区号,这里填1,就会创建/dev/sda1分区。
  第30行:输入开始扇区,如果新建默认是1,直接回车。
  第31行: 输入结束扇区,或者输入大小,这里输入大小 “+100G”,注意必须有"+"符号。
  第46行: 将分区信息写入磁盘,分区信息保存退出。

4,查看分区,可以看到多了/dev/sdb1分区:

点击(此处)折叠或打开

  1. [root@localhost ~]# fdisk -l /dev/sdb

  2. Disk /dev/sdb: 322.1 GB, 322122547200 bytes
  3. 16 heads, 63 sectors/track, 624152 cylinders
  4. Units = cylinders of 1008 * 512 = 516096 bytes
  5. Sector size (logical/physical): 512 bytes / 512 bytes
  6. I/O size (minimum/optimal): 512 bytes / 512 bytes
  7. Disk identifier: 0xc8542e4a

  8.    Device Boot Start End Blocks Id System
  9. /dev/sdb1 1 208052 104858176+ 83 Linux

5,格式化分区:
    利用划好的分区,可以直接进行文件系统格式化。

点击(此处)折叠或打开

  1. [root@localhost ~]# mkfs.ext4 /dev/vdb1
  2. mke2fs 1.41.12 (17-May-2010)
  3. warning: 144 blocks unused.
   格式化时间长短,取决于,磁盘分区大小。

6,挂载分区:
     将/dev/vdb1分区挂载在/mnt目录下。要确保/mnt/目录为空,或者挂载在一个实际为空的其他目录。

点击(此处)折叠或打开

  1. [root@localhost ~]# mount /dev/vdb1 /mnt/
  2. [root@localhost ~]# cd /mnt/
  3. [root@localhost mnt]# ls
  4. lost+found
  5. [root@localhost mnt]#

这里就完成了,磁盘的分区,格式化,和挂载,此时对挂载的目录的操作就相当于对磁盘的操作。
阅读(1324) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~