在创建虚拟机的时候明明分配了50GB的硬盘空间!但是在使用df -h命令查看的时候

[root@centos-fuwenchao ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             9.7G  4.6G  4.6G  51% /
tmpfs                 495M   37M  459M   8% /dev/shm

还以为是自己创建的时候数字写错了,发现有个fdisk命令

[root@centos-fuwenchao ~]# fdisk -l
Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x0004b51e
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        1275    10240000   83  Linux
/dev/sda2            1275        1536     2095104   82  Linux swap / Solaris
/dev/sda3            1536        6528    40092672   83  Linux

原来是系统启动的时候没有把磁盘挂载上去

现学习下fdisk的具体用法:

一、在 console 上输入 fdisk -l /dev/sda ,观察硬盘之实体使用情形。

[root@centos-fuwenchao ~]#  fdisk -l /dev/sda
Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x0004b51e
#分区序列 引导       开始           终止 容量   分区类型ID 分区类型
 Device   Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        1275    10240000   83  Linux
/dev/sda2            1275        1536     2095104   82  Linux swap / Solaris
/dev/sda3            1536        6528    40092672   83  Linux

关于fdisk -l 一些数值的说明

Disk /dev/hda: 53.7 GB, 80026361856 bytes

255 heads, 63 sectors/track, 6527 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

这个硬盘是53.7G的,有255个磁面;63个扇区;6527个磁柱;每个 cylinder(磁柱)的容量是 8225280 bytes=8225.280 K(约为)=8.225280M(约为);

硬盘分区的表示:在Linux 是通过hd*x 或 sd*x 表示的,其中 * 表示的是a、b、c …… …… x表示的数字 1、2、3 …… …… hd大多是IDE硬盘;sd大多是SCSI或移动存储;

引导(Boot):表示引导分区,在上面的例子中 hda1 是引导分区;

Start (开始):表示的一个分区从X cylinder(磁柱)开始;

End (结束):表示一个分区到 Y cylinder(磁柱)结束;

id和System 表示的是一个意思,id看起来不太直观,我们要在fdisk 一个分区时,通过指定id来确认分区类型;比如 7表示的就NTFS 分区;这个在fdisk 中要通过t功能来指定。下面的部份会提到;

Blocks(容量):这是我翻译的,其实不准确,表示的意思的确是容量的意思,其单位是K;一个分区容量的值是由下面的公式而来的;

Blocks = (相应分区End数值 - 相应分区Start数值)x 单位cylinder(磁柱)的容量

所以我们算一下 hda1的 Blocks 的大小 :

hda1 Blocks=(765-1)x8225.280=6284113.92 K = 6284.113.92M

注:换算单位以硬盘厂家提供的10进位算起,如果以操作系统二进制来算,这个分区容量应该更少一些,得出的这个值和我们通过 fdisk -l 看到的 /dev/hda1的值是大体相当的,因为换算方法不一样,所以也不可能尽可能的精确;再加上分区时的一点损失之类,有时或大或小是存在的;

我们查看分区大小或者文件的时候,还是用十进制来计算比较直观;推算办法是 byte 向前推小数点三位就是K ,K单位的值向前推小数点三位就是M,M向前推小数点三位就是G…… …… 一般也差不了多少;这么算就行;



fdisk 对硬盘及分区的操作,进入fdisk 对硬盘操作阶段,以后再说!

续集

因生产需要,公司增加了第三块磁盘,先对他进行分区等操作,详情如下

公司的第三块盘如下所示

Last login: Thu Nov 28 13:12:21 2013 from 182.151.205.254
[root@pacteralinux ~]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1             29954008  17765060  10667336  63% /
tmpfs                   794380         0    794380   0% /dev/shm
/dev/sdb1             72246600   4005880  64570808   6% /mnt/resource
[root@pacteralinux ~]# fdisk -l
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x00072ca8
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        3789    30432256   83  Linux
/dev/sda2            3789        3917     1024000   82  Linux swap / Solaris
Disk /dev/sdb: 75.2 GB, 75161927680 bytes
255 heads, 63 sectors/track, 9137 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: 0xd1b75611
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1        9138    73398272   83  Linux
Disk /dev/sdc: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 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

开始分区

1:进入分区状态

[root@pacteralinux ~]# fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x05df0a32.
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): m

