{"id":5388,"date":"2026-08-30T17:40:35","date_gmt":"2026-08-30T08:40:35","guid":{"rendered":"https:\/\/donguri3.net\/server-tech\/wsl2-ubuntu-data-migration-guide-2\/"},"modified":"2026-08-30T17:40:36","modified_gmt":"2026-08-30T08:40:36","slug":"wsl2-ubuntu-data-migration-guide","status":"publish","type":"post","link":"https:\/\/donguri3.net\/en\/server-tech\/virtualization-container-wsl\/wsl2-ubuntu-data-migration-guide\/","title":{"rendered":"WSL2: How to Share Data Without Copying or Deleting the Old Environment When Introducing a New OS"},"content":{"rendered":"<p>A major advantage of using Windows Subsystem for Linux (WSL2) is the ability to quickly and lightweightly create and destroy Linux environments. However, as development continues over the long term, you accumulate tools that only work on specific OS versions and carefully crafted configuration files built up over years. When a new OS environment (such as an LTS version) is released, while there is a desire to take advantage of the latest features, completely discarding the old environment or copying massive amounts of data to a new virtual disk consumes significant time and storage capacity.<br \/>\nTherefore, this time, we will introduce a solution where the old environment&#8217;s instance is directly mounted as a &#8220;virtual drive&#8221; in the new environment, allowing you to handle files from the old environment in the new one without any data copying. As a result, you can keep the new OS clean while retaining access to your past development assets.<\/p>\n<h2>Goal for Building a Sustainable Development Foundation That Doesn&#8217;t Waste Resources<\/h2>\n<p>In this construction task, taking the addition of a new environment like Ubuntu 24.04 and accessing data from the old environment (such as Ubuntu 22.04) as our theme, we aim to achieve the following two metrics:<\/p>\n<ol>\n<li>Keep access latency to the old environment&#8217;s data down to zero, maintaining performance equivalent to native file operations.<\/li>\n<li>To suppress the risk of data loss during migration to &#8220;physically zero,&#8221; make absolutely no modifications (deletion or relocation) to existing instances. This ensures ease of &#8220;rollbacks&#8221; so that even if a bug occurs in the new environment, work can instantly resume in the old environment.<\/li>\n<\/ul>\n<h2>The &#8220;Risk of Disappearance&#8221; and Permission Barriers Due to Virtualized Environments<\/h2>\n<p>The most critical hazard in WSL2 operations is accidental user operations, particularly executing the wsl &#8211;unregister command. When this command is run, the virtual disk (VHDX) of the target distribution is immediately deleted without warning. If you erase the &#8220;data source,&#8221; the development assets stored within it can never be recovered. Many users attempt to clean up their environments without fully realizing this risk and end up failing. Additionally, when attempting to reference data from another distribution, Linux permissions (ownership) often become a barrier, leading to frequent practical issues where file editing or Git operations are denied.<\/p>\n<h2>Concrete Solutions for Safe and Efficient Data Integration<\/h2>\n<p>The solution to avoid these risks and securely inherit data lies in combining WSL2&#8217;s &#8220;drvfs mount&#8221; and &#8220;symbolic links.&#8221;<\/p>\n<h3>Backup and Preparation of the New Environment<\/h3>\n<p>First and foremost, we recommend taking a backup of the old environment. Export it to a safe location using the following command:<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">wsl --export Ubuntu-22.04 C:\\Backup\\ubuntu-22.04-backup.tar<\/pre>\n<p>&nbsp;<\/p>\n<p>After that, install Ubuntu 24.04 and set it as the default.<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">wsl --install -d Ubuntu-24.04\nwsl --set-default Ubuntu-24.04<\/pre>\n<h3>Mounting the Stopped Old Environment<\/h3>\n<p>Edit \/etc\/wsl.conf on the Ubuntu 24.04 side to add settings that automatically mount the old environment at startup. Here, to facilitate &#8220;data inheritance,&#8221; we add options to force ownership to the current user.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">&#x5B;boot]\nsystemd=true\ncommand = &quot;mkdir -p \/mnt\/old_assets &amp;amp;&amp;amp; mount -t drvfs &#039;\\\\\\\\wsl.localhost\\\\Ubuntu-22.04&#039; \/mnt\/old_assets -o uid=1000,gid=1000,metadata&quot;<\/pre>\n<h3>Seamless Usage via Path Integration<\/h3>\n<p>Finally, create a link directly under the home directory of the new environment pointing to the working directory of the old environment.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">ln -s \/mnt\/old_assets\/home\/user\/work ~\/old_work<\/pre>\n<p>Through this procedure, you can &#8220;inherit&#8221; and utilize the entity of the old environment from the new environment without deleting the old instance itself. <code>Note: Even after this procedure, never delete the past instance itself (Ubuntu-22.04 in this case). Deleting it will also destroy the contents of \/mnt\/old_assets.<\/code><\/p>\n<h2>Conclusion<\/h2>\n<p>Through this initiative, we have resolved the barrier of &#8220;independence&#8221; inherent to each WSL2 distribution by utilizing appropriate mounting technology. We can now say that an environment has been established where past assets can be called upon freely from the cutting-edge stage of Ubuntu 24.04.<\/p>\n<p>However, the most important point to keep in mind when operating this method is that <code>\"if you delete (unregister) the mount source instance, its actual data will also be completely lost.\"<\/code> Recognizing the location of your data clearly\u2014so that you do not carelessly target the old environment for cleanup under the assumption that it is an &#8220;unused OS&#8221;\u2014becomes an extremely crucial challenge in maintaining this coexistence environment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A major advantage of using Windows Subsystem for Linux (WSL2) is the ability to quickly and lightweightly crea [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":2887,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"en_US","_original_post":"https:\/\/donguri3.net\/?p=2884","footnotes":""},"categories":[1171],"tags":[51,105,352,100,1000,365,251],"class_list":["post-5388","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-virtualization-container-wsl","tag-git","tag-linux","tag-ubuntu","tag-ubuntu-22-04","tag-wsl","tag-wsl2","tag-251","en-US"],"_links":{"self":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts\/5388","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/comments?post=5388"}],"version-history":[{"count":1,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts\/5388\/revisions"}],"predecessor-version":[{"id":5391,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts\/5388\/revisions\/5391"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/media\/2887"}],"wp:attachment":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/media?parent=5388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/categories?post=5388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/tags?post=5388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}