
我對交換磁碟分割的理解有問題。問題在於尺寸。我透過 fstab 建立大小為 2GB 的新分割區:
Command (m for help): n
Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-536870911, default 2048):
Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-536870911, default 536870911): +2G Partition 1 of type Linux and of size 2 GiB is set
分配後進行交換
mkswap /dev/sdc1
swapon /dev/sdc1
在 /etc/fstab 中,此 uuid 代表 /dev/sdc1
UUID=1ec60ea1-1ebe-420e-9bbc-bc75f25b4cb2 none swap sw 0 0
檢查交換大小後
>> free | gr
ep -i swap | awk '{print $2" / 1024 " }' | bc -l
2047.99609375000000000000
>> free -g
total used free shared buff/cache available
Mem: 15 0 15 0 0 15
Swap: 1 0 1
>> free -h
total used free shared buff/cache available
Mem: 15G 221M 15G 8.4M 299M 15G
Swap: 2.0G 0B 2.0G
問題是為什麼 kb 輸出不適合 2GB,以及我在哪裡丟失了該內存(如果我計算正確,我錯過了 4kb,它是為文件夾層次結構保留的嗎?)或者我在哪裡犯了錯誤?
環境:
>> fdisk -v
來自 util-linux 2.23.2 的 fdisk
>> free -V
free from procps-ng 3.3.10
>> cat /proc/swaps | awk '{print $3" / 1024 " }' | bc -l
2047.99609375000000000000
>> cat /etc/*-release
CentOS Linux release 7.3.1611 (Core)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
CentOS Linux release 7.3.1611 (Core)
我期望 KB 和 GB 大小與創建的分割區大小相同
答案1
(如果我計算正確的話,我錯過了 4kb,它是為資料夾層次結構保留的嗎?)
交換區不是檔案系統,也不包含檔案層次結構。然而,它們確實包含一個 4 kB 的「交換標頭」——這就是您每次運行mkswap
.
這交換區頭持有UUID;可用頁數; 「壞塊」列表;以及其他資訊(例如該區域目前是否用於保存休眠影像)。