Skip to main content

4 posts tagged with "OS"

View All Tags

Set up OS for developer to prevent data loss

· 2 min read
Huakun Shen
Website Owner

As a developer, I have hundreds of repos on my computer. I also need to reinstall the system every year or few months depending on the amount of garbage I added to the OS or if I broken the OS.

Data loss is a serous problem. My design goal is to prevent any possibility of losing important files even if the OS crashed, the computer is stolen, and I can reset it any time without worrying about backing up my data. (Reinstalling apps is fine for me).

The solution is simple, cloud.

My files include the following categories

  1. Code
  2. Videos
  3. Regular documents (pdf, books, forms, notes, etc.)
  4. Images

My code repos is always tracked with git and all changes must be backed up to GitHub immediately.

The code are stored in ~/Dev/

All other files are saved in OneDrive or iCloud Drive.

There is nothing on my ~/Desktop. I like to keep it clean.

This way I can reset my computer any time.

Backup

Although I have all my files in the cloud, sometimes you may forgot to commit all changes to git. You may want to backup the entire projects folder to a drive, or cloud.

However, projects can take up a huge amount of space. My single rust project can easily take up 10-60GB due to large cache. This will take forever to upload to the cloud.

I wrote a small app called devclean (https://github.com/HuakunShen/devclean) with 2 simple feautres:

  1. Scan a given directory recursively for all git repos that have uncommitted changes.
    1. You can commit the changes and push before resetting the computer.
  2. Scan a given directory recursively for cache and dependency files (node_modules, target, etc.). These files can be deleted before backup. Then the project code is probably a few MB.
    1. Clearing cache and dependencies can save a lot of space and time during backup.

MacOS Purgeable Space Problem (solved with Daisy Disk)

· One min read
Huakun Shen
Website Owner

Problem Description

I encountered a weird problem with MacOS storage.

I wanted to install a MacOS VM with Parallels Desktop, but was unable to. The error message says I don't have enough space (at least 49.13G) on disk. But storage displayed in preference tells me I have more than 500GB of space, and I just cleaned the storage.

Although preference says that I have space, other places give me different result.

df -h . says my disk usage is 97%

In disk utility, my disk usage is displayed to be 942.28/994.66GB.

Right click on the disk -> Get Info. The purgeable space section takes ~500GB of space.

Usually, Mac should handle it. Space should be freed while needed, but not here.

MacOS doesn't seem to provide a option to manually purge space, so I have to use a third party software.

How stupid is this?

Readings and Solutions

With DaisyDisk, you can find the purgeable space visually. Drag it to the button at the bottom, and delete. Then the purgeable space will be purged.

Result

Windows OpenSSH Server authorized_keys Failure on Administrative User Account

· 2 min read
Huakun Shen
Website Owner

Problem

I run into a problem related to ssh and got stuck for a few days. On a fresh-intsalled win11 PC, I tried to configure OpenSSh server, which I have done a thousand times on Linux OS.

I could ssh into the windows PC, but only using password; Key-based auth (i.e. password-less) doesn't work no matter what I do.

I added the authorized_keys file to C:\Users\username\.ssh, checked the file permission and even created another user account to compare.

None of these fixed the problem, and I couldn't find a good solution from Google or Chat GPT. BTW, Chat GPT keeps giving me Linux-related solutions.

Solution

The solution is actually quite simple. I read the official Doc by microsoft. Key-based authentication (Administrative user).

It turns out, Windows treat admin account differently. On Linux, regular accounts and sudoer accounts both use $HOME/.ssh/authorized_keys to stored trusted public keys.

The reason of my failure was because I was trying to ssh into an admin account.

On Windows, a administrators_authorized_keys should be placed under C:\ProgramData\ssh\. The content of administrators_authorized_keys is exactly the same.

Solution verified to work.

Comment

  • I can't blame Microsoft as this may be a more secure approach, and it's clearly documented in their documentation.
    • But maybe don't hide this at the bottom of the page. Highlight it in the beginning. It's easy to ignore it.
  • However, I don't understand why I can't easily find solution for such a common topic online. One would not search with the "administrative" keyword for such problem. Maybe Windows should give more warning messages and hints when OpenSSH server is installed or when login failed.
  • Furthermore, Chat GPT still has a long way to go.
  • And Google Search, ... hope you don't get completely replaced by some tech like Chat GPT one day.

Good Luck Hacking!

Fix Windows Network Adapter Low Speed

· 3 min read
Huakun Shen
Website Owner

This is a very weird bug. I will describe the scenario first, then the hacky fix.

Scenario

Environment

Description

I built a new PC with Gigabyte Z690 UD AX DDR4. The wifi 6 wireless adapter works fine, reaches 800+Mbps on my gigabit network; but the ethernet connection can only reach ~10Mbps.

This is super weird, the name is Realtek Gaming 2.5GbE Family Controlleras, the ethernet adapter should support 2.5G, and there is nothing wrong with the router.

Debug Process

  • I plugged in a 2.5G usb C ethernet converter, it worked fine.
  • When I use Ubuntu, the ethernet works fine (reach 900+Mbps).

From this debugging process, we know that the hardware should be fine. The problem most likely comes from Windows, or compatibility issue between windows and the network adapter (driver).

Solution

V1

The first time I got it working is by opening "Device", uninstall the device, and reinstall it.

After scanning, the network adapter is back, and the network speed is fixed (900+Mbps).

But this process has to be done every time a computer is booted.

V2 (auto)

This powershell script basically automate the previous solution using powershell.

caution

It requires Adminitrator permission to run the script.

Running this manually everytime is not better than the previous solution, we have to auto-run it on system starts.

The commented out lines is for debugging purpose, to see if the script has really run.

caution

Edit the following script to fit your scenario.

e.g. Update the deviceName, and log path.

# echo "start" | Out-File -Append C:\Users\user\Desktop\debug.log
# date | Out-File -Append C:\Users\user\Desktop\debug.log
# Start-Sleep -Seconds 5
$deviceName="Realtek Gaming 2.5GbE Family Controller"
foreach ($dev in (Get-PnpDevice | Where-Object{$_.Name -eq $deviceName})) {
&"pnputil" /remove-device $dev.InstanceId
}
pnputil /scan-devices
# echo "finish" | Out-File -Append C:\Users\user\Desktop\debug.log
  1. Press Win key, search and open "Task Scheduler"
  2. Action -> Create Basic Task Wizard
  3. Give a name
  4. Use "When I log on" for Trigger
  5. Action should be "Start a program", then fill in the script path
    1. Enter powershell <script-path>
  6. Then Finish
  7. Go to Task Scheduler Library -> Your Task, check Run with highest priviledges

Restart the computer, it should now be fixed.

If it doesn't, you may need to debug.

  1. Check the variables in script
  2. Run the script in powershell as Administrator and see if the network speed is normal.
  3. Then restart and see
  4. If it still doesn't work, uncomment the commented out code to see if the code has really run
  5. If it still doesn't work, then I don't know, good luck
Blame

Microsoft, Realtek, and Gigabyte, I don't know which of you should be responsible for this bug, but this needs to be fixed.

A gaming motherboard can't game at 10Mbps!

I personally believe Microsft/Windows should take the blame, as it works fine on Ubuntu and the driver itself should be fine. Reinstalling the device fixes the problem could induce that a wrong driver is used (override the correct driver).

This solution is hacky and inelegant, but I can't find a better solution online.

Come on, Microsoft.