2:m寻求帮

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)

3:p显示磁盘分区情形

Command (m for help): p
Disk /dev/sdc: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 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: 0x05df0a32
   Device Boot      Start         End      Blocks   Id  System

因磁盘还未开始分区,显示为空

4:n增加第一个新的分区

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-65270, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-65270, default 65270): 48000
  • 输入 e 硬盘为[延伸]分割区(extend)。

  • 输入 p 硬盘为[主要]分割区(primary)。

5:p显示分区情形

Command (m for help): p
Disk /dev/sdc: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 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: 0x05df0a32
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1       48000   385559968+  83  Linux

6:增加第二个分区

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
Partition 1 is already defined.  Delete it before re-adding it.
Command (m for help): 2
2: unknown command
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): 2
First cylinder (48001-65270, default 48001):
Using default value 48001
Last cylinder, +cylinders or +size{K,M,G} (48001-65270, default 65270):
Using default value 65270
Command (m for help): p
Disk /dev/sdc: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 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: 0x05df0a32
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1       48000   385559968+  83  Linux
/dev/sdc2           48001       65270   138721275   83  Linux

7:保存退出

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

8:查看分区情形

Syncing disks.
[root@pacteralinux ~]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1             29954008  17765068  10667328  63% /
tmpfs                   794380         0    794380   0% /dev/shm
/dev/sdb1             72246600   4005880  64570808   6% /mnt/resource
[root@pacteralinux ~]# fdisk -l
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x00072ca8
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        3789    30432256   83  Linux
/dev/sda2            3789        3917     1024000   82  Linux swap / Solaris
Disk /dev/sdb: 75.2 GB, 75161927680 bytes
255 heads, 63 sectors/track, 9137 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: 0xd1b75611
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1        9138    73398272   83  Linux
Disk /dev/sdc: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 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: 0x05df0a32
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1       48000   385559968+  83  Linux
/dev/sdc2           48001       65270   138721275   83  Linux

9:格式化第一个分区,约半个小时

[root@pacteralinux ~]# mkfs.ext4 /dev/sdc1
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
24100864 inodes, 9638××× blocks
4819499 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
2942 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, 78675968
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.

10:查看分区情形

Disk /dev/sdc: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 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: 0x05df0a32
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1       48000   385559968+  83  Linux
/dev/sdc2           48001       65270   138721275   83  Linux

11:格式化第二个分区

[root@pacteralinux ~]# mkfs.ext3 /dev/sdc2
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
8675328 inodes, 34680318 blocks
1734015 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
1059 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
Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

12:查看分区

Disk /dev/sdc: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 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: 0x05df0a32
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1       48000   385559968+  83  Linux
/dev/sdc2           48001       65270   138721275   83  Linux

13:挂载分区

[root@pacteralinux resource]# pwd
/mnt/resource
[root@pacteralinux resource]# mkdir mysqldataper
[root@pacteralinux resource]# mkdir sdc3mnt
[root@pacteralinux resource]# mount /dev/sdc1 mysqldat
mysqldataper/ mysqldate/   
[root@pacteralinux resource]# mount /dev/sdc1 mysqldataper/
[root@pacteralinux resource]# mount /dev/sdc2 sdc3mnt/

14:查看挂在情况

[root@pacteralinux resource]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              29G   17G   11G  63% /
tmpfs                 776M     0  776M   0% /dev/shm
/dev/sdb1              69G  3.9G   62G   6% /mnt/resource
/dev/sdc1             362G  195M  344G   1% /mnt/resource/mysqldataper
/dev/sdc2             131G  188M  124G   1% /mnt/resource/sdc3mnt

注意

  • 硬盘总容量=主分区(包括扩展分区)总容量

  • 扩展分区容量=逻辑分区总容量

  • 在扩展分区上建立逻辑分区
      

参考:http://www.liusuping.com/ubuntu-linux/linux-fdisk-disk.html