From 7559967386066178724974aff62c7e11f16d20ce Mon Sep 17 00:00:00 2001 From: Christopher Guest Date: Tue, 21 Jan 2025 18:19:25 +0000 Subject: [PATCH 1/6] feat(wsl): :sparkles: Disk corruption and how to fix it --- .vscode/extensions.json | 12 ++++++++++++ 34_WSL/FIXING_DISKS.md | 25 +++++++++++++++++++++++++ TODO.md | 1 + 3 files changed, 38 insertions(+) create mode 100644 .vscode/extensions.json create mode 100644 34_WSL/FIXING_DISKS.md diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..922a079 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,12 @@ +{ + "recommendations": [ + "davidanson.vscode-markdownlint", + "vivaxy.vscode-conventional-commits", + "docsmsft.docs-markdown", + "yzhang.markdown-all-in-one", + "bierner.github-markdown-preview", + "bierner.markdown-preview-github-styles", + "bierner.markdown-mermaid", + "qcz.text-power-tools" + ] +} \ No newline at end of file diff --git a/34_WSL/FIXING_DISKS.md b/34_WSL/FIXING_DISKS.md new file mode 100644 index 0000000..318cb38 --- /dev/null +++ b/34_WSL/FIXING_DISKS.md @@ -0,0 +1,25 @@ +# FIXING DISKS + +Information on checking and fixing vhd disks for distros. + +## Locate Disks + +Use powershell to go through the disks. + +```ps +wsl --list --verbose + +(Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq '2025_22_04_distro' }).GetValue("BasePath") + "\ext4.vhdx" + +ls C:\Users\chris\Documents\WSLDistros\imported\2025_22_04_distro\ext4.vhdx +``` + +## + +## Resources + +* https://www.reddit.com/r/linuxquestions/comments/pj3s24/run_fsck_towards_a_physical_partition_through_wsl/?rdt=65500 +* https://learn.microsoft.com/en-us/windows/wsl/wsl2-mount-disk +* https://unix.stackexchange.com/questions/766981/ubuntu-file-system-read-only-after-windows-system-restore-at-previous-point +* https://anthony-f-tannous.medium.com/wsl2-how-to-prepare-and-attach-virtual-drives-vhd-ac17b1fc7a61 + diff --git a/TODO.md b/TODO.md index 61ad4c8..db14335 100644 --- a/TODO.md +++ b/TODO.md @@ -15,3 +15,4 @@ * lynis hardening * x11 * wsl webcam https://askubuntu.com/questions/1405903/capturing-webcam-video-with-opencv-in-wsl2 +* https://github.com/DDoSolitary/LxRunOffline From e23fc7ddfb7a7ead0d390cda41e88686ce2d9bdb Mon Sep 17 00:00:00 2001 From: Christopher Guest Date: Tue, 21 Jan 2025 20:08:03 +0000 Subject: [PATCH 2/6] feat(wsl): :sparkles: Add set default distro instructions --- 34_WSL/INSTALL_DISTRO.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/34_WSL/INSTALL_DISTRO.md b/34_WSL/INSTALL_DISTRO.md index 1b802bf..7d03e02 100644 --- a/34_WSL/INSTALL_DISTRO.md +++ b/34_WSL/INSTALL_DISTRO.md @@ -74,6 +74,7 @@ ls "${HOME}\Documents\WSLDistros\rootfs" ```powershell $DISTRO_NAME = "work_22_04_distro" $DISTRO_NAME = "kernel_build_distro" +$DISTRO_NAME = "2025work_22_04_distro" # 23.10 $ROOT_FS_ZIP = "ubuntu-mantic-wsl-amd64-wsl.rootfs.tar.gz" @@ -116,6 +117,9 @@ wsl --terminate ${DISTRO_NAME} # look a running status wsl --list --verbose +# set default distro in wsl +wsl --set-default ${DISTRO_NAME} + # backup (this seems to signal the distro to shutdown then fails.) # NOTE: This seems to be run inside a cmd prompt and then run pwsh - otherwise you get Error code: Wsl/Service/ERROR_SHARING_VIOLATION. # NOTE: I also got this working by performing `wsl --shutdown` From 9250e3d1b4a05f5f8235b5a019ea71b017597505 Mon Sep 17 00:00:00 2001 From: Christopher Guest Date: Tue, 21 Jan 2025 21:01:54 +0000 Subject: [PATCH 3/6] feat(wsl): :sparkles: Testing mounting a code drive --- 34_WSL/SECOND_DISK.md | 83 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 34_WSL/SECOND_DISK.md diff --git a/34_WSL/SECOND_DISK.md b/34_WSL/SECOND_DISK.md new file mode 100644 index 0000000..c14ad6f --- /dev/null +++ b/34_WSL/SECOND_DISK.md @@ -0,0 +1,83 @@ +# SECOND DISKS + +Add second drives for managing codebases away from root drive. + +## Create + +```powershell +# in admin powerhsell +$DISTRO_NAME = "2025work_24_04_distro" +New-VHD "${HOME}\Documents\WSLDistros\imported\${DISTRO_NAME}\code.vhdx" -SizeBytes 200GB -Dynamic -BlockSizeBytes 1MB +``` + +## Mount on Host + +```powershell +# in admin powershell +Write-Output "\\.\PhysicalDrive$((Mount-VHD -Path "${HOME}\Documents\WSLDistros\imported\${DISTRO_NAME}\code.vhdx" -PassThru | Get-Disk).Number)" + +diskmgmt + +# physical drive number comes from command before +wsl --mount \\.\PhysicalDrive1 --bare +``` + +## WSL + +```sh +# enter wsl +wsl + +# look for drive matching size. +lsblk +# you should be able to see the drive being mounted +dmesg +``` + +## Partition + +```sh +# elevate +sudo -i + +fdisk /dev/sdf + +# new GPT partition +g +# new parition +n +# write and exit +w +``` + +## Format + +```sh +mkfs.ext4 -G 4096 /dev/sdf1 +mkdir ./code +``` + +## Mount + +```sh +mount -o remount,rw /dev/sdf1 ./code +``` + +## UNMOUNT + +```sh +umount ./code +``` + + +```powershell +wsl --unmount \\.\PhysicalDriveX + +#To detach it completely (eg. if you want to (re)move the file) +Dismount-VHD support.vhdx +``` + + +## Resources + +* https://gist.github.com/lseongjoo/d38b29fdbd5c082880576d0c34f7593e \ No newline at end of file From 26d68e6729748e43b696221b4cfc1e52f5fb65c0 Mon Sep 17 00:00:00 2001 From: Christopher Guest Date: Tue, 21 Jan 2025 21:40:20 +0000 Subject: [PATCH 4/6] feat: :sparkles: Second disk works and is mounted correctly --- 34_WSL/FIXING_DISKS.md | 27 +++++++++++++++++++++++---- 34_WSL/SECOND_DISK.md | 13 ++++++++++--- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/34_WSL/FIXING_DISKS.md b/34_WSL/FIXING_DISKS.md index 318cb38..16c4e7f 100644 --- a/34_WSL/FIXING_DISKS.md +++ b/34_WSL/FIXING_DISKS.md @@ -6,15 +6,34 @@ Information on checking and fixing vhd disks for distros. Use powershell to go through the disks. -```ps +```powershell wsl --list --verbose -(Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq '2025_22_04_distro' }).GetValue("BasePath") + "\ext4.vhdx" +$location=(Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq '2025_22_04_distro' }).GetValue("BasePath") + "\ext4.vhdx" -ls C:\Users\chris\Documents\WSLDistros\imported\2025_22_04_distro\ext4.vhdx +echo $location ``` -## +## Mount on Host + +```powershell +# in admin powershell +Write-Output "\\.\PhysicalDrive$((Mount-VHD -Path "$location" -PassThru | Get-Disk).Number)" + +# list drives +diskmgmt +# or +GET-CimInstance -query "SELECT * from Win32_DiskDrive" + +# physical drive number comes from command before +wsl --mount \\.\PhysicalDrive1 --bare +``` + +## Fix + +```sh +sudo e2fsck -f /dev/sdf1 +``` ## Resources diff --git a/34_WSL/SECOND_DISK.md b/34_WSL/SECOND_DISK.md index c14ad6f..d5fc1f4 100644 --- a/34_WSL/SECOND_DISK.md +++ b/34_WSL/SECOND_DISK.md @@ -16,7 +16,10 @@ New-VHD "${HOME}\Documents\WSLDistros\imported\${DISTRO_NAME}\code.vhdx" -SizeBy # in admin powershell Write-Output "\\.\PhysicalDrive$((Mount-VHD -Path "${HOME}\Documents\WSLDistros\imported\${DISTRO_NAME}\code.vhdx" -PassThru | Get-Disk).Number)" +# list drives diskmgmt +# or +GET-CimInstance -query "SELECT * from Win32_DiskDrive" # physical drive number comes from command before wsl --mount \\.\PhysicalDrive1 --bare @@ -60,10 +63,12 @@ mkdir ./code ## Mount ```sh -mount -o remount,rw /dev/sdf1 ./code +mount -o rw /dev/sdf1 ./code +# change ownership of folder to prevent read-only +sudo chown -R ${USER}:chrisguest ./code ``` -## UNMOUNT +## Umount ```sh umount ./code @@ -80,4 +85,6 @@ Dismount-VHD support.vhdx ## Resources -* https://gist.github.com/lseongjoo/d38b29fdbd5c082880576d0c34f7593e \ No newline at end of file +* https://gist.github.com/lseongjoo/d38b29fdbd5c082880576d0c34f7593e +* https://learn.microsoft.com/en-us/windows/wsl/wsl2-mount-disk +* https://learn.microsoft.com/en-us/windows/wsl/disk-space \ No newline at end of file From 44068e2392e74b9b164af99eeac7e74b92a9a4b1 Mon Sep 17 00:00:00 2001 From: Christopher Guest Date: Tue, 21 Jan 2025 22:13:59 +0000 Subject: [PATCH 5/6] docs(wsl): :sparkles: Fixed my first VHD. --- 34_WSL/FIXING_DISKS.md | 31 +++++++++++++++++++++++++++++-- 34_WSL/SECOND_DISK.md | 12 +++++++++--- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/34_WSL/FIXING_DISKS.md b/34_WSL/FIXING_DISKS.md index 16c4e7f..9e634a1 100644 --- a/34_WSL/FIXING_DISKS.md +++ b/34_WSL/FIXING_DISKS.md @@ -9,7 +9,8 @@ Use powershell to go through the disks. ```powershell wsl --list --verbose -$location=(Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq '2025_22_04_distro' }).GetValue("BasePath") + "\ext4.vhdx" +$DISTRO_NAME="Ubuntu-24.04" +$location=(Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq "$DISTRO_NAME" }).GetValue("BasePath") + "\ext4.vhdx" echo $location ``` @@ -29,10 +30,36 @@ GET-CimInstance -query "SELECT * from Win32_DiskDrive" wsl --mount \\.\PhysicalDrive1 --bare ``` +## WSL + +```sh +# enter wsl +wsl + +# look for drive matching size. +lsblk +# you should be able to see the drive being mounted +dmesg +``` + ## Fix ```sh -sudo e2fsck -f /dev/sdf1 +sudo e2fsck -f /dev/sdd +``` + +## Host Powershell + +```powershell +wsl --unmount \\.\PhysicalDrive1 + +# list drives +diskmgmt +# or +GET-CimInstance -query "SELECT * from Win32_DiskDrive" + +#To detach it completely (eg. if you want to (re)move the file) +Dismount-VHD "${location}" ``` ## Resources diff --git a/34_WSL/SECOND_DISK.md b/34_WSL/SECOND_DISK.md index d5fc1f4..3226dea 100644 --- a/34_WSL/SECOND_DISK.md +++ b/34_WSL/SECOND_DISK.md @@ -68,18 +68,24 @@ mount -o rw /dev/sdf1 ./code sudo chown -R ${USER}:chrisguest ./code ``` -## Umount +## Umount (inside WSL) ```sh umount ./code ``` +## Host Powershell ```powershell -wsl --unmount \\.\PhysicalDriveX +wsl --unmount \\.\PhysicalDrive1 + +# list drives +diskmgmt +# or +GET-CimInstance -query "SELECT * from Win32_DiskDrive" #To detach it completely (eg. if you want to (re)move the file) -Dismount-VHD support.vhdx +Dismount-VHD "${HOME}\Documents\WSLDistros\imported\${DISTRO_NAME}\code.vhdx" ``` From c297e8b32d43fc4c159c60b39d0b6c6d34f85599 Mon Sep 17 00:00:00 2001 From: Christopher Guest Date: Tue, 21 Jan 2025 22:49:19 +0000 Subject: [PATCH 6/6] feat: :memo: Still got issues repairing a corrupted disk --- 34_WSL/FIXING_DISKS.md | 15 ++++++++++++--- 34_WSL/SECOND_DISK.md | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/34_WSL/FIXING_DISKS.md b/34_WSL/FIXING_DISKS.md index 9e634a1..b8884ed 100644 --- a/34_WSL/FIXING_DISKS.md +++ b/34_WSL/FIXING_DISKS.md @@ -2,14 +2,23 @@ Information on checking and fixing vhd disks for distros. -## Locate Disks +## Windows VHD Tools + +```sh +chkdsk + +# checks if windows components are corrupted. +dism /Online /Cleanup-Image /ScanHealth +``` + +## Locate VHDX Disks Use powershell to go through the disks. ```powershell wsl --list --verbose -$DISTRO_NAME="Ubuntu-24.04" +$DISTRO_NAME="2025_22_04_distro" $location=(Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq "$DISTRO_NAME" }).GetValue("BasePath") + "\ext4.vhdx" echo $location @@ -68,4 +77,4 @@ Dismount-VHD "${location}" * https://learn.microsoft.com/en-us/windows/wsl/wsl2-mount-disk * https://unix.stackexchange.com/questions/766981/ubuntu-file-system-read-only-after-windows-system-restore-at-previous-point * https://anthony-f-tannous.medium.com/wsl2-how-to-prepare-and-attach-virtual-drives-vhd-ac17b1fc7a61 - +* https://www.linkedin.com/pulse/how-repair-unreadable-corrupt-vhd-vhdx-file-cigati-solutions-qfhuf/ \ No newline at end of file diff --git a/34_WSL/SECOND_DISK.md b/34_WSL/SECOND_DISK.md index 3226dea..ba3ae43 100644 --- a/34_WSL/SECOND_DISK.md +++ b/34_WSL/SECOND_DISK.md @@ -63,7 +63,7 @@ mkdir ./code ## Mount ```sh -mount -o rw /dev/sdf1 ./code +mount -o rw /dev/sdd1 ./code # change ownership of folder to prevent read-only sudo chown -R ${USER}:chrisguest ./code ```