Guide
Mount Google Drive in a Colab Notebook to Access Your Files
Learn how to mount Google Drive in a Colab notebook, verify the mount, and recover from authentication failures.
Published by Tasadduq Burney
23 Aug 2026, 17:18 UTC
2 min35.6K views0

Desired outcome
Mount your Google Drive inside a Google Colab notebook so that you can read, write, and manipulate files stored in Drive as if they were local to the notebook’s runtime.
Prerequisites
- A Google account that can access both Google Colab and Google Drive.
- An existing or newly created Colab notebook (File → New notebook).
- A folder in Google Drive whose contents you want to work with (e.g.,
MyDrive/project-data).
Procedure
- Open the notebook and insert a new code cell.
- Paste the following import and mount command:
- Run the cell (Shift+Enter). A prompt appears with an authorization link.
- Click the link, sign in with your Google account if needed, and grant Colab access to Drive.
- Copy the authentication code displayed on the consent page.
- Paste the code into the cell’s input box and press Enter.
- The cell will finish execution and display 'Mounted at /content/drive'.
from google.colab import drive
drive.mount('/content/drive')
Expected checks
- In the left‑hand file browser, expand the
/contentdirectory; you should see a folder nameddrive. - Navigate to
/content/drive/MyDrive(or the subfolder you need) and verify that your files appear. - Alternatively, run a shell command to list contents:
!ls -l /content/drive/MyDrive
Recovery options
- If the authentication step fails (e.g., you entered an incorrect code or the link expired), you can reset the runtime and try again:
- Select Runtime → Factory reset from the notebook menu.
- Confirm the reset; this clears all mounted drives and variables.
- Re‑run the mount cell from step 2.
- If you prefer to keep the runtime but want to clear a failed mount, execute:
drive.flush_and_unmount()
drive.mount command.Limits and safety notes
- The mounted Drive is tied to the notebook’s runtime. Closing the notebook, disconnecting, or runtime recycling will automatically unmount the Drive; you must repeat the authentication on the next session.
- Mounting grants the notebook full read/write access to your entire Drive. Avoid running untrusted or third‑party code that could modify or delete files unintentionally.
- Performance depends on your network latency to Google Drive; large file transfers may be slower than local disk access.
Quick verification checklist
- Run
!ls /content/drive/MyDriveand confirm you see expected folders. - Open a file from Drive, e.g.,
%cat /content/drive/MyDrive/notebooks/example.ipynb - Write a test file:
!echo 'test' > /content/drive/MyDrive/test.txtand verify it appears in the UI.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.