Skip to content

Commit 1a5c3df

Browse files
committed
fixed proc being unmounted too early
Signed-off-by: Zen <[email protected]>
1 parent 59af362 commit 1a5c3df

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

ugrd/base/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = 'desultory'
2-
__version__ = '1.2.0'
2+
__version__ = '1.2.2'
33

44

55
def do_switch_root(self) -> str:
@@ -10,6 +10,7 @@ def do_switch_root(self) -> str:
1010
mount_dest = self.config_dict['mounts']['root']['destination']
1111
out = [f"echo 'Checking root mount: {mount_dest}'"]
1212
out += [f"if grep -q ' {mount_dest} ' /proc/mounts ; then"]
13+
out += [" clean_mounts"]
1314
out += [f" exec switch_root {mount_dest} /sbin/init"]
1415
out += ["else"]
1516
out += [" echo 'Root mount not found, starting bash shell'"]

ugrd/fs/mounts.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = 'desultory'
2-
__version__ = '1.2.0'
2+
__version__ = '1.2.1'
33

44
from pathlib import Path
55

@@ -39,6 +39,8 @@ def _process_mounts_multi(self, mount_name: str, mount_config) -> None:
3939

4040
# Set defaults
4141
mount_config['destination'] = Path(mount_config.get('destination', mount_name))
42+
if not mount_config['destination'].is_absolute():
43+
mount_config['destination'] = '/' / mount_config['destination']
4244
mount_config['base_mount'] = mount_config.get('base_mount', False)
4345
mount_config['options'] = set(mount_config.get('options', ''))
4446

@@ -163,18 +165,14 @@ def mount_fstab(self) -> list[str]:
163165
out += ["read -sr"]
164166

165167
out += ["mount -a || (echo 'Failed to mount fstab. Please ensure mounts are made and then exit.' && bash)"]
166-
167168
return out
168169

169170

170171
def _get_mounts_source_device(self, mountpoint: str) -> Path:
171172
"""
172173
Returns the source device of a mountpoint on /proc/mounts
173174
"""
174-
# Make the mount a string and ensure it starts with a /
175175
mountpoint = str(mountpoint)
176-
if not mountpoint.startswith('/') and not mountpoint.startswith(' /'):
177-
mountpoint = '/' + mountpoint
178176

179177
self.logger.debug("Getting source device path for: %s" % mountpoint)
180178
# Add space padding to the mountpoint
@@ -265,6 +263,12 @@ def clean_mounts(self) -> list[str]:
265263
"""
266264
Generates init lines to unmount all mounts
267265
"""
266+
umounts = [f"umount {mount['destination']}" for mount in self.config_dict['mounts'].values() if not mount.get('skip_unmount')]
267+
# Ensure /proc is unmounted last
268+
if 'umount /proc' in umounts and umounts[-1] != 'umount /proc':
269+
umounts.remove('umount /proc')
270+
umounts.append('umount /proc')
271+
268272
return [f"umount {mount['destination']}" for mount in self.config_dict['mounts'].values() if not mount.get('skip_unmount')]
269273

270274

ugrd/fs/mounts.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mount_wait = false
2727
[imports.init_mount]
2828
"ugrd.fs.mounts" = [ "mount_root" ]
2929

30-
[imports.init_cleanup]
30+
[imports.functions]
3131
"ugrd.fs.mounts" = [ "clean_mounts" ]
3232

3333
[custom_parameters]

0 commit comments

Comments
 (0)