昨晚突然被学生问道这个问题,我当时并没有一个精确的答案,只是觉得应该是换算的方法不一样才会显示的不一样。今天仔细研究了一番终于得出了想要的答案:下面是两种不同的查看方式:
1. df -B 1Filesystem 1B-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root 18536591360 1466068992 16128901120 9% /
tmpfs 188743680 0 188743680 0% /dev/shm
/dev/sda1 507744256 32395264 449134592 7% /boot
2. fdisk -l /dev/sda
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x000c09e3
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM
df查看到的数据并不全,因为它并没有显示出swap的大小,那么swap如何查看呢?我们使用free即可
[root@localhost ~]# free -b
total used free shared buffers cached
Mem: 300740608 208289792 92450816 0 16146432 128188416
-/+ buffers/cache: 63954944 236785664
Swap: 2113921024 0 2113921024
最终得出df查看的磁盘大小为 18536591360+507744256+2113921024=21158256640
而fdisk -l 得到的结果为21474836480 bytes,
首先比较这两个数值,虽然是有部分差距的,但是差的也并不是很大了。那么我们再看看,这个差值到底是如何来的?
为了看的更加清楚,我单独又加了一块磁盘,分了几个分区,其中我们要关注的是这个/dev/sdb1
[root@localhost ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0xe99bb17a
Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
/dev/sdb2 133 394 2104515 83 Linux
/dev/sdb3 395 656 2104515 83 Linux
[root@localhost ~]# df -B1024
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root 18102140 1431708 15750880 9% /
tmpfs 184320 0 184320 0% /dev/shm
/dev/sda1 495844 31636 438608 7% /boot
/dev/sdb1 1043548 34072 956464 4% /mnt
仔细比较/dev/sdb1那一行,我们发现fdisk -l 查看到的/dev/sdb1 有1060258个块(每一个块大小为1024字节),而df查看到的/dev/sdb1块有1043548,看来还是有不少差距的。问题就在这里啦!
1. df -B 1Filesystem 1B-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root 18536591360 1466068992 16128901120 9% /
tmpfs 188743680 0 188743680 0% /dev/shm
/dev/sda1 507744256 32395264 449134592 7% /boot
2. fdisk -l /dev/sda
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x000c09e3
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM
df查看到的数据并不全,因为它并没有显示出swap的大小,那么swap如何查看呢?我们使用free即可
[root@localhost ~]# free -b
total used free shared buffers cached
Mem: 300740608 208289792 92450816 0 16146432 128188416
-/+ buffers/cache: 63954944 236785664
Swap: 2113921024 0 2113921024
最终得出df查看的磁盘大小为 18536591360+507744256+2113921024=21158256640
而fdisk -l 得到的结果为21474836480 bytes,
首先比较这两个数值,虽然是有部分差距的,但是差的也并不是很大了。那么我们再看看,这个差值到底是如何来的?
为了看的更加清楚,我单独又加了一块磁盘,分了几个分区,其中我们要关注的是这个/dev/sdb1
[root@localhost ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0xe99bb17a
Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
/dev/sdb2 133 394 2104515 83 Linux
/dev/sdb3 395 656 2104515 83 Linux
[root@localhost ~]# df -B1024
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root 18102140 1431708 15750880 9% /
tmpfs 184320 0 184320 0% /dev/shm
/dev/sda1 495844 31636 438608 7% /boot
/dev/sdb1 1043548 34072 956464 4% /mnt
仔细比较/dev/sdb1那一行,我们发现fdisk -l 查看到的/dev/sdb1 有1060258个块(每一个块大小为1024字节),而df查看到的/dev/sdb1块有1043548,看来还是有不少差距的。问题就在这里啦!
编辑回复