{"id":87,"date":"2024-09-30T02:52:13","date_gmt":"2024-09-30T02:52:13","guid":{"rendered":"https:\/\/plantuml.cn\/?p=87"},"modified":"2024-09-30T02:52:14","modified_gmt":"2024-09-30T02:52:14","slug":"expanding-linux-disk-to-a-directory","status":"publish","type":"post","link":"https:\/\/plantuml.cn\/index.php\/2024\/09\/30\/expanding-linux-disk-to-a-directory\/","title":{"rendered":"Expanding linux disk to a directory"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Demand<\/h2>\n\n\n\n<p>To append <code>\/dev\/sda3 <\/code>to <code>\/home <\/code>, you need to mount the <code>\/dev\/sda3 <\/code>to a subdirectory under the <code>\/home <\/code>directory or merge the <code>\/dev\/sda3 <\/code>into an existing <code>\/home <\/code>partition. Here are the detailed steps for both methods:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method 1: Mount <code>\/dev\/sda3 <\/code>to a <code>\/home <\/code>subdirectory<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">Create a Mount Point directory<\/h4>\n\n\n\n<p>First, create a new directory under the <code>\/home <\/code>directory as Mount Point. For example, create a directory named <code>docker <\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mkdir \/home\/docker<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2. Mount <code>\/dev\/sda3<\/code><\/h4>\n\n\n\n<p>Use the <code>mount <\/code>command to mount <code>\/dev\/sda3 <\/code>to the newly created directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mount \/dev\/sda3 \/home\/docker<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">3. Edit <code>\/etc\/fstab <\/code>files<\/h4>\n\n\n\n<p>To ensure that the system automatically mounts the <code>\/dev\/sda3 <\/code>after a reboot, you need to edit the <code>\/etc\/fstab <\/code>file.<\/p>\n\n\n\n<p>Open the <code>\/etc\/fstab <\/code>file with your favorite text editor, such as <code>nano <\/code>or <code>vim <\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/fstab<\/code><\/pre>\n\n\n\n<p>Add the following line at the end of the file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/dev\/sda3 \/home\/docker ext4 defaults 0 0<\/code><\/pre>\n\n\n\n<p>Save and close the file.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">4. Confirm successful mounting<\/h4>\n\n\n\n<p>Use the <code>df -h <\/code>command to confirm that <code>\/dev\/sda3 <\/code>has been successfully mounted to the <code>\/home\/docker <\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>df -h<\/code><\/pre>\n\n\n\n<p>The output should contain <code>\/dev\/sda3 <\/code>Mount Point.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method 2: Merge <code>\/dev\/sda3 <\/code>into an existing <code>\/home <\/code>partition<\/h2>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Confirm if<\/strong> <strong><code>\/dev\/sda3<\/code><\/strong> <strong>have been merged<\/strong><\/li>\n<\/ol>\n\n\n\n<p>First, confirm that the <code>\/dev\/sda3 <\/code>have been merged into the <code>\/dev\/mapper\/centos-home <\/code>. You can use the <code>pvs <\/code>and <code>vgs <\/code>commands to view information about physical volumes and volume groups.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo pvs\nsudo vgs<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"934\" height=\"168\" src=\"https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-3.png\" alt=\"\" class=\"wp-image-92\" srcset=\"https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-3.png 934w, https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-3-300x54.png 300w, https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-3-768x138.png 768w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n\n\n\n<p>From the output of <code>pvs <\/code>and <code>vgs <\/code>, <code>\/dev\/sda2 <\/code>is the only physical volume (PV), and it has been fully allocated to the volume group (VG) <code>centos <\/code>. This means that <code>\/dev\/sda3 <\/code>is not included in the <code>centos <\/code>volume group.<\/p>\n\n\n\n<p>Since <code>\/dev\/sda3 <\/code>is not included in the <code>centos <\/code>volume group, you need to add it to the volume group and then expand <code>\/home <\/code>logical volume.<\/p>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>Add <code>\/dev\/sda3 <\/code>to <code>centos <\/code>volume group<\/li>\n<\/ol>\n\n\n\n<p>First, use the <code>pvcreate <\/code>command to initialize the <code>\/dev\/sda3 <\/code>to a physical volume:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo pvcreate \/dev\/sda3<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1018\" height=\"87\" src=\"https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-1.png\" alt=\"\" class=\"wp-image-89\" srcset=\"https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-1.png 1018w, https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-1-300x26.png 300w, https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-1-768x66.png 768w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n\n\n\n<p>Then, use the <code>vgextend <\/code>command to add <code>\/dev\/sda3 <\/code>to the <code>centos <\/code>volume group:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo vgextend centos \/dev\/sda3<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1104\" height=\"103\" src=\"https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-6.png\" alt=\"\" class=\"wp-image-94\" srcset=\"https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-6.png 1104w, https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-6-300x28.png 300w, https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-6-1024x96.png 1024w, https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-6-768x72.png 768w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li>Extended <code>\/home <\/code>Logical Volume<\/li>\n<\/ol>\n\n\n\n<p>Now you can use the <code>lvextend <\/code>command to add <code>\/dev\/sda3 <\/code>space to <code>\/home <\/code>logical volume:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo lvextend -l +100%FREE \/dev\/mapper\/centos-home<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1131\" height=\"73\" src=\"https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image.png\" alt=\"\" class=\"wp-image-88\" srcset=\"https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image.png 1131w, https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-300x19.png 300w, https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-1024x66.png 1024w, https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-768x50.png 768w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li>Extended file system<\/li>\n<\/ol>\n\n\n\n<p>Use the <code>resize2fs <\/code>command to extend the file system:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo resize2fs \/dev\/mapper\/centos-home<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1151\" height=\"106\" src=\"https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-5.png\" alt=\"\" class=\"wp-image-93\" srcset=\"https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-5.png 1151w, https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-5-300x28.png 300w, https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-5-1024x94.png 1024w, https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-5-768x71.png 768w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n\n\n\n<p>From the error message, the <code>resize2fs <\/code>command cannot find a valid filesystem superblock for the <code>\/dev\/mapper\/centos-home <\/code>. This usually means that there is no correct filesystem on the <code>\/dev\/mapper\/centos-home <\/code>, or that the filesystem is corrupted.<\/p>\n\n\n\n<ol start=\"5\" class=\"wp-block-list\">\n<li><strong>Confirm file system type<\/strong><\/li>\n<\/ol>\n\n\n\n<p>Use the <code>blkid <\/code>command to check <code>\/dev\/mapper\/centos-home <\/code>filesystem type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo blkid \/dev\/mapper\/centos-home<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"836\" height=\"48\" src=\"https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-4.png\" alt=\"\" class=\"wp-image-91\" srcset=\"https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-4.png 836w, https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-4-300x17.png 300w, https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-4-768x44.png 768w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/figure>\n\n\n\n<p>As you can see from <code>blkid <\/code>&#8216;s output, the filesystem type on the <code>\/dev\/mapper\/centos-home <\/code>is <code>xfs <\/code>, not <code>ext4 <\/code>. Therefore, you need to use the <code>xfs_growfs <\/code>command to extend the <code>xfs <\/code>filesystem, not <code>resize2fs <\/code>.<\/p>\n\n\n\n<ol start=\"6\" class=\"wp-block-list\">\n<li>Extend the <code>xfs <\/code>file system using <code>xfs_growfs <\/code>commands<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo xfs_growfs \/dev\/mapper\/centos-home<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"857\" height=\"215\" src=\"https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-7.png\" alt=\"\" class=\"wp-image-95\" srcset=\"https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-7.png 857w, https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-7-300x75.png 300w, https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-7-768x193.png 768w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n\n\n\n<ol start=\"7\" class=\"wp-block-list\">\n<li>Confirm expansion successful<\/li>\n<\/ol>\n\n\n\n<p>Use the <code>df -h <\/code>command to confirm that the size of the <code>\/home <\/code>partition has increased:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>df -h<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1087\" height=\"193\" src=\"https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-2.png\" alt=\"\" class=\"wp-image-90\" srcset=\"https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-2.png 1087w, https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-2-300x53.png 300w, https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-2-1024x182.png 1024w, https:\/\/plantuml.cn\/wp-content\/uploads\/2024\/09\/image-2-768x136.png 768w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Demand To append \/dev\/sda3 to \/home , you need to mount &hellip; <a href=\"https:\/\/plantuml.cn\/index.php\/2024\/09\/30\/expanding-linux-disk-to-a-directory\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cExpanding linux disk to a directory\u201d<\/span><\/a><\/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-87","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/plantuml.cn\/index.php\/wp-json\/wp\/v2\/posts\/87"}],"collection":[{"href":"https:\/\/plantuml.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/plantuml.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/plantuml.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/plantuml.cn\/index.php\/wp-json\/wp\/v2\/comments?post=87"}],"version-history":[{"count":1,"href":"https:\/\/plantuml.cn\/index.php\/wp-json\/wp\/v2\/posts\/87\/revisions"}],"predecessor-version":[{"id":96,"href":"https:\/\/plantuml.cn\/index.php\/wp-json\/wp\/v2\/posts\/87\/revisions\/96"}],"wp:attachment":[{"href":"https:\/\/plantuml.cn\/index.php\/wp-json\/wp\/v2\/media?parent=87"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/plantuml.cn\/index.php\/wp-json\/wp\/v2\/categories?post=87"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/plantuml.cn\/index.php\/wp-json\/wp\/v2\/tags?post=87"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}