1

Is swap a partition, but not a file system? Is that the reason why df doesn't show it?

Is there a command which can list all the partitions (whether they hold file systems or not)?

Thanks.

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            3.9G     0  3.9G   0% /dev
tmpfs           788M  1.5M  786M   1% /run
/dev/sda3       260G   17G  231G   7% /
tmpfs           3.9G  403M  3.5G  11% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda4       550G  323G  200G  62% /home
tmpfs           788M   56K  788M   1% /run/user/1000
tmpfs           788M  4.0K  788M   1% /run/user/1001

$ cat /proc/swaps 
Filename                Type        Size    Used    Priority
/dev/sda2                               partition   15625212    12653864    -2
ctrl-alt-delor
  • 27,473
  • 9
  • 58
  • 102
Tim
  • 98,580
  • 191
  • 570
  • 977
  • Yes. `sfdisk -d /whatever/file/or/device`. –  Feb 17 '19 at 15:50
  • Also, you can use Gparted, a gret application pre-installed in meny Debian distributions. – Z E Nir Feb 17 '19 at 15:55
  • @mosvy Thanks. I guess `sfdisk -l` is more appropriate – Tim Feb 17 '19 at 15:55
  • 1
    @mosvy that is a good answer. It is short, but such is the nature of this question. Please copy to an answer, so we can ✓ you. – ctrl-alt-delor Feb 17 '19 at 15:57
  • 1
    @ctrl-alt-delor I don't think this question hasn't been answered before. –  Feb 17 '19 at 15:59
  • `parted -l` seems also can do the same – Tim Feb 17 '19 at 16:06
  • 1
    `lsblk`: https://unix.stackexchange.com/q/157154/80886 – jimmij Feb 17 '19 at 16:20
  • you may want to check out **kernel.org** and the somewhat *official* description of SWAP, specifically **swap management** and **describing the swap area** https://www.kernel.org/doc/gorman/html/understand/index.html – ron Feb 17 '19 at 23:20

2 Answers2

3

Is swap a partition, but not a file system?

The common way to set up a swap space is indeed to use a partition (like your /dev/sda2). The swap space has some identifiers, so it can be identified as such, but it's not a file system: it doesn't contain files.

You could of course also put swap space on a file on some regular filesystem.

(I wouldn't say swap is a partition, but in can lie on a partition.)

Is that the reason why df doesn't show it?

That, and the fact that df only shows mounted filesystems (visible to the process).

Is there a command which can list all the partitions (whether they hold file systems or not)?

All disk partitioning tools; fdisk, sfdisk, GParted, what have you. They might or might not show what's inside the partitions though. (/proc/partitions also contains a list, but not much details.)

ilkkachu
  • 133,243
  • 15
  • 236
  • 397
3

Is swap a partition, but not a file system?

A swap File / Partition is just a big BLOB where the kernel stores Randomly Accessible Memory. Although RAM can contain files, it needs a RAM DISK conversion to do that.

Is that the reason why df doesn't show it?

Yes, from the man page:

NAME
df - report file system disk space usage

Is there a command which can list all the partitions (whether they hold file systems or not)?

parted --list
Fabby
  • 5,836
  • 2
  • 22
  • 38