1MKSWAP(8)                    System Administration                   MKSWAP(8)
2
3
4

NAME

6       mkswap - set up a Linux swap area
7

SYNOPSIS

9       mkswap [options] device [size]
10

DESCRIPTION

12       mkswap sets up a Linux swap area on a device or in a file.
13
14       The device argument will usually be a disk partition (something like
15       /dev/sdb7) but can also be a file. The Linux kernel does not look at
16       partition IDs, but many installation scripts will assume that
17       partitions of hex type 82 (LINUX_SWAP) are meant to be swap partitions.
18       (Warning: Solaris also uses this type. Be careful not to kill your
19       Solaris partitions.)
20
21       The size parameter is superfluous but retained for backwards
22       compatibility. (It specifies the desired size of the swap area in
23       1024-byte blocks. mkswap will use the entire partition or file if it is
24       omitted. Specifying it is unwise - a typo may destroy your disk.)
25
26       After creating the swap area, you need the swapon(8) command to start
27       using it. Usually swap areas are listed in /etc/fstab so that they can
28       be taken into use at boot time by a swapon -a command in some boot
29       script.
30

WARNING

32       The swap header does not touch the first block. A boot loader or disk
33       label can be there, but it is not a recommended setup. The recommended
34       setup is to use a separate partition for a Linux swap area.
35
36       mkswap, like many others mkfs-like utils, erases the first partition
37       block to make any previous filesystem invisible.
38
39       However, mkswap refuses to erase the first block on a device with a
40       disk label (SUN, BSD, ...).
41

OPTIONS

43       -c, --check
44           Check the device (if it is a block device) for bad blocks before
45           creating the swap area. If any bad blocks are found, the count is
46           printed.
47
48       -f, --force
49           Go ahead even if the command is stupid. This allows the creation of
50           a swap area larger than the file or partition it resides on.
51
52           Also, without this option, mkswap will refuse to erase the first
53           block on a device with a partition table.
54
55       -q, --quiet
56           Suppress output and warning messages.
57
58       -L, --label label
59           Specify a label for the device, to allow swapon(8) by label.
60
61       --lock[=mode]
62           Use exclusive BSD lock for device or file it operates. The optional
63           argument mode can be yes, no (or 1 and 0) or nonblock. If the mode
64           argument is omitted, it defaults to yes. This option overwrites
65           environment variable $LOCK_BLOCK_DEVICE. The default is not to use
66           any lock at all, but it’s recommended to avoid collisions with
67           systemd-udevd(8) or other tools.
68
69       -p, --pagesize size
70           Specify the page size (in bytes) to use. This option is usually
71           unnecessary; mkswap reads the size from the kernel.
72
73       -U, --uuid UUID
74           Specify the UUID to use. The default is to generate a UUID. The
75           format of the UUID is a series of hex digits separated by hyphens,
76           like this: "c1b9d5a2-f162-11cf-9ece-0020afc76f16". The UUID
77           parameter may also be one of the following:
78
79           clear
80               clear the filesystem UUID
81
82           random
83               generate a new randomly-generated UUID
84
85           time
86               generate a new time-based UUID
87
88       -v, --swapversion 1
89           Specify the swap-space version. (This option is currently
90           pointless, as the old -v 0 option has become obsolete and now only
91           -v 1 is supported. The kernel has not supported v0 swap-space
92           format since 2.5.22 (June 2002). The new version v1 is supported
93           since 2.1.117 (August 1998).)
94
95       --verbose
96           Verbose execution. With this option mkswap will output more details
97           about detected problems during swap area set up.
98
99       -h, --help
100           Display help text and exit.
101
102       -V, --version
103           Print version and exit.
104

ENVIRONMENT

106       LIBBLKID_DEBUG=all
107           enables libblkid debug output.
108
109       LOCK_BLOCK_DEVICE=<mode>
110           use exclusive BSD lock. The mode is "1" or "0". See --lock for more
111           details.
112

NOTES

114       The maximum useful size of a swap area depends on the architecture and
115       the kernel version.
116
117       The maximum number of the pages that is possible to address by swap
118       area header is 4294967295 (32-bit unsigned int). The remaining space on
119       the swap device is ignored.
120
121       Presently, Linux allows 32 swap areas. The areas in use can be seen in
122       the file /proc/swaps.
123
124       mkswap refuses areas smaller than 10 pages.
125
126       If you don’t know the page size that your machine uses, you can look it
127       up with getconf PAGESIZE.
128
129       To set up a swap file, it is necessary to create that file before
130       initializing it with mkswap, e.g. using a command like
131
132           # dd if=/dev/zero of=swapfile bs=1MiB count=$((8*1024))
133
134       to create 8GiB swapfile.
135
136       Please read notes from swapon(8) about the swap file use restrictions
137       (holes, preallocation and copy-on-write issues).
138

SEE ALSO

140       fdisk(8), swapon(8)
141

REPORTING BUGS

143       For bug reports, use the issue tracker at
144       https://github.com/util-linux/util-linux/issues.
145

AVAILABILITY

147       The mkswap command is part of the util-linux package which can be
148       downloaded from Linux Kernel Archive
149       <https://www.kernel.org/pub/linux/utils/util-linux/>.
150
151
152
153util-linux 2.38.1                 2022-05-11                         MKSWAP(8)
Impressum