WSL2迁移与硬盘读写测试

前言

上篇 WSL2内核编译_添加SocketCAN支持提到解压过程文件名大小写的坑和/mnt目录下感人的速度, 其实如果是在/home目录下, 这些都不是问题(大小写问题没有了, 读写解压编译速度也上去了). 只是WSL2默认装在C盘, 如下图Ubuntu18.04和Ubuntu的ext4磁盘所在的位置.
在这里插入图片描述
这个磁盘和虚拟机类似, 用多少占多少, 但膨胀一般而言不可逆, 不知道现在有没有改观. C盘一般最多也就500G, 不能乱搞, 所以只能把WSL2的ext4磁盘搬家了.

WSL2迁移

把Ubuntu-18.04和Ubuntu(20)两个ext4磁盘从C盘搬到D盘(SN550, 1T SSD)里面, 过程如下

# everything 搜索 ext4.vhdx

> wsl -l -v                                                                                      
  NAME            STATE           VERSION
* Ubuntu-18.04    Stopped         2 
  Ubuntu          Stopped         2 

# 终止运行
> wsl -t Ubuntu
> wsl -t Ubuntu-18.04

# 导出备份
> wsl --export Ubuntu D:\wsl\Ubuntu_bak.tar
> wsl --export Ubuntu-18.04 D:\wsl\Ubuntu18_bak.tar

# 注销
> wsl --unregister Ubuntu
> wsl --unregister Ubuntu-18.04
# 注销后可以在everything看到两个上G大小的w ext4.vhdx 消失了

# 从备份导入
> wsl --import Ubuntu D:\wsl\Ubuntu D:\wsl\Ubuntu_bak.tar --version 2
> wsl --import Ubuntu-18.04 D:\wsl\Ubuntu-18.04 D:\wsl\Ubuntu18_bak.tar --version 2

# 设置默认登录用户
> Ubuntu config --default-user karoto
> Ubuntu1804 config --default-user karoto

# 完成后可以删除tar备份
# 也可以不删, 日后ext4.vhdx膨胀到不能忍受时, 可以用这个tar备份恢复出厂设置或者回滚

接下来就可以愉快的使用/home目录, 读写速度较之前/mnt方式有很大提升

Linux硬盘读写测试

先来测试~目录读写速度

# D盘是SN550
# 硬盘读写测试(先纯写, 再纯读, 后读写)

# 纯写
~$ touch testReadOrWrite 
~$ time dd if=/dev/zero of=./testReadOrWrite bs=8k count=1000000
1000000+0 records in
1000000+0 records out
8192000000 bytes (8.2 GB, 7.6 GiB) copied, 6.28316 s, 1.3 GB/s

real    0m6.285s
user    0m0.470s
sys     0m5.761s

# 纯读
~$ time dd if=./testReadOrWrite of=/dev/null bs=8k count=1000000
1000000+0 records in
1000000+0 records out
8192000000 bytes (8.2 GB, 7.6 GiB) copied, 1.41806 s, 5.8 GB/s

real    0m1.419s
user    0m0.480s
sys     0m0.939s

# 读写测试
~$ touch testReadAndWrite
~$ time dd if=./testReadOrWrite of=./testReadAndWrite bs=8k count=1000000
1000000+0 records in
1000000+0 records out
8192000000 bytes (8.2 GB, 7.6 GiB) copied, 7.48878 s, 1.1 GB/s

real    0m7.490s
user    0m0.493s
sys     0m6.833s

# 清理测试文件
~$ rm -f testReadOrWrite testReadAndWrite

# 这个速度比统一硬盘下虚拟机里面的Ubuntu18速度还要快不少
# 测试完后 ext4.vhdx 3.58GB
# 即便删除测试文件, 重启系统, 这个空间也缩不回去了

接下来测试/mnt/d的数据

: ~$ cd /mnt/d
: /mnt/d$ time dd if=/dev/zero of=./testReadOrWrite bs=8k count=1000000
1000000+0 records in
1000000+0 records out
8192000000 bytes (8.2 GB, 7.6 GiB) copied, 125.597 s, 65.2 MB/s

real    2m5.600s
user    0m3.286s
sys     0m15.371s

/mnt/d$ time dd if=./testReadOrWrite of=/dev/null bs=8k count=1000000
1000000+0 records in
1000000+0 records out
8192000000 bytes (8.2 GB, 7.6 GiB) copied, 118.679 s, 69.0 MB/s

real    1m58.681s
user    0m3.361s
sys     0m16.840s

/mnt/d$ time dd if=./testReadOrWrite of=./testReadAndWrite bs=8k count=1000000

1000000+0 records in
1000000+0 records out
8192000000 bytes (8.2 GB, 7.6 GiB) copied, 240.352 s, 34.1 MB/s

real    4m1.034s
user    0m7.074s
sys     0m32.523s

# 清理测试文件
~$ rm -f testReadOrWrite testReadAndWrite

可以看到, 写速度/mnt/d~目录慢了约20倍, 读速度更是差了85倍, 读写速度差了33倍

unzip之类的快多了, 也没有大小写的问题了, 编译wsl2_kernel也从之前的30~40分钟缩短为 4分多钟, 这体验直接飞升.

更改Terminal中WSL2的默认启动目录

启动后默认目录是 /mnt/c/Users/karoto, karoto是我的windows用户名, 这是默认的 %USERPROFILE%, 可以直接在windows terminal中修改

如设置为~目录, 填入//wsl$/Ubuntu-18.04/home/karoto, karoto是我的ubuntu用户名, 一定要记得点右下角的保存

在这里插入图片描述

参考

参考自:

欢迎扫描二维码关注本人微信公众号, 及时获取最新文章:
在这里插入图片描述

  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值