1"use strict";(self.webpackChunkharvesterhci_io=self.webpackChunkharvesterhci_io||[]).push([[5309],{3905:function(e,t,n){n.d(t,{Zo:function(){return c},kt:function(){return m}});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?i(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function l(e,t){if(null==e)return{};var n,a,r=function(e,t){if(null==e)return{};var n,a,r={},i=Object.keys(e);for(a=0;a<i.length;a++)n=i[a],t.indexOf(n)>=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(a=0;a<i.length;a++)n=i[a],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var s=a.createContext({}),p=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},c=function(e){var t=p(e.components);return a.createElement(s.Provider,{value:t},e.children)},d={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},u=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,i=e.originalType,s=e.parentName,c=l(e,["components","mdxType","originalType","parentName"]),u=p(n),m=r,h=u["".concat(s,".").concat(m)]||u[m]||d[m]||i;return n?a.createElement(h,o(o({ref:t},c),{},{components:n})):a.createElement(h,o({ref:t},c))}));function m(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var i=n.length,o=new Array(i);o[0]=u;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l.mdxType="string"==typeof e?e:r,o[1]=l;for(var p=2;p<i;p++)o[p]=n[p];return a.createElement.apply(null,o)}return a.createElement.apply(null,n)}u.displayName="MDXCreateElement"},8696:function(e,t,n){n.r(t),n.d(t,{assets:function(){return c},contentTitle:function(){return s},default:function(){return m},frontMatter:function(){return l},metadata:function(){return p},toc:function(){return d}});var a=n(7462),r=n(3366),i=(n(7294),n(3905)),o=["components"],l={title:"Scan and Repair Root Filesystem of VirtualMachine",description:"Scan and repair root filesystem of VM",slug:"scan-and-repair-vm-root-filesystem",authors:[{name:"Vicente Cheng",title:"Senior Software Engineer",url:"https://github.com/Vicente-Cheng",image_url:"https://github.com/Vicente-Cheng.png"}],tags:["storage","longhorn","root","filesystem"],hide_table_of_contents:!1},s=void 0,p={permalink:"/kb/scan-and-repair-vm-root-filesystem",editUrl:"https://github.com/harvester/harvesterhci.io/edit/main/kb/2023-02-01/scan_and_repair_filesystem.md",source:"@site/kb/2023-02-01/scan_and_repair_filesystem.md",title:"Scan and Repair Root Filesystem of VirtualMachine",description:"Scan and repair root filesystem of VM",date:"2023-02-01T00:00:00.000Z",formattedDate:"February 1, 2023",tags:[{label:"storage",permalink:"/kb/tags/storage"},{label:"longhorn",permalink:"/kb/tags/longhorn"},{label:"root",permalink:"/kb/tags/root"},{label:"filesystem",permalink:"/kb/tags/filesystem"}],readingTime:3.37,truncated:!1,authors:[{name:"Vicente Cheng",title:"Senior Software Engineer",url:"https://github.com/Vicente-Cheng",image_url:"https://github.com/Vicente-Cheng.png",imageURL:"https://github.com/Vicente-Cheng.png"}],frontMatter:{title:"Scan and Repair Root Filesystem of VirtualMachine",description:"Scan and repair root filesystem of VM",slug:"scan-and-repair-vm-root-filesystem",authors:[{name:"Vicente Cheng",title:"Senior Software Engineer",url:"https://github.com/Vicente-Cheng",image_url:"https://github.com/Vicente-Cheng.png",imageURL:"https://github.com/Vicente-C
1heng.png"}],tags:["storage","longhorn","root","filesystem"],hide_table_of_contents:!1},prevItem:{title:"Package your own Toolbox Image",permalink:"/kb/package_your_own_toolbox_image"},nextItem:{title:"Evicting Replicas From a Disk (the CLI way)",permalink:"/kb/evicting-replicas-from-a-disk-the-cli-way"}},c={authorsImageUrls:[void 0]},d=[{value:"Stop The VM And Backup Volume",id:"stop-the-vm-and-backup-volume",level:2},{value:"Scanning the root filesystem and repairing",id:"scanning-the-root-filesystem-and-repairing",level:2},{value:"XFS",id:"xfs",level:3},{value:"EXT4",id:"ext4",level:3},{value:"Detach and Start VM again.",id:"detach-and-start-vm-again",level:2}],u={toc:d};function m(e){var t=e.components,l=(0,r.Z)(e,o);return(0,i.kt)("wrapper",(0,a.Z)({},u,l,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("p",null,"In earlier versions of Harvester (v1.0.3 and prior), Longhorn volumes may get corrupted during the replica rebuilding process (reference: ",(0,i.kt)("a",{parentName:"p",href:"https://longhorn.io/kb/troubleshooting-volume-filesystem-corruption/#solution"},"Analysis: Potential Data/Filesystem Corruption"),"). In Harvester v1.1.0 and later versions, the Longhorn team has fixed this issue. This article covers manual steps you can take to scan the VM's filesystem and repair it if needed."),(0,i.kt)("h2",{id:"stop-the-vm-and-backup-volume"},"Stop The VM And Backup Volume"),(0,i.kt)("p",null,"Before you scan the filesystem, it is recommend you back up the volume first. For an example, refer to the following steps to stop the VM and backup the volume."),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Find the target VM.")),(0,i.kt)("p",null,(0,i.kt)("img",{loading:"lazy",alt:"finding the target VM",src:n(8083).Z,width:"2560",height:"880"})),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Stop the target VM.")),(0,i.kt)("p",null,(0,i.kt)("img",{loading:"lazy",alt:"Stop the target VM",src:n(3719).Z,width:"2546",height:"856"})),(0,i.kt)("p",null,"The target VM is stopped and the related volumes are detached. Now go to the Longhorn UI to backup this volume."),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Enable ",(0,i.kt)("inlineCode",{parentName:"li"},"Developer Tools & Features")," (Preferences -> Enable Developer Tools & Features).")),(0,i.kt)("p",null,(0,i.kt)("img",{loading:"lazy",alt:"Preferences then enable developer mode",src:n(6727).Z,width:"2570",height:"1090"}),"\n",(0,i.kt)("img",{loading:"lazy",alt:"Enable the developer mode",src:n(395).Z,width:"2760",height:"350"})),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Click the ",(0,i.kt)("inlineCode",{parentName:"li"},"\u22ee")," button and select ",(0,i.kt)("strong",{parentName:"li"},"Edit Config")," to edit the config page of the VM.")),(0,i.kt)("p",null,(0,i.kt)("img",{loading:"lazy",alt:"goto edit config page of VM",src:n(8166).Z,width:"2526",height:"964"})),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Go to the ",(0,i.kt)("inlineCode",{parentName:"li"},"Volumes")," tab and select ",(0,i.kt)("inlineCode",{parentName:"li"},"Check volume details."))),(0,i.kt)("p",null,(0,i.kt)("img",{loading:"lazy",alt:"link to longhorn volume page",src:n(2713).Z,width:"2522",height:"1372"})),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Click the dropdown menu on the right side and select 'Attach' to attach the volume again. ")),(0,i.kt)("p",null,(0,i.kt)("img",{loading:"lazy",alt:"attach this volume again",src:n(6592).Z,width:"2972",height:"1358"})),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Select the attached node. ")),(0,i.kt)("p",null,(0,i.kt)("img",{loading:"lazy",alt:"choose the attached node",src:n(6694).Z,width:"2964",height:"1362"})),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Check the volume attached under ",(0,i.kt)("inlineCode",{parentName:"li"},"Volume Details")," and select ",(0,i.kt)("inlineCode",{parentName:"li"},"Take Snapshot")," on this volume page.")),(0,i.kt)("p",null,(0,i.kt)("img",{loading:"lazy",alt:"take snapshot on volume page",src:n(8663).Z,width:"2976",height:"1358"})),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Confirm that the snapshot is ready.")),(0,i.kt)("p",null,(0,i.kt)("img",{loading:"lazy",alt:"check the snapshot is ready",src:n(3009).Z,width:"2968",height:"1356"})),(0,i.kt)("p",null,"Now that you completed the volume backup, you need to scan and repair the root filesystem."),(0,i.kt)("h2",{id:"scanning-the-root-filesystem-and-repairing"},"Scanning the root filesystem and repairing"),(0,i.kt)("p",null,"This section will introduce how to scan the filesystem (e.g., XFS, EXT4) using related tools."),(0,i.kt)("p",null,"Before scanning, you need to know the filesystem's device/partition."),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Identify the filesystem's device by checking the major and minor numbers of that device.")),(0,i.kt)("ol",null,(0,i.kt)("li",{parentName:"ol"},(0,i.kt)("p",{parentName:"li"},"Obtain the major and minor numbers from the listed volume information."),(0,i.kt)("p",{parentName:"li"},"In the following example, the volume name is ",(0,i.kt)("inlineCode",{parentName:"p"},"pvc-ea7536c0-301f-479e-b2a2-e40ddc864b58"),"."),(0,i.kt)("pre",{parentName:"li"},(0,i.kt)("code",{parentName:"pre"},"harvester-node-0:~ # ls /dev/longhorn/pvc-ea7536c0-301f-479e-b2a2-e40ddc864b58 -al\nbrw-rw---- 1 root root 8, 0 Oct 23 14:43 /dev/longhorn/pvc-ea7536c0-301f-479e-b2a2-e40ddc864b58\n")),(0,i.kt)("p",{parentName:"li"},"The output indicates that the major and minor numbers are ",(0,i.kt)("inlineCode",{parentName:"p"},"8:0"),".")),(0,i.kt)("li",{parentName:"ol"},(0,i.kt)("p",{parentName:"li"},"Obtain the device name from the output of the ",(0,i.kt)("inlineCode",{parentName:"p"},"lsblk")," command."),(0,i.kt)("pre",{parentName:"li"},(0,i.kt)("code",{parentName:"pre"},"harvester-node-0:~ # lsblk\nNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS\nloop0 7:0 0 3G 1 loop /\nsda 8:0 0 40G 0 disk\n\u251c\u2500sda1 8:1 0 2M 0 part\n\u251c\u2500sda2 8:2 0 20M 0 part\n\u2514\u2500sda3 8:3 0 40G 0 part\n")),(0,i.kt)("p",{parentName:"li"},"The output indicates that ",(0,i.kt)("inlineCode",{parentName:"p"},"8:0")," are the major and minor numbers of the device named ",(0,i.kt)("inlineCode",{parentName:"p"},"sda"),". Therefore, ",(0,i.kt)("inlineCode",{parentName:"p"},"/dev/sda")," is related to the volume named ",(0,i.kt)("inlineCode",{parentName:"p"},"pvc-ea7536c0-301f-479e-b2a2-e40ddc864b58"),"."))),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"You should now know the filesystem's partition. In the example below, sda3 is the filesystem's partition."),(0,i.kt)("li",{parentName:"ul"},"Use the Filesystem toolbox image to scan and repair.")),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"# docker run -it --rm --privileged registry.opensuse.org/isv/rancher/harvester/toolbox/main/fs-toolbox:latest -- bash\n")),(0,i.kt)("p",null,"Then we try to scan with this target device."),(0,i.kt)("h3",{id:"xfs"},"XFS"),(0,i.kt)("p",null,"When scanning an XFS filesystem, use the ",(0,i.kt)("inlineCode",{parentName:"p"},"xfs_repair")," command and specify the problematic partition of the device."),(0,i.kt)("p",null,"In the following example, ",(0,i.kt)("inlineCode",{parentName:"p"},"/dev/sda3")," is the problematic partition."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"# xfs_repair -n /dev/sda3\n")),(0,i.kt)("p",null,"To repair the corrupted partition, run the following command."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"# xfs_repair /dev/sda3\n")),(0,i.kt)("h3",{id:"ext4"},"EXT4"),(0,i.kt)("p",null,"When scanning a EXT4 filesystem, use the ",(0,i.kt)("inlineCode",{parentName:"p"},"e2fsck")," command as follows, where the ",(0,i.kt)("inlineCode",{parentName:"p"},"/dev/sde1")," is the problematic partition of the device."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"# e2fsck -f /dev/sde1\n")),(0,i.kt)("p",null,"To repair the corrupted partition, run the following command."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"# e2fsck -fp /dev/sde1\n")),(0,i.kt)("p",null,"After using the 'e2fsck' command, you should also see logs related to scanning and repairing the partition. Scanning and repairing the corrupted partition is successful if there are no errors in these logs. "),(0,i.kt)("h2",{id:"detach-and-start-vm-again"},"Detach and Start VM again."),(0,i.kt)("p",null,"After the corrupted partition is scanned and repaired, detach the volume and try to
1start the related VM again."),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Detach the volume from the Longhorn UI.")),(0,i.kt)("p",null,(0,i.kt)("img",{loading:"lazy",alt:"detach volume on longhorn UI",src:n(4864).Z,width:"2964",height:"1364"})),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Start the related VM again from the Harvester UI.")),(0,i.kt)("p",null,(0,i.kt)("img",{loading:"lazy",alt:"Start VM again",src:n(5505).Z,width:"2540",height:"854"})),(0,i.kt)("p",null,"Your VM should now work normally."))}m.isMDXComponent=!0},6592:function(e,t,n){t.Z=n.p+"assets/images/attach_this_volume_again-f008c1d56b9cdfa2b141e30093cc51fe.png"},3009:function(e,t,n){t.Z=n.p+"assets/images/check_the_snapshot_is_ready-7f0716b1b699c668c11ad5b5b46596b0.png"},6694:function(e,t,n){t.Z=n.p+"assets/images/choose_the_attached_node-cde38647a09abf50189b40f5a37da9cb.png"},4864:function(e,t,n){t.Z=n.p+"assets/images/detach_volume-a71a0c79f0a6052fd5ecb562bf532b71.png"},395:function(e,t,n){t.Z=n.p+"assets/images/enable_the_developer_mode-8dffb1796b8e5da9863d6c69ad7f0209.png"},8083:function(e,t,n){t.Z=n.p+"assets/images/finding_the_target_vm-c3f5c227fdeda94499a32e880a302e80.png"},8166:function(e,t,n){t.Z=n.p+"assets/images/goto_vm_edit_config_page-52e958d3a5e04c912e77615d3ab05616.png"},2713:function(e,t,n){t.Z=n.p+"assets/images/link_to_longhorn_volume-ced67ce270fd55fa7ff5a73c651ae940.png"},6727:function(e,t,n){t.Z=n.p+"assets/images/preferences_enable_developer_mode-1379680f02f9980091177736ed7ce523.png"},5505:function(e,t,n){t.Z=n.p+"assets/images/start_vm_again-6ce38c23de061f1587da9e4f8698b7e8.png"},3719:function(e,t,n){t.Z=n.p+"assets/images/stop_the_target_vm-35b68914885fd42f4b7310aa849f944f.png"},8663:function(e,t,n){t.Z=n.p+"assets/images/take_snapshot_on_volume_page-fe966d238b47aea3360b6f5c55664846.png"}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.