Blob


1 version=pmwiki-2.3.20 ordered=1 urlencoded=1
2 agent=w3m/0.5.3+git20230121
3 author=jrmu
4 charset=UTF-8
5 csum=
6 ctime=1712817194
7 host=104.167.242.140
8 name=Swapctl.Usage
9 rev=5
10 targets=Fdisk.Usage,Disklabel.Usage,Openbsd.Fstab,Dd.Usage
11 text=(:title swapctl(8) -- System swap management tool:)%0a%0a[[https://man.openbsd.org/swapctl|swapctl(8)]] helps manage system swap.%0a%0aTo list swap devices and files:%0a%0a[@%0a$ swapctl -l%0aDevice 512-blocks Used Avail Capacity Priority%0a/dev/sd0b 2109020 0 2109020 0%25 0%0a@]%0a%0aHere we see partition @@/dev/sd0b@@, the swap partition, with 2109020 blocks (or 1GB of swap). 0%25 capacity is used, meaning all 1GB of swap is available.%0a%0aOn a system with heavy memory usage, all swap space may be used. In the%0afollowing example, we will switch to a busier system:%0a%0a[@%0a$ swapctl -l%0aDevice 512-blocks Used Avail Capacity Priority%0a/dev/sd1b 2109020 2106160 2860 100%25 0%0a@]%0a%0a!! Adding Swap Partition%0a%0aTo add a new swap partition, you need some free space to create a new%0adisklabel partition.%0a%0aIn this example, we've just prepared a new disk @@sd1@@ with%0a[[fdisk/usage|fdisk]] and have 20G of free space:%0a%0a[@%0a# disklabel -E sd1%0aLabel editor (enter '?' for help at any prompt)%0asd1> p g%0aOpenBSD area: 64-41943040; size: 20.0G; free: 20.0G%0a# size offset fstype [fsize bsize cpg]%0a c: 20.0G 0 unused %0a@]%0a%0aWe add a new swap partition @@sd1b@@ since by convention, swap%0apartitions use the letter @@b@@:%0a%0a[@%0asd1> a b%0aoffset: [64] %0asize: [41942976] 1G%0aFS type: [swap] %0asd1*> p g%0aOpenBSD area: 64-41943040; size: 20.0G; free: 19.0G%0a# size offset fstype [fsize bsize cpg]%0a b: 1.0G 64 swap %0a c: 20.0G 0 unused %0asd1*> w%0asd1> q%0aNo label changes.%0a@]%0a%0a'''NOTE''': You can add a swap partition even if another swap partition%0aalready exists, so long as you have the free space and you specify the%0aFS type is @@swap@@. It is not necessary to have a new disk with only a%0asingle swap partition.%0a%0aNext, we find the DUID on the [[disklabel/usage|disklabel]]:%0a%0a[@%0a# disklabel sd1 | grep duid%0aduid: 23e250c235b4218f%0a@]%0a%0aThen we add this line at the bottom of [[openbsd/fstab|/etc/fstab]]:%0a%0a[@%0a23e250c235b4218f.b none swap sw%0a@]%0a%0aThis says that partition @@b@@ of the device with duid @@23e250c235b4218f@@ has a mount point of @@none@@, and is of type @@swap@@.%0a%0aFinally we call swapctl to add this new swap device:%0a%0a[@%0a# swapctl -A %0aswapctl: adding 23e250c235b4218f.b as swap device at priority 0%0a@]%0a%0aWe can confirm its presence:%0a%0a[@%0a# swapctl -l%0aDevice 512-blocks Used Avail Capacity Priority%0a/dev/sd0b 2109020 0 2109020 0%25 0%0a/dev/sd1b 2104451 0 2104451 0%25 0%0aTotal 4213471 0 4213471 0%25%0a@]%0a%0a!! Using Swap Files%0a%0aIf you lack free space on disk to create a swap partition, you can also%0ause a swap file.%0a%0a'''NOTE''': A dedicated swap partition is preferred where possible.%0a%0aFirst, we create the swap file in an existing partition with plenty of%0afree space. We will use [[dd/usage|dd]]. Replace @@count=1024@@ with%0athe size of the swapfile you need in megabytes:%0a%0a[@%0a# dd if=/dev/zero of=/home/user/swapfile bs=1m count=1024%0a1024+0 records in%0a1024+0 records out%0a1073741824 bytes transferred in 14.092 secs (76192760 bytes/sec)%0a@]%0a%0aThen provide the path to swapctl:%0a%0a[@%0a# swapctl -a /home/user/swapfile%0a@]%0a%0aYou can verify the swap file is now being used:%0a%0a[@%0a# swapctl -l%0aDevice 512-blocks Used Avail Capacity Priority%0a/dev/sd0b 2109020 0 2109020 0%25 0%0a/home/user/swapfile 2097152 0 2097152 0%25 0%0aTotal 6310623 0 6310623 0%25%0a@]%0a
12 time=1712819184
13 title=swapctl(8) -- System swap management tool
14 author:1712819184=jrmu
15 diff:1712819184:1712818403:=94,127d93%0a%3c @]%0a%3c %0a%3c !! Using Swap Files%0a%3c %0a%3c If you lack free space on disk to create a swap partition, you can also%0a%3c use a swap file.%0a%3c %0a%3c '''NOTE''': A dedicated swap partition is preferred where possible.%0a%3c %0a%3c First, we create the swap file in an existing partition with plenty of%0a%3c free space. We will use [[dd/usage|dd]]. Replace @@count=1024@@ with%0a%3c the size of the swapfile you need in megabytes:%0a%3c %0a%3c [@%0a%3c # dd if=/dev/zero of=/home/user/swapfile bs=1m count=1024%0a%3c 1024+0 records in%0a%3c 1024+0 records out%0a%3c 1073741824 bytes transferred in 14.092 secs (76192760 bytes/sec)%0a%3c @]%0a%3c %0a%3c Then provide the path to swapctl:%0a%3c %0a%3c [@%0a%3c # swapctl -a /home/user/swapfile%0a%3c @]%0a%3c %0a%3c You can verify the swap file is now being used:%0a%3c %0a%3c [@%0a%3c # swapctl -l%0a%3c Device 512-blocks Used Avail Capacity Priority%0a%3c /dev/sd0b 2109020 0 2109020 0%25 0%0a%3c /home/user/swapfile 2097152 0 2097152 0%25 0%0a%3c Total 6310623 0 6310623 0%25%0a
16 host:1712819184=104.167.242.140
17 author:1712818403=jrmu
18 diff:1712818403:1712818256:=71,72c71,73%0a%3c Then we add this line at the bottom of [[openbsd/fstab|/etc/fstab]]:%0a%3c %0a---%0a> Then add the swap partition at the bottom of%0a> [[openbsd/fstab|/etc/fstab]]:%0a> %0a73a75,83%0a> # cat /etc/fstab %0a> 3e9c52c837229b9f.b none swap sw%0a> 3e9c52c837229b9f.a / ffs rw 1 1%0a> 3e9c52c837229b9f.k /home ffs rw,nodev,nosuid 1 2%0a> 3e9c52c837229b9f.d /tmp ffs rw,nodev,nosuid 1 2%0a> 3e9c52c837229b9f.f /usr ffs rw,nodev 1 2%0a> 3e9c52c837229b9f.g /usr/X11R6 ffs rw,nodev 1 2%0a> 3e9c52c837229b9f.h /usr/local ffs rw,wxallowed,nodev 1 2%0a> 3e9c52c837229b9f.e /var ffs rw,nodev,nosuid 1 2%0a76,77d85%0a%3c %0a%3c This says that partition @@b@@ of the device with duid @@23e250c235b4218f@@ has a mount point of @@none@@, and is of type @@swap@@.%0a
19 host:1712818403=104.167.242.140
20 author:1712818256=jrmu
21 diff:1712818256:1712818054:=85,101d84%0a%3c @]%0a%3c %0a%3c Finally we call swapctl to add this new swap device:%0a%3c %0a%3c [@%0a%3c # swapctl -A %0a%3c swapctl: adding 23e250c235b4218f.b as swap device at priority 0%0a%3c @]%0a%3c %0a%3c We can confirm its presence:%0a%3c %0a%3c [@%0a%3c # swapctl -l%0a%3c Device 512-blocks Used Avail Capacity Priority%0a%3c /dev/sd0b 2109020 0 2109020 0%25 0%0a%3c /dev/sd1b 2104451 0 2104451 0%25 0%0a%3c Total 4213471 0 4213471 0%25%0a
22 host:1712818256=104.167.242.140
23 author:1712818054=jrmu
24 diff:1712818054:1712817194:=24,85d23%0a%3c !! Adding Swap Partition%0a%3c %0a%3c To add a new swap partition, you need some free space to create a new%0a%3c disklabel partition.%0a%3c %0a%3c In this example, we've just prepared a new disk @@sd1@@ with%0a%3c [[fdisk/usage|fdisk]] and have 20G of free space:%0a%3c %0a%3c [@%0a%3c # disklabel -E sd1%0a%3c Label editor (enter '?' for help at any prompt)%0a%3c sd1> p g%0a%3c OpenBSD area: 64-41943040; size: 20.0G; free: 20.0G%0a%3c # size offset fstype [fsize bsize cpg]%0a%3c c: 20.0G 0 unused %0a%3c @]%0a%3c %0a%3c We add a new swap partition @@sd1b@@ since by convention, swap%0a%3c partitions use the letter @@b@@:%0a%3c %0a%3c [@%0a%3c sd1> a b%0a%3c offset: [64] %0a%3c size: [41942976] 1G%0a%3c FS type: [swap] %0a%3c sd1*> p g%0a%3c OpenBSD area: 64-41943040; size: 20.0G; free: 19.0G%0a%3c # size offset fstype [fsize bsize cpg]%0a%3c b: 1.0G 64 swap %0a%3c c: 20.0G 0 unused %0a%3c sd1*> w%0a%3c sd1> q%0a%3c No label changes.%0a%3c @]%0a%3c %0a%3c '''NOTE''': You can add a swap partition even if another swap partition%0a%3c already exists, so long as you have the free space and you specify the%0a%3c FS type is @@swap@@. It is not necessary to have a new disk with only a%0a%3c single swap partition.%0a%3c %0a%3c Next, we find the DUID on the [[disklabel/usage|disklabel]]:%0a%3c %0a%3c [@%0a%3c # disklabel sd1 | grep duid%0a%3c duid: 23e250c235b4218f%0a%3c @]%0a%3c %0a%3c Then add the swap partition at the bottom of%0a%3c [[openbsd/fstab|/etc/fstab]]:%0a%3c %0a%3c [@%0a%3c # cat /etc/fstab %0a%3c 3e9c52c837229b9f.b none swap sw%0a%3c 3e9c52c837229b9f.a / ffs rw 1 1%0a%3c 3e9c52c837229b9f.k /home ffs rw,nodev,nosuid 1 2%0a%3c 3e9c52c837229b9f.d /tmp ffs rw,nodev,nosuid 1 2%0a%3c 3e9c52c837229b9f.f /usr ffs rw,nodev 1 2%0a%3c 3e9c52c837229b9f.g /usr/X11R6 ffs rw,nodev 1 2%0a%3c 3e9c52c837229b9f.h /usr/local ffs rw,wxallowed,nodev 1 2%0a%3c 3e9c52c837229b9f.e /var ffs rw,nodev,nosuid 1 2%0a%3c 23e250c235b4218f.b none swap sw%0a%3c @]%0a
25 host:1712818054=104.167.242.140
26 author:1712817194=jrmu
27 diff:1712817194:1712817194:=1,23d0%0a%3c (:title swapctl(8) -- System swap management tool:)%0a%3c %0a%3c [[https://man.openbsd.org/swapctl|swapctl(8)]] helps manage system swap.%0a%3c %0a%3c To list swap devices and files:%0a%3c %0a%3c [@%0a%3c $ swapctl -l%0a%3c Device 512-blocks Used Avail Capacity Priority%0a%3c /dev/sd0b 2109020 0 2109020 0%25 0%0a%3c @]%0a%3c %0a%3c Here we see partition @@/dev/sd0b@@, the swap partition, with 2109020 blocks (or 1GB of swap). 0%25 capacity is used, meaning all 1GB of swap is available.%0a%3c %0a%3c On a system with heavy memory usage, all swap space may be used. In the%0a%3c following example, we will switch to a busier system:%0a%3c %0a%3c [@%0a%3c $ swapctl -l%0a%3c Device 512-blocks Used Avail Capacity Priority%0a%3c /dev/sd1b 2109020 2106160 2860 100%25 0%0a%3c @]%0a%3c %0a
28 host:1712817194=104.167.242.140