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..b8884ed --- /dev/null +++ b/34_WSL/FIXING_DISKS.md @@ -0,0 +1,80 @@ +# FIXING DISKS + +Information on checking and fixing vhd disks for distros. + +## 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="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 +``` + +## 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 +``` + +## 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/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 + +* 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 +* 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/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` diff --git a/34_WSL/SECOND_DISK.md b/34_WSL/SECOND_DISK.md new file mode 100644 index 0000000..ba3ae43 --- /dev/null +++ b/34_WSL/SECOND_DISK.md @@ -0,0 +1,96 @@ +# 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)" + +# list drives +diskmgmt +# or +GET-CimInstance -query "SELECT * from Win32_DiskDrive" + +# 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 rw /dev/sdd1 ./code +# change ownership of folder to prevent read-only +sudo chown -R ${USER}:chrisguest ./code +``` + +## Umount (inside WSL) + +```sh +umount ./code +``` + +## 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 "${HOME}\Documents\WSLDistros\imported\${DISTRO_NAME}\code.vhdx" +``` + + +## Resources + +* 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 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