{"id":240318,"date":"2022-04-27T09:03:32","date_gmt":"2022-04-27T01:03:32","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=240318"},"modified":"2022-04-11T11:15:40","modified_gmt":"2022-04-11T03:15:40","slug":"liunx-hard-disk","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/liunx-hard-disk.html","title":{"rendered":"Liunx\u6dfb\u52a0\u65b0\u786c\u76d8\u548c\u5206\u533a\u65b9\u6cd5"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nLiunx\u6dfb\u52a0\u65b0\u786c\u76d8\u5176\u5b9e\u548cWindows\u7684\u64cd\u4f5c\u4e00\u6837\uff0c\u4f46\u4e00\u4e2a\u662f\u56fe\u5f62\u5316\u64cd\u4f5c\uff0c\u53e6\u4e00\u4e2a\u662f\u547d\u4ee4\u884c\u64cd\u4f5c\uff0c\u4e0d\u8fc7\u6b65\u9aa4\u662f\u4e00\u6837\uff0c\u4e0b\u9762\u5c31\u52a8\u624b\u6f14\u793a\u548c\u8bb2\u89e3<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
Linux\u6302\u8f7d\u65b0\u786c\u76d8<\/strong><\/div>\n
1\u3001\u67e5\u770b\u786c\u76d8\u4fe1\u606f<\/strong><\/span><\/div>\n

\u547d\u4ee4\uff1a<\/p>\n

fdisk -l<\/pre>\n
# fdisk -l\r\nDisk \/dev\/vda: 21.5 GB, 21474836480 bytes                                          #\u7b2c\u4e00\u5757\u786c\u76d8\u7684\u4fe1\u606f\u548c\u5206\u533a\u4fe1\u606f\r\n255 heads, 63 sectors\/track, 2610 cylinders\r\nUnits = cylinders of 16065 * 512 = 8225280 bytes\r\nSector size (logical\/physical): 512 bytes \/ 512 bytes\r\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\r\nDisk identifier: 0x0003a7b4\r\n\r\n  Device Boot      Start        End      Blocks  Id  System\r\n    \/dev\/vda1  *          1        2611    20970496  83  Linux\r\n\r\nDisk \/dev\/vdb: 107.4 GB, 107374182400 bytes                                        #\u7b2c\u4e8c\u5757\u786c\u76d8\u7684\u4fe1\u606f\u548c\u5206\u533a\u4fe1\u606f\r\n16 heads, 63 sectors\/track, 208050 cylinders\r\nUnits = cylinders of 1008 * 512 = 516096 bytes\r\nSector size (logical\/physical): 512 bytes \/ 512 bytes\r\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\r\nDisk identifier: 0x00000000<\/pre>\n
2\u3001\u521b\u5efa\u65b0\u786c\u76d8\u5206\u533a<\/strong><\/span><\/div>\n

\u547d\u4ee4\uff1a<\/p>\n

fdisk \/dev\/vdb<\/pre>\n
# fdisk \/dev\/vdb\r\nDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel\r\nBuilding a new DOS disklabel with disk identifier 0x1e694286.\r\nChanges will remain in memory only, until you decide to write them.\r\nAfter that, of course, the previous content won't be recoverable.\r\n\r\nWarning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)\r\n\r\nWARNING: DOS-compatible mode is deprecated. It's strongly recommended to\r\n        switch off the mode (command 'c') and change display units to\r\n        sectors (command 'u').\r\n\r\nCommand (m for help): n\r\nCommand action\r\n  e  extended                                #e\u4e3a\u521b\u5efa\u6269\u5c55\u5206\u533a\r\n  p  primary partition (1-4)            #p\u4e3a\u521b\u5efa\u903b\u8f91\u5206\u533a\r\np\r\nPartition number (1-4): 1          #\u5728\u8fd9\u91cc\u8f93\u51651\uff0c\u5c31\u8fdb\u5165\u5212\u5206\u903b\u8f91\u5206\u533a\u9636\u6bb5\u4e86\uff1b\r\nFirst cylinder (1-208050, default 1): 1      #\u5206\u533a\u7684Start \u503c\uff0c\u8fd9\u91cc\u6700\u597d\u76f4\u63a5\u6309\u56de\u8f66\uff0c\u5426\u5219\u53ef\u80fd\u4f1a\u9020\u6210\u7a7a\u95f4\u6d6a\u8d39\uff1b\r\nUsing default value 1\r\nLast cylinder, +cylinders or +size{K,M,G} (1-208050, default 208050): 208050      #\u5206\u533a\u7684Over\u503c\uff0c\u6211\u5c31\u5206\u4e00\u4e2a\u533a\r\nUsing default value 208050\r\n\r\nCommand (m for help): w                            #\u6700\u540e\u8f93\u5165w\u56de\u8f66\u4fdd\u5b58\u9000\u51fa\u3002\r\nThe partition table has been altered!\r\n\r\nCalling ioctl() to re-read partition table.\r\nSyncing disks.<\/pre>\n

fdisk\u53ef\u4ee5\u7528m\u547d\u4ee4\u6765\u770bfdisk\u547d\u4ee4\u7684\u5185\u90e8\u547d\u4ee4\uff1b
\na\uff1a\u547d\u4ee4\u6307\u5b9a\u542f\u52a8\u5206\u533a\uff1b
\nd\uff1a\u547d\u4ee4\u5220\u9664\u4e00\u4e2a\u5b58\u5728\u7684\u5206\u533a\uff1b
\nl\uff1a\u547d\u4ee4\u663e\u793a\u5206\u533aID\u53f7\u7684\u5217\u8868\uff1b
\nm\uff1a\u67e5\u770bfdisk\u547d\u4ee4\u5e2e\u52a9\uff1b
\nn\uff1a\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u5206\u533a\uff1b
\np\uff1a\u547d\u4ee4\u663e\u793a\u5206\u533a\u5217\u8868\uff1b
\nt\uff1a\u547d\u4ee4\u4fee\u6539\u5206\u533a\u7684\u7c7b\u578bID\u53f7\uff1b
\nw\uff1a\u547d\u4ee4\u662f\u5c06\u5bf9\u5206\u533a\u8868\u7684\u4fee\u6539\u5b58\u76d8\u8ba9\u5b83\u53d1\u751f\u4f5c\u7528\uff1b<\/p>\n

3\u3001\u786e\u8ba4\u65b0\u5206\u533a\u4fe1\u606f<\/strong><\/span><\/div>\n

\u547d\u4ee4\uff1a<\/p>\n

fdisk -l<\/pre>\n
# fdisk -l\r\nDisk \/dev\/vda: 21.5 GB, 21474836480 bytes\r\n255 heads, 63 sectors\/track, 2610 cylinders\r\nUnits = cylinders of 16065 * 512 = 8225280 bytes\r\nSector size (logical\/physical): 512 bytes \/ 512 bytes\r\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\r\nDisk identifier: 0x0003a7b4\r\n\r\n  Device Boot      Start        End      Blocks  Id  System\r\n    \/dev\/vda1  *          1        2611    20970496  83  Linux\r\n\r\nDisk \/dev\/vdb: 107.4 GB, 107374182400 bytes\r\n16 heads, 63 sectors\/track, 208050 cylinders\r\nUnits = cylinders of 1008 * 512 = 516096 bytes\r\nSector size (logical\/physical): 512 bytes \/ 512 bytes\r\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\r\nDisk identifier: 0x1e694286\r\n\r\n  Device Boot      Start        End      Blocks  Id  System\r\n    \/dev\/vdb1              1      208050  104857168+  83  Linux          #\u521a\u521b\u5efa\u597d\u7684\u5206\u533a\u4fe1\u606f<\/pre>\n
4\u3001\u683c\u5f0f\u5316\u5206\u533a<\/strong><\/span><\/div>\n

\u547d\u4ee4\uff1a<\/p>\n

mkfs.ext4 \/dev\/vdb1<\/pre>\n
# mkfs.ext4 \/dev\/vdb1\r\nmke2fs 1.41.12 (17-May-2010)\r\nFilesystem label=                  #\u6587\u4ef6\u7cfb\u7edf\u6807\u7b7e\r\nOS type: Linux                #\u64cd\u4f5c\u7cfb\u7edf\u7c7b\u578b\r\nBlock size=4096 (log=2)          #\u5757\u5927\u5c0f\r\nFragment size=4096 (log=2)      #\u5206\u5757\u5927\u5c0f\r\nStride=0 blocks, Stripe width=0 blocks\r\n6553600 inodes, 26214292 blocks\r\n1310714 blocks (5.00%) reserved for the super user\r\nFirst data block=0          #\u7b2c\u4e00\u4e2a\u6570\u636e\u5757\r\nMaximum filesystem blocks=4294967296\r\n800 block groups\r\n32768 blocks per group, 32768 fragments per group\r\n8192 inodes per group\r\nSuperblock backups stored on blocks:\r\n    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,\r\n    4096000, 7962624, 11239424, 20480000, 23887872\r\n\r\nWriting inode tables: done                          #\u5199\u5165inode\u8868\r\nCreating journal (32768 blocks): done\r\nWriting superblocks and filesystem accounting information: done\r\n\r\nThis filesystem will be automatically checked every 26 mounts or\r\n180 days, whichever comes first.  Use tune2fs -c or -i to override.<\/pre>\n

Linux\u7684\u5206\u533a\u7c7b\u578b\u4ecb\u7ecd\uff1a
\n\u968f\u7740Linux\u7cfb\u7edf\u5728\u73b0\u5728\u4e1a\u52a1\u4e2d\u7684\u5e94\u7528\uff0cLinux\u6587\u4ef6\u7cfb\u7edf\u7684\u5f31\u70b9\u4e5f\u6e10\u6e10\u663e\u9732\u51fa\u6765\u4e86\uff0c\u5176\u4e2d\u7cfb\u7edf\u7f3a\u7701\u4f7f\u7528\u7684ext2\u6587\u4ef6\u7cfb\u7edf\u662f\u975e\u65e5\u5fd7\u6587\u4ef6\u7cfb\u7edf\u3002\u8fd9\u5728\u5173\u952e\u884c\u4e1a\u7684\u5e94\u7528\u662f\u4e00\u4e2a\u81f4\u547d\u7684\u5f31\u70b9.\u800cExt3\u6587\u4ef6\u7cfb\u7edf\u662f\u76f4\u63a5\u4eceExt2\u6587\u4ef6\u7cfb\u7edf\u53d1\u5c55\u800c\u6765\uff0c\u76ee\u524dext3\u6587\u4ef6\u7cfb\u7edf\u5df2\u7ecf\u975e\u5e38\u7a33\u5b9a\u53ef\u9760\u3002\u5b83\u5b8c\u5168\u517c\u5bb9Ext2\u6587\u4ef6\u7cfb\u7edf\u3002
\nExt3\u7684\u7279\u70b9\uff1a\u9ad8\u53ef\u7528\u6027\u3001\u6570\u636e\u7684\u5b8c\u6574\u6027\u3001\u6570\u636e\u7684\u5b8c\u6574\u6027\u3001\u6570\u636e\u8f6c\u6362\u3001\u591a\u79cd\u65e5\u5fd7\u6a21\u5f0f
\n\u540c\u6837\u7684Ext4\u5b8c\u5168\u517c\u5bb9Ext3\uff0c\u76f8\u5bf9\u4e8eExt3\u6765\u8bf4\uff0cExt4\u652f\u6301\u66f4\u5927\u7684\u5b58\u50a8\uff0cExt3\u76ee\u524d\u6240\u652f\u6301\u7684\u6700\u592716TB\u6587\u4ef6\u7cfb\u7edf\u548c\u6700\u59272TB\u6587\u4ef6\uff0c\u800cExt4\u5206\u522b\u652f\u63011EB\u7684\u6587\u4ef6\u7cfb\u7edf\uff0c\u4ee5\u53ca16TB \u7684\u6587\u4ef6\uff0c\u8fd8\u6709\u5c31\u662fExt3\u76ee\u524d\u53ea\u652f\u630132,000\u4e2a\u5b50\u76ee\u5f55\uff0c\u800cExt4\u652f\u6301\u65e0\u9650\u6570\u91cf\u7684\u5b50\u76ee\u5f55\uff0cExt4\u5f15\u5165\u4e86\u73b0\u4ee3\u6587\u4ef6\u7cfb\u7edf\u4e2d\u6d41\u884c\u7684extents\u6982\u5ff5\uff0c\u6bcf\u4e2a extent \u4e3a\u4e00\u7ec4\u8fde\u7eed\u7684\u6570\u636e\u5757\uff0c\u4e0a\u8ff0\u6587\u4ef6\u5219\u8868\u793a\u4e3a\u201c\u8be5\u6587\u4ef6\u6570\u636e\u4fdd\u5b58\u5728\u63a5\u4e0b\u6765\u768425,600\u4e2a\u6570\u636e\u5757\u4e2d\u201d\uff0c\u63d0\u9ad8\u4e86\u4e0d\u5c11\u6548\u7387\u3002<\/p>\n

5\u3001\u521b\u5efa\u6302\u8f7d\u76ee\u5f55<\/strong><\/span><\/div>\n

\u547d\u4ee4\uff1a<\/p>\n

mkdir \/data<\/pre>\n

6\u3001\u6302\u8f7d\u5206\u533a<\/p>\n

\u547d\u4ee4\uff1a<\/p>\n

mount \/dev\/vdb1 \/data<\/pre>\n
7\u3001\u67e5\u770b\u786c\u76d8\u5927\u5c0f\u4ee5\u53ca\u6302\u8f7d\u5206\u533a<\/strong><\/span><\/div>\n

\u547d\u4ee4\uff1a<\/p>\n

df -Th<\/pre>\n
# df -Th\r\nFilesystem    Type  Size  Used Avail Use% Mounted on\r\n\/dev\/vda1      ext4    20G  1.1G  18G  6% \/\r\ntmpfs          tmpfs  3.9G    0  3.9G  0% \/dev\/shm\r\n\/dev\/vdb1      ext4    99G  60M  94G  1% \/data          #\u65b0\u6302\u8f7d\u7684\u5206\u533a<\/pre>\n
8\u3001\u914d\u7f6e\u5f00\u673a\u81ea\u52a8\u6302\u8f7d<\/strong><\/span><\/div>\n

\u547d\u4ee4\uff1a<\/p>\n

vim \/etc\/fstab \/dev\/vdb1 \/data ext4 defaults 1 1<\/pre>\n
# blkid\r\n\/dev\/vda1: UUID=\"b7aae0d4-268c-4b60-914a-f3b48e22819c\" TYPE=\"ext4\"\r\n\/dev\/vdb1: UUID=\"5de835dd-5322-46f0-8728-3d4ae7d83b54\" TYPE=\"ext4\"<\/pre>\n
# cat \/etc\/fstab\r\n#\r\n# \/etc\/fstab\r\n# Created by anaconda on Tue Mar 27 04:51:55 2018\r\n#\r\n# Accessible filesystems, by reference, are maintained under '\/dev\/disk'\r\n# See man pages fstab(5), findfs(8), mount(8) and\/or blkid(8) for more info\r\n#\r\nUUID=b7aae0d4-268c-4b60-914a-f3b48e22819c      \/                      ext4      defaults      1 1\r\nUUID=5de835dd-5322-46f0-8728-3d4ae7d83b54    \/data                ext4  defaults    1 1\r\ntmpfs                  \/dev\/shm                tmpfs  defaults        0 0\r\ndevpts                  \/dev\/pts                devpts  gid=5,mode=620  0 0\r\nsysfs                  \/sys                    sysfs  defaults        0 0\r\nproc                    \/proc                  proc    defaults        0 0<\/pre>\n
Swap\u5206\u533a<\/strong><\/div>\n

Swap\u5206\u533a\u5176\u5b9e\u548cWindows\u4e0a\u7684\u865a\u62df\u5185\u5b58\u4e00\u6837\uff0cSwap\u5206\u533a\u5728\u7cfb\u7edf\u7684\u7269\u7406\u5185\u5b58\u4e0d\u591f\u7528\u7684\u65f6\u5019\uff0c\u628a\u7269\u7406\u5185\u5b58\u4e2d\u7684\u4e00\u90e8\u5206\u7a7a\u95f4\u91ca\u653e\u51fa\u6765\uff0c\u4ee5\u4f9b\u5f53\u524d\u8fd0\u884c\u7684\u7a0b\u5e8f\u4f7f\u7528\u3002\u90a3\u4e9b\u88ab\u91ca\u653e\u7684\u7a7a\u95f4\u53ef\u80fd\u6765\u81ea\u4e00\u4e9b\u5f88\u957f\u65f6\u95f4\u6ca1\u6709\u4ec0\u4e48\u64cd\u4f5c\u7684\u7a0b\u5e8f\uff0c\u8fd9\u4e9b\u88ab\u91ca\u653e\u7684\u7a7a\u95f4\u88ab\u4e34\u65f6\u4fdd\u5b58\u5230Swap\u5206\u533a\u4e2d\uff0c\u7b49\u5230\u90a3\u4e9b\u7a0b\u5e8f\u8981\u8fd0\u884c\u65f6\uff0c\u518d\u4eceSwap\u5206\u533a\u4e2d\u6062\u590d\u4fdd\u5b58\u7684\u6570\u636e\u5230\u5185\u5b58\u4e2d\u3002<\/p>\n

\u4e0b\u9762\u4ecb\u7ecd\u4e24\u79cd\u521b\u5efaswap\u7684\u65b9\u6cd5\uff1a
\n\u2022\u65b0\u5efa\u78c1\u76d8\u5206\u533a\u4f5c\u4e3aswap\u5206\u533a
\n\u2022\u7528\u6587\u4ef6\u4f5c\u4e3aSwap\u5206\u533a<\/p>\n

\u65b0\u5efa\u78c1\u76d8\u5206\u533a\u4f5c\u4e3aswap\u5206\u533a<\/strong><\/span><\/div>\n

1.\u7528fdisk\u547d\u4ee4\u5bf9\u78c1\u76d8\u8fdb\u884c\u5206\u533a\uff0c\u6dfb\u52a0swap\u5206\u533a\uff0c\u65b0\u5efa\u5206\u533a\uff0c\u5728fdisk\u4e2d\u7528\u201ct\u201d\u547d\u4ee4\u5c06\u65b0\u6dfb\u7684\u5206\u533aid\u6539\u4e3a82
\n\uff08Linux swap\u7c7b\u578b\uff09<\/p>\n

2.\u683c\u5f0f\u5316swap\u5206\u533a\uff0c\u8fd9\u91cc\u7684sdb2\u8981\u770b\u60a8\u52a0\u5b8c\u540ep\u547d\u4ee4\u663e\u793a\u7684\u5b9e\u9645\u5206\u533a\u8bbe\u5907\u540d<\/p>\n

mkswap \/dev\/sdb1<\/pre>\n

3.\u542f\u52a8\u65b0\u7684swap\u5206\u533a<\/p>\n

swapon \/dev\/sdb1<\/pre>\n

4.\u8ba9\u7cfb\u7edf\u542f\u52a8\u65f6\u80fd\u81ea\u52a8\u542f\u7528\u8fd9\u4e2a\u4ea4\u6362\u5206\u533a\uff0c\u53ef\u4ee5\u7f16\u8f91\/etc\/fstab,\u52a0\u5165\u4e0b\u9762\u4e00\u884c<\/p>\n

\/dev\/sdb1 swap swap defaults 0 0<\/pre>\n
\u7528\u6587\u4ef6\u4f5c\u4e3aSwap\u5206\u533a<\/strong><\/span><\/div>\n

1.\u521b\u5efa\u8981\u4f5c\u4e3aswap\u5206\u533a\u7684\u6587\u4ef6:\u589e\u52a01GB\u5927\u5c0f\u7684\u4ea4\u6362\u5206\u533a\uff0c\u5219\u547d\u4ee4\u5199\u6cd5\u5982\u4e0b\uff0c\u5176\u4e2d\u7684count\u7b49\u4e8e\u60f3\u8981\u7684\u5757\u7684\u6570\u91cf\uff08bs*count=\u6587\u4ef6\u5927\u5c0f\uff09\u3002<\/p>\n

dd if=\/dev\/zero of=\/root\/swapfile bs=1M count=1024<\/pre>\n

2.\u683c\u5f0f\u5316\u4e3a\u4ea4\u6362\u5206\u533a\u6587\u4ef6\uff0c\u5efa\u7acbswap\u7684\u6587\u4ef6\u7cfb\u7edf:<\/p>\n

mkswap \/root\/swapfile<\/pre>\n

3.\u7528\u4ea4\u6362\u5206\u533a\u6587\u4ef6:<\/p>\n

swapon \/root\/swapfile<\/pre>\n

4.\u4f7f\u7cfb\u7edf\u5f00\u673a\u65f6\u81ea\u542f\u7528\uff0c\u5728\u6587\u4ef6\/etc\/fstab\u4e2d\u6dfb\u52a0\u4e00\u884c\uff1a<\/p>\n

\/root\/swapfile swap swap defaults 0 0<\/pre>\n","protected":false},"excerpt":{"rendered":"

\u547d\u4ee4\uff1a fdisk -l # fdisk -l Disk \/dev\/vda: 21.5 GB, 2147483 […]<\/p>\n","protected":false},"author":310,"featured_media":240335,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-240318","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\/240318","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\/310"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=240318"}],"version-history":[{"count":17,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/240318\/revisions"}],"predecessor-version":[{"id":240554,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/240318\/revisions\/240554"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/240335"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=240318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=240318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=240318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}