{"id":79938,"date":"2023-10-28T14:17:05","date_gmt":"2023-10-28T06:17:05","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=79938"},"modified":"2023-10-28T14:17:05","modified_gmt":"2023-10-28T06:17:05","slug":"linux-create-partition","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-create-partition.html","title":{"rendered":"Linux \u4e0a\u4ea4\u6362\u5206\u533a\u7684\u7b80\u5355\u64cd\u4f5c"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u7528\u6237\u53ef\u4ee5\u5728\u4efb\u4f55 Linux \u64cd\u4f5c\u7cfb\u7edf\u7684\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u6216\u8005\u662f\u5176\u5b83\u5fc5\u8981\u7684\u65f6\u5019\u521b\u5efa\u4ea4\u6362\u7a7a\u95f4\u3002\u5982\u679c\u4f60\u5728\u5b89\u88c5 Linux \u7684\u65f6\u5019\u5fd8\u8bb0\u4e86\u521b\u5efa\u6216\u662f\u4f60\u60f3\u8981\u518d\u589e\u52a0\u4ea4\u6362\u5206\u533a\u7684\u7a7a\u95f4\uff0c\u4f60\u968f\u65f6\u90fd\u53ef\u4ee5\u518d\u521b\u5efa\u6216\u589e\u52a0\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u6709\u65f6\u5019\u5728\u4f60\u5b89\u88c5\u540e\u6447\u5347\u7ea7 RAM \u7684\u65f6\u5019\u9700\u8981\u589e\u52a0\u4e00\u70b9\u4ea4\u6362\u5206\u533a\u7684\u7a7a\u95f4\uff0c\u6bd4\u5982\u4f60\u8981\u5c06\u4f60\u7684\u7cfb\u7edf\u7684 RAM \u4ece 1GB \u5347\u7ea7\u5230 2GB \u4f60\uff0c\u90a3\u4e48\u4f60\u5c31\u4e0d\u5f97\u4e0d\u5c06\u4f60\u7684\u4ea4\u6362\u5206\u533a\u7a7a\u95f4\u4e5f\u5347\u7ea7\u4e00\u4e0b\uff08\u4ece 2GB \u5230 4GB\uff09\uff0c\u8fd9\u662f\u56e0\u4e3a\u5b83\u4f7f\u7528\u7684\u5bb9\u91cf\u662f\u7269\u7406 RAM \u7684\u53cc\u500d\u5bb9\u91cf\u3002\uff08LCTT \u8bd1\u6ce8\uff1a\u5176\u5b9e\u8fd9\u91cc\u662f\u4e2a\u8bef\u533a\uff0c\u4ea4\u6362\u5206\u533a\u4e0d\u4e00\u5b9a\u975e\u5f97\u662f\u53cc\u500d\u7684\u7269\u7406\u5185\u5b58\u5bb9\u91cf\uff0c\u53ea\u662f\u60ef\u4f8b\u5982\u6b64\u3002\u4e8b\u5b9e\u4e0a\uff0c\u5982\u679c\u4f60\u7684\u7269\u7406\u5185\u5b58\u8db3\u591f\u7684\u8bdd\uff0c\u4f60\u5b8c\u5168\u53ef\u4ee5\u4e0d\u7528\u4ea4\u6362\u5206\u533a\u2014\u2014\u5728\u8fd9\u91cc\u7684\u60c5\u5f62\u4e0b\uff0c\u6216\u8bb8\u4f60\u589e\u52a0\u4e86\u7269\u7406\u5185\u5b58\uff0c\u5c31\u6ca1\u5fc5\u8981\u589e\u52a0\u4ea4\u6362\u5206\u533a\u5927\u5c0f\u4e86\u3002\uff09<\/p>\n

\u4ea4\u6362\u7a7a\u95f4\u662f\u5f53\u7269\u7406\u5185\u5b58\uff08RAM \u968f\u673a\u5b58\u53d6\u5b58\u50a8\u5668\uff09\u7684\u7528\u91cf\u5df2\u6ee1\u65f6\uff0c\u88ab\u4fdd\u7559\u7528\u4f5c\u865a\u62df\u5185\u5b58\u7684\u78c1\u76d8\u4e0a\u7684\u7a7a\u95f4\u3002 \u5982\u679c\u7cfb\u7edf\u5728 RAM \u6ee1\u8f7d\u65f6\u9700\u8981\u66f4\u591a\u7684\u5185\u5b58\u8d44\u6e90\uff0c\u5185\u5b58\u4e2d\u7684\u975e\u6d3b\u52a8\u9875\u9762\u5c06\u88ab\u79fb\u52a8\u5230\u4ea4\u6362\u7a7a\u95f4\uff0c\u8fd9\u6837\u53ef\u4ee5\u5e2e\u52a9\u7cfb\u7edf\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u66f4\u591a\u7684\u65f6\u95f4\uff0c\u4f46\u4e0d\u5e94\u8be5\u628a\u5b83\u5f53\u505a RAM \u7684\u6269\u5c55\u3002<\/p>\n

\u5efa\u8bae\u4f60\u521b\u5efa\u4e00\u4e2a\u4e13\u7528\u7684\u4ea4\u6362\u5206\u533a\uff0c\u4f46\u662f\u5982\u679c\u4f60\u6ca1\u6709\u53ef\u7528\u7684\u5206\u533a\uff0c\u90a3\u4e48\u53ef\u4ee5\u4f7f\u7528\u4ea4\u6362\u6587\u4ef6\uff0c\u6216\u4ea4\u6362\u5206\u533a\u548c\u4ea4\u6362\u6587\u4ef6\u7684\u7ec4\u5408\u3002 \u4ea4\u6362\u7a7a\u95f4\u901a\u5e38\u5efa\u8bae\u7528\u6237\u81f3\u5c11 4 GB\uff0c\u7528\u6237\u4e5f\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u8981\u6c42\u548c\u73af\u5883\u521b\u5efa\u4ea4\u6362\u7a7a\u95f4\u3002<\/p>\n

\u6211\u53d1\u73b0\u5927\u90e8\u5206 VM \u548c \u4e91\u670d\u52a1\u5668\u90fd\u6ca1\u6709\u4ea4\u6362\u5206\u533a\uff0c\u6240\u4ee5\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4e09\u79cd\u65b9\u6cd5\u521b\u5efa\uff0c\u6269\u5c55\u6216\u589e\u52a0\u4ea4\u6362\u7a7a\u95f4\u3002<\/p>\n

\u5982\u4f55\u68c0\u6d4b\u5f53\u524d\u4ea4\u6362\u5206\u533a\u5927\u5c0f<\/strong><\/div>\n

\u901a\u8fc7 free\u00a0&\u00a0swapon \u547d\u4ee4\u6765\u68c0\u6d4b\u5f53\u524d\u7684\u4ea4\u6362\u5206\u533a\u7a7a\u95f4\u7684\u5927\u5c0f\u3002<\/p>\n

$ free -h\r\n\r\ntotal used free shared buff\/cache available\r\n\r\nMem: 2.0G 1.3G 139M 45M 483M 426M\r\n\r\nSwap: 2.0G 655M 1.4G\r\n\r\n$ swapon --show\r\n\r\nNAME TYPE SIZE USED PRIO\r\n\r\n\/dev\/sda5 partition 2G 655.2M -1\r\n<\/pre>\n

\u4e0a\u9762\u7684\u8f93\u51fa\u663e\u793a\u4e86\u5f53\u524d\u7684\u4ea4\u6362\u5206\u533a\u7a7a\u95f4\u662f 2GB \u3002<\/p>\n

\u65b9\u6cd5 1 : \u901a\u8fc7 fallocate \u547d\u4ee4\u521b\u5efa\u4ea4\u6362\u6587\u4ef6<\/strong><\/span><\/div>\n

fallocate \u7a0b\u5e8f\u662f\u7acb\u5373\u521b\u5efa\u9884\u5206\u914d\u5927\u5c0f\u7684\u6587\u4ef6\u7684\u6700\u4f73\u65b9\u6cd5\u3002<\/p>\n

\u4e0b\u9762\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u521b\u5efa\u4e00\u4e2a 1GB \u5927\u5c0f \u7684\u00a0\/swapfile\u3002<\/p>\n

$ sudo fallocate -l 1G \/swapfile\r\n<\/pre>\n

\u68c0\u67e5\u4e00\u4e0b\u521b\u5efa\u7684\u6587\u4ef6\u7684\u5927\u5c0f\u662f\u5426\u6b63\u786e\u3002<\/p>\n

$ ls -lh \/swapfile\r\n\r\n-rw-r--r-- 1 root root 1.0G Jun 7 09:49 \/swapfile\r\n<\/pre>\n

\u5c06\u8be5\u6587\u4ef6\u7684\u6743\u9650\u8bbe\u7f6e\u4e3a 600 \u8fd9\u6837\u53ea\u6709 root \u7528\u6237\u53ef\u4ee5\u8bbf\u95ee\u8fd9\u4e2a\u6587\u4ef6\u3002<\/p>\n

$ sudo chmod 600 \/swapfile\r\n<\/pre>\n

\u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u7684\u547d\u4ee4\u6765\u5c06\u6b64\u6587\u4ef6\u8f6c\u6362\u4e3a\u4ea4\u6362\u6587\u4ef6\u3002<\/p>\n

$ sudo mkswap \/swapfile\r\n\r\nSetting up swapspace version 1, size = 1024 MiB (1073737728 bytes)\r\n\r\nno label, UUID=cda50e0e-41f3-49c7-af61-b8cb4a33a464\r\n<\/pre>\n

\u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u7684\u547d\u4ee4\u6765\u4f7f\u4ea4\u6362\u6587\u4ef6\u751f\u6548\u3002<\/p>\n

$ sudo swapon \/swapfile\r\n<\/pre>\n

\u5c06\u65b0\u521b\u5efa\u7684\u4ea4\u6362\u6587\u4ef6\u6dfb\u52a0\u5230 fstab \u6587\u4ef6\u4e2d\uff0c\u8fd9\u6837\u4ea4\u6362\u5206\u533a\u7a7a\u95f4\u7684\u4fee\u6539\u5373\u4f7f\u5728\u91cd\u542f\u540e\u4e5f\u53ef\u4ee5\u751f\u6548\u3002<\/p>\n

$ vi \/etc\/fstab\r\n\r\n\/swapfile swap swap defaults 0 0\r\n<\/pre>\n

\u68c0\u67e5\u4e00\u4e0b\u65b0\u521b\u5efa\u7684\u4ea4\u6362\u6587\u4ef6\u3002<\/p>\n

$ swapon --show\r\n\r\nNAME TYPE SIZE USED PRIO\r\n\r\n\/dev\/sda5 partition 2G 657.8M -1\r\n\r\n\/swapfile file 1024M 0B -2\r\n<\/pre>\n

\u73b0\u5728\u6211\u53ef\u4ee5\u770b\u5230\u4e00\u4e2a\u65b0\u7684 \u00a01GB \u7684 \/swapfile1 \u6587\u4ef6\u4e86\u3002\u91cd\u542f\u7cfb\u7edf\u4ee5\u4f7f\u65b0\u7684\u4ea4\u6362\u6587\u4ef6\u751f\u6548\u3002<\/p>\n

\u65b9\u6cd5 2 : \u901a\u8fc7 dd \u547d\u4ee4\u6765\u521b\u5efa\u4ea4\u6362\u6587\u4ef6<\/strong><\/span><\/div>\n

dd \u547d\u4ee4\u662f\u53e6\u4e00\u4e2a\u5b9e\u7528\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u7acb\u5373\u521b\u5efa\u9884\u5206\u914d\u5927\u5c0f\u7684\u6587\u4ef6\u3002<\/p>\n

\u4ee5\u4e0b dd \u547d\u4ee4\u5c06\u521b\u5efa 1GB \u7684 \/swapfile1\u3002<\/p>\n

$ sudo dd if=\/dev\/zero of=\/swapfile1 bs=1G count=1\r\n\r\n1+0 records in\r\n\r\n1+0 records out\r\n\r\n1073741824 bytes (1.1 GB, 1.0 GiB) copied, 16.6154 s, 64.6 MB\/s\r\n<\/pre>\n

\u8be6\u89e3\uff1a if=\/dev\/zero\u00a0\u662f\u8f93\u5165\u6587\u4ef6\uff0c\/dev\/zero \u662f\u7c7b Unix \u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u4e00\u4e2a\u7279\u6b8a\u6587\u4ef6\uff0c\u5b83\u63d0\u4f9b\u4ece\u5b83\u8bfb\u53d6\u7684\u5c3d\u53ef\u80fd\u591a\u7684\u7a7a\u5b57\u7b26\uff08ASCII NUL\uff0c0x00\uff09\u3002<\/p>\n

of=\/swapfile1\u00a0\u8bbe\u7f6e\u8f93\u51fa\u6587\u4ef6\u3002<\/p>\n

bs=1G\u00a0\u4e00\u6b21\u6027\u8bfb\u5199\u7684\u5927\u5c0f\u4e3a 1GB<\/p>\n

count=1\u00a0\u4ec5\u590d\u5236\u4e00\u4e2a\u8f93\u5165\u5757<\/p>\n

\u68c0\u67e5\u4e00\u4e0b\u521b\u5efa\u7684\u6587\u4ef6\u7684\u5927\u5c0f\u662f\u5426\u6b63\u786e\u3002<\/p>\n

$ ls -lh \/swapfile1\r\n\r\n-rw-r--r-- 1 root root 1.0G Jun 7 09:58 \/swapfile1\r\n<\/pre>\n

\u5c06\u8be5\u6587\u4ef6\u7684\u6743\u9650\u8bbe\u7f6e\u4e3a 600 \u8fd9\u6837\u53ea\u6709 root \u7528\u6237\u53ef\u4ee5\u8bbf\u95ee\u8fd9\u4e2a\u6587\u4ef6\u3002<\/p>\n

$ sudo chmod 600 \/swapfile1\r\n<\/pre>\n

\u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u7684\u547d\u4ee4\u6765\u5c06\u6b64\u6587\u4ef6\u8f6c\u6362\u4e3a\u4ea4\u6362\u6587\u4ef6\u3002<\/p>\n

$ sudo mkswap \/swapfile1\r\n\r\nSetting up swapspace version 1, size = 1024 MiB (1073737728 bytes)\r\n\r\nno label, UUID=96def6d7-b2da-4954-aa72-aa32316ec993\r\n<\/pre>\n

\u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u7684\u547d\u4ee4\u6765\u4f7f\u4ea4\u6362\u6587\u4ef6\u751f\u6548\u3002<\/p>\n

$ sudo swapon \/swapfile1\r\n<\/pre>\n

\u5c06\u65b0\u521b\u5efa\u7684\u4ea4\u6362\u6587\u4ef6\u6dfb\u52a0\u5230 fstab \u6587\u4ef6\u4e2d\uff0c\u8fd9\u6837\u4ea4\u6362\u5206\u533a\u7a7a\u95f4\u7684\u4fee\u6539\u5373\u4f7f\u5728\u91cd\u542f\u540e\u4e5f\u53ef\u4ee5\u751f\u6548\u3002<\/p>\n

$ vi \/etc\/fstab\r\n\r\n\/swapfile1 swap swap defaults 0 0\r\n<\/pre>\n

\u68c0\u67e5\u65b0\u521b\u5efa\u7684\u4ea4\u6362\u6587\u4ef6\u3002<\/p>\n

$ swapon --show\r\n\r\nNAME TYPE SIZE USED PRIO\r\n\r\n\/dev\/sda5 partition 2G 1.3G -1\r\n\r\n\/swapfile file 1024M 0B -2\r\n\r\n\/swapfile1 file 1024M 0B -3\r\n<\/pre>\n

\u73b0\u5728\u6211\u53ef\u4ee5\u770b\u5230\u4e00\u4e2a\u65b0\u7684 \u00a01GB \u7684 \/swapfile1 \u4e86\u3002\u91cd\u542f\u7cfb\u7edf\u4ee5\u4f7f\u65b0\u7684\u4ea4\u6362\u6587\u4ef6\u751f\u6548\u3002<\/p>\n

\u65b9\u6cd5 3 : \u901a\u8fc7\u786c\u76d8\u5206\u533a\u6765\u521b\u5efa\u4ea4\u6362\u6587\u4ef6<\/strong><\/span><\/div>\n

\u6211\u4eec\u4e5f\u63a8\u8350\u4f7f\u7528\u901a\u8fc7\u786c\u76d8\u5206\u533a\u7684\u65b9\u5f0f\u6765\u521b\u5efa\u4ea4\u6362\u5206\u533a\u3002<\/p>\n

\u5982\u679c\u4f60\u5df2\u7ecf\u5728\u4f60\u7684\u53e6\u4e00\u4e2a\u786c\u76d8\u4e0a\u901a\u8fc7 fdisk \u547d\u4ee4\u521b\u5efa\u4e86\u4e00\u4e2a\u65b0\u7684\u5206\u533a\uff0c\u5047\u8bbe\u6211\u4eec\u5df2\u7ecf\u521b\u5efa\u4e86\u4e00\u4e2a\u53eb\u505a \/dev\/sda4 \u7684\u5206\u533a\u3002<\/p>\n

\u4f7f\u7528 mkswap \u547d\u4ee4\u6765\u5c06\u8fd9\u4e2a\u5206\u533a\u8f6c\u6362\u6210\u4ea4\u6362\u5206\u533a\u3002<\/p>\n

$ sudo mkswap \/dev\/sda4\r\n<\/pre>\n

\u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u4f7f\u4ea4\u6362\u6587\u4ef6\u751f\u6548\u3002<\/p>\n

$ sudo swapon \/dev\/sda4\r\n<\/pre>\n

\u628a\u65b0\u589e\u7684\u4ea4\u6362\u6587\u4ef6\u6dfb\u52a0\u5230 fstab \u6587\u4ef6\u4e2d\uff0c\u8fd9\u6837\u5373\u4f7f\u662f\u91cd\u542f\u4e86\u7cfb\u7edf\u4ea4\u6362\u5206\u533a\u7684\u4fee\u6539\u4e5f\u80fd\u751f\u6548\u3002<\/p>\n

$ vi \/etc\/fstab\r\n\r\n\/dev\/sda4 swap swap defaults 0 0\r\n<\/pre>\n

\u68c0\u67e5\u65b0\u521b\u5efa\u7684\u4ea4\u6362\u6587\u4ef6\u3002<\/p>\n

$ swapon --show\r\n\r\nNAME TYPE SIZE USED PRIO\r\n\r\n\/dev\/sda5 partition 2G 1.3G -1\r\n\r\n\/swapfile file 1024M 0B -2\r\n\r\n\/swapfile1 file 1024M 0B -3\r\n\r\n\/dev\/sda4 partition 1G 0B -4\r\n<\/pre>\n

\u6211\u53ef\u4ee5\u770b\u5230\u65b0\u7684\u4ea4\u6362\u5206\u533a\u00a01GB \u7684 \/dev\/sda4\u3002\u91cd\u542f\u7cfb\u7edf\u5c31\u53ef\u4ee5\u4f7f\u7528\u65b0\u7684\u4ea4\u6362\u5206\u533a\u4e86\u3002<\/p>\n

via: http:\/\/www.2daygeek.com\/add-extend-increase-swap-space-memory-file-partition-linux\/<\/a><\/p>\n

\u4f5c\u8005\uff1a2DAYGEEK<\/a> \u8bd1\u8005\uff1achenxinlong<\/a> \u6821\u5bf9\uff1awxy<\/a><\/p>\n

\u672c\u6587\u7531 LCTT<\/a> \u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd<\/a> \u8363\u8a89\u63a8\u51fa<\/p>\n

\n

\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/linux.cn\/article-8699-1.html<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1a http:\/\/lrxjmw.cn\/linux-create-partition.html<\/a>\u7f16\u8f91\uff1a\u90d1\u5e05\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u5bfc\u8bfb \u7528\u6237\u53ef\u4ee5\u5728\u4efb\u4f55 Linux \u64cd\u4f5c\u7cfb\u7edf\u7684\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u6216\u8005\u662f\u5176\u5b83\u5fc5\u8981\u7684\u65f6\u5019\u521b\u5efa\u4ea4\u6362\u7a7a\u95f4\u3002\u5982\u679c\u4f60\u5728\u5b89\u88c5 Linu […]<\/p>\n","protected":false},"author":63,"featured_media":80056,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-79938","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/79938","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=79938"}],"version-history":[{"count":9,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/79938\/revisions"}],"predecessor-version":[{"id":286231,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/79938\/revisions\/286231"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/80056"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=79938"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=79938"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=79938"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}