[GH-ISSUE #2661] Migrating models from WSL2 to Native Windows #1578

Closed
opened 2026-04-12 11:30:38 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @circbuf255 on GitHub (Feb 22, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/2661

What is the correct workflow to migrate from WSL2 to Native Windows? Migrating models (blobs/manifests) from WSL2 to Windows does not seem to work as expected. For those with hundreds of GB already downloaded in WSL2, there should be a method to move those to native Windows. The method I tried that does not work:

Modifying the blobs:

  1. copy/paste all sha256 blobs from WSL2 to Windows
  2. rename the blobs to replace the "sha256:" with "sha256-" since windows doesn't support colon in filename
  3. edit the contents of the blobs replacing "sha256:" with "sha256-"

Modifying the manifests:

  1. copy and past the manifest directory from WSL2 to Windows
  2. edit the contents of the manifest files replacing "sha256:" with "sha256-"

Command prompt:

ollama list
...
(I got the expected results - I see all of the models)

ollama run mixtral
...
(Again, I got the expected results I was able to chat with the model)

However, after closing ollama in the taskbar and reloading it. ALL BLOBS ARE DELETED
server.log says:
"total blobs: 59"
"total unused blobs removed: 59"

Originally created by @circbuf255 on GitHub (Feb 22, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/2661 **What is the correct workflow to migrate from WSL2 to Native Windows?** Migrating models (blobs/manifests) from WSL2 to Windows does not seem to work as expected. For those with hundreds of GB already downloaded in WSL2, there should be a method to move those to native Windows. The method I tried that does not work: **Modifying the blobs:** 1) copy/paste all sha256 blobs from WSL2 to Windows 2) rename the blobs to replace the "sha256:" with "sha256-" since windows doesn't support colon in filename 3) edit the contents of the blobs replacing "sha256:" with "sha256-" **Modifying the manifests:** 1) copy and past the manifest directory from WSL2 to Windows 2) edit the contents of the manifest files replacing "sha256:" with "sha256-" Command prompt: >>ollama list >>... (I got the expected results - I see all of the models) >> ollama run mixtral >>... (Again, I got the expected results I was able to chat with the model) However, after closing ollama in the taskbar and reloading it. ALL BLOBS ARE DELETED server.log says: "total blobs: 59" "total unused blobs removed: 59"
Author
Owner

@circbuf255 commented on GitHub (Feb 22, 2024):

Solved. Only the blobs files needs to be edited not the manifest files.

Step 1: copy the entire models folder from "\\wsl$\..." to the new model folder in Windows.
Step 2: place this python script in the new models folder
Step 3: run the script -- "python migrate.py"

# migrate.py

import os
import shutil

# Recursively rename all files starting with 'sha256' in 'blobs' directory
for root, dirs, files in os.walk('blobs'):
    for file in files:
        if file.startswith('sha256'):
            old_path = os.path.join(root, file)
            new_name = 'sha256-' + file[7:]
            new_path = os.path.join(root, new_name)
            shutil.move(old_path, new_path)
            print('Renamed file to:', new_path)

# Process files in 'blobs' directory if their size is less than 2KB (2048 bytes)
for root, dirs, files in os.walk('blobs'):
    for file in files:
        path = os.path.join(root, file)
        size_in_bytes = os.path.getsize(path)
        
        if size_in_bytes > 2048:
            print('Skipped file:', path)
        else:
            print('Processing file:', path)
            
            with open(path, 'r') as f:
                lines = f.readlines()
                
            new_lines = [line.replace('sha256:', 'sha256-') for line in lines]
            
            # Write the modified content to a temporary file
            with open('temp.txt', 'w') as f:
                f.writelines(new_lines)
                
            # Move the temporary file back into place for the original file
            shutil.move('temp.txt', path)
<!-- gh-comment-id:1958922069 --> @circbuf255 commented on GitHub (Feb 22, 2024): Solved. Only the blobs files needs to be edited not the manifest files. Step 1: copy the entire models folder from "\\\\wsl$\\..." to the new model folder in Windows. Step 2: place this python script in the new models folder Step 3: run the script -- "python migrate.py" ``` # migrate.py import os import shutil # Recursively rename all files starting with 'sha256' in 'blobs' directory for root, dirs, files in os.walk('blobs'): for file in files: if file.startswith('sha256'): old_path = os.path.join(root, file) new_name = 'sha256-' + file[7:] new_path = os.path.join(root, new_name) shutil.move(old_path, new_path) print('Renamed file to:', new_path) # Process files in 'blobs' directory if their size is less than 2KB (2048 bytes) for root, dirs, files in os.walk('blobs'): for file in files: path = os.path.join(root, file) size_in_bytes = os.path.getsize(path) if size_in_bytes > 2048: print('Skipped file:', path) else: print('Processing file:', path) with open(path, 'r') as f: lines = f.readlines() new_lines = [line.replace('sha256:', 'sha256-') for line in lines] # Write the modified content to a temporary file with open('temp.txt', 'w') as f: f.writelines(new_lines) # Move the temporary file back into place for the original file shutil.move('temp.txt', path) ```
Author
Owner

@LL1yt commented on GitHub (May 21, 2024):

I would really appreciate it if someone could rewrite this script to port from win to wsl. as I started with the win version but now realized it doesn't use gpu.

<!-- gh-comment-id:2123591316 --> @LL1yt commented on GitHub (May 21, 2024): I would really appreciate it if someone could rewrite this script to port from win to wsl. as I started with the win version but now realized it doesn't use gpu.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#1578