0%

解决ubuntu上回环设备/dev/loop0占用100%的问题

当前ubuntu环境

1
2
cat /etc/issue
Ubuntu 19.04 \n \l

当我们查看文件系统占用情况时,发现有/dev/loop0至/dev/loop7占用率为100%。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 796M 1.9M 794M 1% /run
/dev/sda1 20G 18G 1.1G 95% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/loop0 15M 15M 0 100% /snap/gnome-characters/254
/dev/loop2 90M 90M 0 100% /snap/core/6673
/dev/loop1 3.8M 3.8M 0 100% /snap/gnome-system-monitor/77
/dev/loop3 152M 152M 0 100% /snap/gnome-3-28-1804/31
/dev/loop4 36M 36M 0 100% /snap/gtk-common-themes/1198
/dev/loop7 1.0M 1.0M 0 100% /snap/gnome-logs/61
/dev/loop6 54M 54M 0 100% /snap/core18/941
/dev/loop5 4.2M 4.2M 0 100% /snap/gnome-calculator/406
tmpfs 796M 36K 795M 1% /run/user/1000

/dev/loopn这些设备在Linux下被称为回环设备。

可以通过执行losetup命令查看所有回环设备。

1
2
3
4
5
6
7
8
9
10
losetup
NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO LOG-SEC
/dev/loop1 0 0 1 1 /var/lib/snapd/snaps/gnome-system-monitor_77.snap 0 512
/dev/loop6 0 0 1 1 /var/lib/snapd/snaps/core18_941.snap 0 512
/dev/loop4 0 0 1 1 /var/lib/snapd/snaps/gtk-common-themes_1198.snap 0 512
/dev/loop2 0 0 1 1 /var/lib/snapd/snaps/core_6673.snap 0 512
/dev/loop0 0 0 1 1 /var/lib/snapd/snaps/gnome-characters_254.snap 0 512
/dev/loop7 0 0 1 1 /var/lib/snapd/snaps/gnome-logs_61.snap 0 512
/dev/loop5 0 0 1 1 /var/lib/snapd/snaps/gnome-calculator_406.snap 0 512
/dev/loop3 0 0 1 1 /var/lib/snapd/snaps/gnome-3-28-1804_31.snap 0 512

我们可以把xxx.iso镜像文件挂载到一个目录下。

1
mount -o loop xxx.iso /media

等同于执行:

1
2
losetup /dev/loop0 xxx.iso
mount /dev/loop0 /media

清理方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
sudo apt autoremove --purge snapd
[sudo] password for simon:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
gnome-software gnome-software-common
Suggested packages:
apt-config-icons-hidpi gnome-software-plugin-flatpak
Recommended packages:
gnome-software-plugin-snap
The following packages will be REMOVED:
apg* gnome-control-center-faces* gnome-online-accounts* gnome-software-plugin-snap* libclutter-imcontext-0.1-0* libclutter-imcontext-0.1-bin*
libcolord-gtk1* libgsound0* libgtop-2.0-11* libgtop2-common* mobile-broadband-provider-info* network-manager-gnome* python3-macaroonbakery*
python3-protobuf* python3-rfc3339* python3-tz* snapd* ubuntu-system-service*
The following packages will be upgraded:
gnome-software gnome-software-common
2 upgraded, 0 newly installed, 18 to remove and 171 not upgraded.
Need to get 2,982 kB of archives.
After this operation, 73.7 MB disk space will be freed.
Do you want to continue? [Y/n] y

再次查看磁盘使用情况:

1
2
3
4
5
6
7
8
9
df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 796M 1.9M 794M 1% /run
/dev/sda1 20G 18G 1.6G 92% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
tmpfs 796M 36K 795M 1% /run/user/1000