Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
80 changes: 80 additions & 0 deletions 34_WSL/FIXING_DISKS.md
Original file line number Diff line number Diff line change
@@ -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/
4 changes: 4 additions & 0 deletions 34_WSL/INSTALL_DISTRO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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`
Expand Down
96 changes: 96 additions & 0 deletions 34_WSL/SECOND_DISK.md
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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