{"id":18,"date":"2024-01-20T17:12:00","date_gmt":"2024-01-20T09:12:00","guid":{"rendered":"https:\/\/www.yuuriso.cn\/?p=18"},"modified":"2024-02-20T17:16:43","modified_gmt":"2024-02-20T09:16:43","slug":"lvm-%e8%99%9a%e6%8b%9f%e6%9c%ba%e6%89%a9%e5%ae%b9","status":"publish","type":"post","link":"https:\/\/www.yuuriso.cn\/?p=18","title":{"rendered":"lvm \u865a\u62df\u673a\u6269\u5bb9"},"content":{"rendered":"\n<p>1.\u4f7f\u7528\u547d\u4ee4\u5c06qcow2 \u6587\u4ef6\u6269\u5bb9<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u6587\u4ef6\u4e4b\u524d\u5df2\u7ecf\u8bbe\u7f6e\u4e8650G,\u73b0\u5728\u589e\u52a050G\nqemu-img resize \/data\/img\/rds1.qcow2 +50G\n\n# \u67e5\u770b\u6587\u4ef6\u4fe1\u606f,\u6267\u884c\u6b64\u547d\u4ee4\u9700\u8981\u865a\u62df\u673a\u5173\u673a\nqemu-img info \/data\/img\/rds1.qcow2 \n\nroot@yuuri-MS-7C94:\/data\/img# qemu-img info \/data\/img\/rds1.qcow2\nimage: \/data\/img\/rds1.qcow2\nfile format: qcow2\nvirtual size: 100 GiB (107374182400 bytes)\ndisk size: 37.3 GiB\ncluster_size: 65536\nSnapshot list:\nID        TAG                     VM SIZE                DATE       VM CLOCK\n1         1651040447             3.27 GiB 2022-04-27 14:20:47   00:08:53.146\nFormat specific information:\n    compat: 1.1\n    lazy refcounts: true\n    refcount bits: 16\n    corrupt: false<\/code><\/pre>\n\n\n\n<p>2.\u6dfb\u52a0\u5b8c\u6210\u540e\u8fdb\u5165\u865a\u62df\u673a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>virsh console rds1\n\n# \u8fdb\u5165\u865a\u62df\u673a\u540e\u67e5\u770b\u7a7a\u95f4\u5df2\u7ecf\u589e\u52a0,\u4f46\u662f\u65e0\u6cd5\u4f7f\u7528\n\n&#91;root@localhost ~]# lsblk\nNAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT\nsr0              11:0    1 1024M  0 rom\nvda             252:0    0  100G  0 disk\n\u251c\u2500vda1          252:1    0    1G  0 part \/boot\n\u2514\u2500vda2          252:2    0   49G  0 part\n  \u251c\u2500centos-root 253:0    0 45.1G  0 lvm  \/\n  \u2514\u2500centos-swap 253:1    0  3.9G  0 lvm  &#91;SWAP]<\/code><\/pre>\n\n\n\n<p>3.\u5c06\u672a\u5206\u914d\u7684\u7a7a\u95f4\u8fdb\u884c\u521d\u59cb\u683c\u5f0f\u5316<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@localhost ~]# fpdisk \/dev\/vda\nWelcome to fdisk (util-linux 2.23.2).\n\nChanges will remain in memory only, until you decide to write them.\nBe careful before using the write command.\n\n\nCommand (m for help):\n\n\n\n# \u4e0b\u4e00\u6b65\u9009\u62e9n ,\u6dfb\u52a0\u4e00\u4e2a\u65b0\u7684\u5206\u533a\n\n\nWelcome to fdisk (util-linux 2.23.2).\n\nChanges will remain in memory only, until you decide to write them.\nBe careful before using the write command.\n\n\nCommand (m for help): n\nPartition type:\n   p   primary (2 primary, 0 extended, 2 free)\n   e   extended\nSelect (default p): p\nPartition number (3,4, default 3): 3\nFirst sector (104857600-209715199, default 104857600):\nUsing default value 104857600\nLast sector, +sectors or +size{K,M,G} (104857600-209715199, default 209715199):\nUsing default value 209715199\nPartition 3 of type Linux and of size 50 GiB is set\n\n\n\n# \u6253\u5370\u5206\u533a\u4fe1\u606f,\u5e76\u5c06\u5206\u533a\u4fee\u6539\u4e3alvm \u683c\u5f0f\n\nCommand (m for help): p\n\nDisk \/dev\/vda: 107.4 GB, 107374182400 bytes, 209715200 sectors\nUnits = sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\nDisk label type: dos\nDisk identifier: 0x00089f98\n\n   Device Boot      Start         End      Blocks   Id  System\n\/dev\/vda1   *        2048     2099199     1048576   83  Linux\n\/dev\/vda2         2099200   104857599    51379200   8e  Linux LVM\n\/dev\/vda3       104857600   209715199    52428800   83  Linux\n\nCommand (m for help): t\nPartition number (1-3, default 3):\nHex code (type L to list all codes): 8e\nChanged type of partition 'Linux' to 'Linux LVM'\n\n\n\n# \u6700\u540e\u4e00\u6b65,\u8f93\u5165w \u9000\u51fa\u5e76\u4fdd\u5b58\u7ed3\u679c\n\nCommand (m for help): m\nCommand action\n   a   toggle a bootable flag\n   b   edit bsd disklabel\n   c   toggle the dos compatibility flag\n   d   delete a partition\n   g   create a new empty GPT partition table\n   G   create an IRIX (SGI) partition table\n   l   list known partition types\n   m   print this menu\n   n   add a new partition\n   o   create a new empty DOS partition table\n   p   print the partition table\n   q   quit without saving changes\n   s   create a new empty Sun disklabel\n   t   change a partition's system id\n   u   change display\/entry units\n   v   verify the partition table\n   w   write table to disk and exit\n   x   extra functionality (experts only)\n\nCommand (m for help): w\nThe partition table has been altered!\n\nCalling ioctl() to re-read partition table.\n\nWARNING: Re-reading the partition table failed with error 16: Device or resource busy.\nThe kernel still uses the old table. The new table will be used at\nthe next reboot or after you run partprobe(8) or kpartx(8)\nSyncing disks.<\/code><\/pre>\n\n\n\n<p>4.\u4f7f\u7528lvm \u8fdb\u884c\u6269\u5bb9<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u9996\u5148\u6267\u884cpartprobe\n&#91;root@localhost ~]# partprobe\n\n# \u6267\u884clsblk \u5206\u533a\u4fe1\u606f,\u5df2\u7ecf\u589e\u52a0\n&#91;root@localhost ~]# lsblk\nNAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT\nsr0              11:0    1 1024M  0 rom\nvda             252:0    0  100G  0 disk\n\u251c\u2500vda1          252:1    0    1G  0 part \/boot\n\u251c\u2500vda2          252:2    0   49G  0 part\n\u2502 \u251c\u2500centos-root 253:0    0 45.1G  0 lvm  \/\n\u2502 \u2514\u2500centos-swap 253:1    0  3.9G  0 lvm  &#91;SWAP]\n\u2514\u2500vda3          252:3    0   50G  0 part\n\n\n\n# \u6dfb\u52a0pv\n&#91;root@localhost ~]# pvcreate \/dev\/vda3\n  Physical volume \"\/dev\/vda3\" successfully created.\n\n\n# \u67e5\u770bpv\n&#91;root@localhost ~]# pvs\n  PV         VG     Fmt  Attr PSize   PFree\n  \/dev\/vda2  centos lvm2 a--  &lt;49.00g  4.00m\n  \/dev\/vda3         lvm2 ---   50.00g 50.00g\n\n\n\n# \u67e5\u770bvg\n&#91;root@localhost ~]# vgs\n  VG     #PV #LV #SN Attr   VSize   VFree\n  centos   1   2   0 wz--n- &lt;49.00g 4.00m\n\n# \u5c06\u5df2\u5b58\u5728\u7684vg \u6269\u5bb9\n&#91;root@localhost ~]# vgextenld centos \/dev\/vda3\n  Volume group \"centos\" successfully extended\n\n&#91;root@localhost ~]# vgs\n  VG     #PV #LV #SN Attr   VSize  VFree\n  centos   2   2   0 wz--n- 98.99g 50.00g\n\n# \u6269\u5bb9lv \n&#91;root@localhost ~]# lvextend -l  +100%FREE \/dev\/mapper\/centos-root\n  Size of logical volume centos\/root changed from &lt;45.12 GiB (11550 extents) to &lt;95.12 GiB (24350 extents).l\n  Logical volume centos\/root successfully resized.\n\n&#91;root@localhost ~]# lvs\n  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert\n  root centos -wi-ao---- &lt;95.12g\n  swap centos -wi-ao----  &lt;3.88g\n\n\n# lsblk \u67e5\u770b\u5df2\u7ecf\u6302\u8f7d\n&#91;root@localhost ~]# lsblk\nNAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT\nsr0              11:0    1 1024M  0 rom\nvda             252:0    0  100G  0 disk\n\u251c\u2500vda1          252:1    0    1G  0 part \/boot\n\u251c\u2500vda2          252:2    0   49G  0 part\n\u2502 \u251c\u2500centos-root 253:0    0 95.1G  0 lvm  \/\n\u2502 \u2514\u2500centos-swap 253:1    0  3.9G  0 lvm  &#91;SWAP]\n\u2514\u2500vda3          252:3    0   50G  0 part\n  \u2514\u2500centos-root 253:0    0 95.1G  0 lvm  \/\n\n# df \u67e5\u770b\u8fd8\u672a\u66f4\u65b0\n&#91;root@localhost ~]# df -h\nFilesystem               Size  Used Avail Use% Mounted on\ndevtmpfs                 1.9G     0  1.9G   0% \/dev\ntmpfs                    1.9G     0  1.9G   0% \/dev\/shm\ntmpfs                    1.9G  9.5M  1.9G   1% \/run\ntmpfs                    1.9G     0  1.9G   0% \/sys\/fs\/cgroup\n\/dev\/mapper\/centos-root   46G   32G   14G  70% \/\n\/dev\/vda1               1014M  150M  865M  15% \/boot\n\n\n# \u4f7f\u7528\u547d\u4ee4xfs_growfs \u66f4\u65b0\n\n&#91;root@localhost ~]# xfs_growfs \/dev\/mapper\/centos-root\nmeta-data=\/dev\/mapper\/centos-root isize=512    agcount=4, agsize=2956800 blks\n         =                       sectsz=512   attr=2, projid32bit=1\n         =                       crc=1        finobt=0 spinodes=0\ndata     =                       bsize=4096   blocks=11827200, imaxpct=25\n         =                       sunit=0      swidth=0 blks\nnaming   =version 2              bsize=4096   ascii-ci=0 ftype=1\nlog      =internal               bsize=4096   blocks=5775, version=2\n         =                       sectsz=512   sunit=0 blks, lazy-count=1\nrealtime =none                   extsz=4096   blocks=0, rtextents=0\ndata blocks changed from 11827200 to 24934400\n\n\n\n# \u6267\u884c\u5b8c\u6210\u540e \u6210\u529f\u66f4\u65b0\n\n&#91;root@localhost ~]# df -h\nFilesystem               Size  Used Avail Use% Mounted on\ndevtmpfs                 1.9G     0  1.9G   0% \/dev\ntmpfs                    1.9G     0  1.9G   0% \/dev\/shm\ntmpfs                    1.9G  9.5M  1.9G   1% \/run\ntmpfs                    1.9G     0  1.9G   0% \/sys\/fs\/cgroup\n\/dev\/mapper\/centos-root   96G   32G   64G  34% \/\n\/dev\/vda1               1014M  150M  865M  15% \/boot<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1.\u4f7f\u7528\u547d\u4ee4\u5c06qcow2 \u6587\u4ef6\u6269\u5bb9 2.\u6dfb\u52a0\u5b8c\u6210\u540e\u8fdb\u5165\u865a\u62df\u673a 3.\u5c06\u672a\u5206\u914d\u7684\u7a7a\u95f4\u8fdb\u884c\u521d\u59cb\u683c\u5f0f\u5316 4.\u4f7f\u7528lvm [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-18","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.yuuriso.cn\/index.php?rest_route=\/wp\/v2\/posts\/18","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yuuriso.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yuuriso.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yuuriso.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yuuriso.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=18"}],"version-history":[{"count":1,"href":"https:\/\/www.yuuriso.cn\/index.php?rest_route=\/wp\/v2\/posts\/18\/revisions"}],"predecessor-version":[{"id":19,"href":"https:\/\/www.yuuriso.cn\/index.php?rest_route=\/wp\/v2\/posts\/18\/revisions\/19"}],"wp:attachment":[{"href":"https:\/\/www.yuuriso.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yuuriso.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yuuriso.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}