@@ -201,50 +201,77 @@ class SquashFs(object):
201
201
OS_PREFIX = "SONiC-OS-"
202
202
203
203
FS_PATH_TEMPLATE = "/host/image-{}/fs.squashfs"
204
+ FS_RW_TEMPLATE = "/host/image-{}/rw"
205
+ FS_WORK_TEMPLATE = "/host/image-{}/work"
204
206
FS_MOUNTPOINT_TEMPLATE = "/tmp/image-{}-fs"
205
207
206
- def __init__ (self ):
207
- current_image = self .__get_current_image ()
208
- next_image = self .__get_next_image ()
209
-
210
- if current_image == next_image :
211
- raise RuntimeError ("Next boot image is not set" )
208
+ OVERLAY_MOUNTPOINT_TEMPLATE = "/tmp/image-{}-overlay"
212
209
213
- image_stem = next_image .lstrip (self .OS_PREFIX )
210
+ def __init__ (self ):
211
+ image_stem = self .next_image .lstrip (self .OS_PREFIX )
214
212
215
213
self .fs_path = self .FS_PATH_TEMPLATE .format (image_stem )
214
+ self .fs_rw = self .FS_RW_TEMPLATE .format (image_stem )
215
+ self .fs_work = self .FS_WORK_TEMPLATE .format (image_stem )
216
216
self .fs_mountpoint = self .FS_MOUNTPOINT_TEMPLATE .format (image_stem )
217
217
218
- def __get_current_image (self ):
218
+ self .overlay_mountpoint = self .OVERLAY_MOUNTPOINT_TEMPLATE .format (image_stem )
219
+
220
+ def get_current_image (self ):
219
221
cmd = "sonic_installer list | grep 'Current: ' | cut -f2 -d' '"
220
222
output = subprocess .check_output (cmd , stderr = subprocess .STDOUT , shell = True )
221
223
222
224
return output .rstrip (NEWLINE )
223
225
224
- def __get_next_image (self ):
226
+ def get_next_image (self ):
225
227
cmd = "sonic_installer list | grep 'Next: ' | cut -f2 -d' '"
226
228
output = subprocess .check_output (cmd , stderr = subprocess .STDOUT , shell = True )
227
229
228
230
return output .rstrip (NEWLINE )
229
231
232
+ def is_next_boot_set (self ):
233
+ return self .current_image != self .next_image
234
+
230
235
def mount_next_image_fs (self ):
231
- if os .path .ismount (self .fs_mountpoint ):
236
+ if os .path .ismount (self .fs_mountpoint ) or os . path . ismount ( self . overlay_mountpoint ) :
232
237
self .umount_next_image_fs ()
233
238
234
239
os .mkdir (self .fs_mountpoint )
235
- cmd = "mount -t squashfs {} {}" .format (self .fs_path , self .fs_mountpoint )
240
+ cmd = "mount -t squashfs {} {}" .format (
241
+ self .fs_path ,
242
+ self .fs_mountpoint
243
+ )
236
244
subprocess .check_call (cmd , shell = True )
237
245
238
- return self .fs_mountpoint
246
+ os .mkdir (self .overlay_mountpoint )
247
+ cmd = "mount -n -r -t overlay -o lowerdir={},upperdir={},workdir={} overlay {}" .format (
248
+ self .fs_mountpoint ,
249
+ self .fs_rw ,
250
+ self .fs_work ,
251
+ self .overlay_mountpoint
252
+ )
253
+ subprocess .check_call (cmd , shell = True )
254
+
255
+ return self .overlay_mountpoint
239
256
240
257
def umount_next_image_fs (self ):
258
+ if os .path .ismount (self .overlay_mountpoint ):
259
+ cmd = "umount -rf {}" .format (self .overlay_mountpoint )
260
+ subprocess .check_call (cmd , shell = True )
261
+
262
+ if os .path .exists (self .overlay_mountpoint ):
263
+ os .rmdir (self .overlay_mountpoint )
264
+
241
265
if os .path .ismount (self .fs_mountpoint ):
242
266
cmd = "umount -rf {}" .format (self .fs_mountpoint )
243
267
subprocess .check_call (cmd , shell = True )
244
268
245
269
if os .path .exists (self .fs_mountpoint ):
246
270
os .rmdir (self .fs_mountpoint )
247
271
272
+ current_image = property (fget = get_current_image )
273
+ next_image = property (fget = get_next_image )
274
+
248
275
249
276
class PlatformComponentsParser (object ):
250
277
"""
0 commit comments