{"id":1349,"date":"2022-05-21T22:46:20","date_gmt":"2022-05-21T13:46:20","guid":{"rendered":"https:\/\/www7390uo.sakura.ne.jp\/wordpress\/?p=1349"},"modified":"2022-07-17T08:50:20","modified_gmt":"2022-07-16T23:50:20","slug":"%e3%82%b9%e3%83%af%e3%83%83%e3%83%97%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%81%ae%e4%bd%9c%e6%88%90%e3%81%abfallocate%e3%81%af%e9%81%a9%e3%81%97%e3%81%a6%e3%81%84%e3%81%aa%e3%81%84","status":"publish","type":"post","link":"https:\/\/www7390uo.sakura.ne.jp\/wordpress\/archives\/1349","title":{"rendered":"\u30b9\u30ef\u30c3\u30d7\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210\u306bfallocate\u306f\u9069\u3057\u3066\u3044\u306a\u3044"},"content":{"rendered":"\n<ul class=\"wp-block-list\"><li>OS: Ubuntu 22.04<\/li><\/ul>\n\n\n\n<p><code>fallocate<\/code>\u30b3\u30de\u30f3\u30c9\u3067\u4ee5\u3063\u3066\u30b9\u30ef\u30c3\u30d7\u30d5\u30a1\u30a4\u30eb\u3092\u5ea6\u3005\u4f5c\u6210\u3057\u3066\u3044\u308b\u3002<code>dd<\/code>\u30b3\u30de\u30f3\u30c9\u3088\u308a\u3082\u77ed\u6642\u9593\u3067\u7247\u304c\u4ed8\u304f\u304b\u3089\u91cd\u5b9d\u3059\u308b\u306e\u3067\u3042\u308b\u3002\u7d42\u305e\u7279\u6bb5\u306e\u4e0d\u90fd\u5408\u306b\u3076\u3064\u304b\u3063\u305f\u8a66\u3057\u304c\u306a\u3044\u3051\u308c\u3069\u3082\u3001\u3069\u3046\u3084\u3089\u3053\u308c\u306f\u826f\u304f\u306a\u3044\u6c17\u914d\u3067\u3042\u308b\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>NOTES<\/p><p>Files with holes<\/p><p>The swap file implementation in the kernel expects to be able to write to the file directly, without the assistance of the filesystem. This is a problem on files with holes or on copy-on-write files on filesystems like Btrfs.<\/p><p>Commands like cp(1) or truncate(1) create files with holes. These files will be rejected by swapon. <\/p><p>Preallocated files created by fallocate(1) may be interpreted as files with holes too depending of the filesystem. Preallocated swap files are supported on XFS since Linux 4.18.<\/p><p>The most portable solution to create a swap file is to use dd(1) and \/dev\/zero.<\/p><cite>$ man 8 swapon<\/cite><\/blockquote>\n\n\n\n<p>\u30b9\u30ef\u30c3\u30d7\u30d5\u30a1\u30a4\u30eb\u306f\u30d5\u30a1\u30a4\u30eb\u30b7\u30b9\u30c6\u30e0\u306e\u52a9\u3051\u3092\u501f\u308a\u305a\u306b\u66f8\u304d\u8fbc\u3081\u308b\u60f3\u5b9a\u3067\u5b9f\u88c5\u3055\u308c\u3066\u3044\u308b\u3068\u3044\u3046\u3002\u3068\u3053\u308d\u304cfallocate\u3067\u4f5c\u6210\u3055\u308c\u305f\u30b9\u30d1\u30fc\u30b9\u30d5\u30a1\u30a4\u30eb\u306e\u53d6\u308a\u6271\u3044\u306f\u30d5\u30a1\u30a4\u30eb\u30b7\u30b9\u30c6\u30e0\u306e\u51fa\u756a\u3068\u306a\u308b\u304b\u3089\u30b9\u30ef\u30c3\u30d7\u30d5\u30a1\u30a4\u30eb\u306b\u9069\u3055\u306a\u3044\u3002\u3068\u3044\u3046\u610f\u5473\u3067\u3042\u308d\u3046\u3068\u304a\u3082\u3046\u3002\u7d50\u5c40\u306fdd\u304c\u826f\u3044\u3068\u3044\u3046\u3053\u3068\u3067\u3042\u3063\u305f\u3002<\/p>\n\n\n\n<p>dd\u3092\u7528\u3044\u30662GB\u306e\u30b9\u30ef\u30c3\u30d7\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b\u306a\u3089\u3053\u3046\u3044\u3046\u5177\u5408\u3067\u3042\u308b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo dd if=\/dev\/zero of=\/swapfile2gb bs=128K count=16384 status=progress\n$ sudo chmod 600 \/swapfile2gb\n$ sudo mkswap \/swapfile2gb\n\u30b9\u30ef\u30c3\u30d7\u7a7a\u9593\u30d0\u30fc\u30b8\u30e7\u30f3 1 \u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002\u30b5\u30a4\u30ba = 2 GiB (2147479552 \u30d0\u30a4\u30c8)\n\u30e9\u30d9\u30eb\u306f\u3042\u308a\u307e\u305b\u3093, UUID=962db686-3bf1-41e2-99f1-f90e214e0806\n\n$ sudo swapon \/swapfile2gb\n$ cat \/proc\/swaps \nFilename              Type        Size            Used        Priority\n\/swapfile2gb          file        2097148         0           -3<\/pre>\n\n\n\n<p>\u7ffb\u610f\u3057\u3066\u30b9\u30ef\u30c3\u30d7\u9818\u57df\u3068\u3057\u3066\u306e\u5f79\u5272\u3092\u53d6\u308a\u6d88\u3059\u5834\u5408\u306f<code>swapoff<\/code>\u30b3\u30de\u30f3\u30c9\u3092\u8d70\u3089\u305b\u308b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo swapoff \/swapfile2gb<\/pre>\n\n\n\n<p>OS\u518d\u8d77\u52d5\u5f8c\u3082\u5f15\u304d\u7d9a\u304d\u30b9\u30ef\u30c3\u30d7\u3092\u6709\u52b9\u306b\u3059\u308b\u306a\u3089<code>\/etc\/fstab<\/code>\u306b\u8a2d\u5b9a\u3092\u6295\u3058\u3066\u304a\u304f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo vi \/etc\/fstab \n\/swapfile2gb   none    swap    sw    0    0<\/pre>\n\n\n\n<h3 class=\"link\">\u53c2\u8003:<\/h3>\n<ul>\n <li><a href=\"https:\/\/askubuntu.com\/questions\/1017309\/fallocate-vs-dd-for-swapfile\">fallocate vs dd for swapfile?<\/a><\/li>\n <li><a href=\"https:\/\/wiki.archlinux.jp\/index.php\/%E3%82%B9%E3%83%AF%E3%83%83%E3%83%97\">\u30b9\u30ef\u30c3\u30d7 &#8211; ArchWiki<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>OS: Ubuntu 22.04 fallocate\u30b3\u30de\u30f3\u30c9\u3067\u4ee5\u3063\u3066\u30b9\u30ef\u30c3\u30d7\u30d5\u30a1\u30a4\u30eb\u3092\u5ea6\u3005\u4f5c\u6210\u3057\u3066\u3044\u308b\u3002dd\u30b3\u30de\u30f3\u30c9\u3088\u308a\u3082\u77ed\u6642\u9593\u3067\u7247\u304c\u4ed8\u304f\u304b\u3089\u91cd\u5b9d\u3059\u308b\u306e\u3067\u3042\u308b\u3002\u7d42\u305e\u7279\u6bb5\u306e\u4e0d\u90fd\u5408\u306b\u3076\u3064\u304b\u3063\u305f\u8a66\u3057\u304c\u306a\u3044\u3051\u308c\u3069\u3082\u3001\u3069\u3046\u3084\u3089\u3053\u308c\u306f\u826f\u304f\u306a\u3044\u6c17\u914d\u3067\u3042\u308b\u3002 NOTES Files with holes The swap file implementation in the kernel expects to b &#8230; <a title=\"\u30b9\u30ef\u30c3\u30d7\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210\u306bfallocate\u306f\u9069\u3057\u3066\u3044\u306a\u3044\" class=\"read-more\" href=\"https:\/\/www7390uo.sakura.ne.jp\/wordpress\/archives\/1349\" aria-label=\"\u30b9\u30ef\u30c3\u30d7\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210\u306bfallocate\u306f\u9069\u3057\u3066\u3044\u306a\u3044 \u306b\u3064\u3044\u3066\u3055\u3089\u306b\u8aad\u3080\">\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":1350,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[157],"tags":[228,167],"class_list":["post-1349","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-fallocate","tag-swap"],"views":3587,"_links":{"self":[{"href":"https:\/\/www7390uo.sakura.ne.jp\/wordpress\/wp-json\/wp\/v2\/posts\/1349","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www7390uo.sakura.ne.jp\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www7390uo.sakura.ne.jp\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www7390uo.sakura.ne.jp\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www7390uo.sakura.ne.jp\/wordpress\/wp-json\/wp\/v2\/comments?post=1349"}],"version-history":[{"count":0,"href":"https:\/\/www7390uo.sakura.ne.jp\/wordpress\/wp-json\/wp\/v2\/posts\/1349\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www7390uo.sakura.ne.jp\/wordpress\/wp-json\/wp\/v2\/media\/1350"}],"wp:attachment":[{"href":"https:\/\/www7390uo.sakura.ne.jp\/wordpress\/wp-json\/wp\/v2\/media?parent=1349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www7390uo.sakura.ne.jp\/wordpress\/wp-json\/wp\/v2\/categories?post=1349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www7390uo.sakura.ne.jp\/wordpress\/wp-json\/wp\/v2\/tags?post=1349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}