MSIX app attach – How To Manage CIMFS File Sprawl – Tips and Tricks


Introduction

CIMFS is a new file system known as the composite file system. A CIM is essentially a small collection of flat files containing one or more data and metadata region files, one or more object ID files and one or more filesystem description files. CIM’s image format is a similar concept to a WIM or a read-only VHD\VHDX.

The term composite means that the image can contain multiple file system volumes which can be mounted individually while sharing the same data region files. I am yet to see this in action; however, this is possible with CIMFS.

CIM can be accessed read-only using the standard Win32 or NT API file system interface.

The Challenge

Whilst CIMFS offers improved reduced resource consumption for large deployments, it does present a file management challenge in a sense there are several files to take care of rather than with a VHD or a VHDX you only have one file to worry about (per MSIX image).

When creating CIM images, it is recommended that you should create them in one folder per .CIM (group of files). If you create multiple CIM images all in one folder, how do you differentiate between them? Its not easy and creates a bit of a challenge.

The image below depicts a small MSIX image which contains an MSIX package in the format of CIMFS. You will note that there are many files that all relate to the same MSIX image known as testapp.cim.

You will also note each object id and region file has the same guid associated. However, how do you associate the CIM file with the region and object id files? This is tricky….

The guid shown on the object and region files is the guid provided during the creation of the cim and is not the guid when mounting the cim image on future mounts.

This is what it looks like if you output all your cim images into the same folder:

You will note that there are two Cims in the folder. However, how can you identify the two different CIM file groups between each other? The object and region files show different guids, which helps. How do you match the .CIM to the region and object files?

Solution to the problem

To avoid the problem in the first place, always create a CIM image in its own dedicated folder.

It does not impact MSIX app attach when separating your CIMs into individual folders. You still have to specify the absolute path of the MSIX image in WVD. However, the slight change is you would not specify the root path; you would rather specify the specific folder “\\path\cimfolder\app1.cim”. Put CIM’s in folders!

When the CIM image files are first created, a creation timestamp is added to the file attributes. We can grab all the associated files to a specific CIM image to collect file attributes and match them when tidying up.

Get creation time stamps for CIMFS

The following PowerShell cmdlet reads the files in a folder and outputs the creation time:

Get-ChildItem -Path C:\Users\Ryan\Desktop\cimtest\testmove | Foreach-Object { write-output "$($_.Mode) $($_.LastWriteTime) $($_.FullName)" }

The output of this is:

As you can see from the screenshot above, we can now see when this group of files were created.

You can also see that they all have the same time or minimal difference, indicating that these are associated with each other.

You can grab the script here: https://github.com/RMITBLOG/MSIX_APP_ATTACH/blob/master/Cim%20Scripts/grab_cimCreationtimes.ps1

Moving CIM images to a new folder

This example: We now know that this specific CIM image group of files was created at 11:49:50 on the 02/06/2021. The next step is to use the move script to grab the files within a specific date and time threshold and move them to a destination folder.

You can then use the following PowerShell to move the Cim files to the chosen destination:

[DateTime]$start_time = "02/06/2021 11:49:50"
[DateTime]$end_time = "02/06/2021 11:49:52"
$des_folder = "C:\Users\Ryan\Desktop\cimtest\testmove"

Get-ChildItem C:\Users\Ryan\Desktop\cimtest* -Recurse | foreach { if ($_.lastwritetime -ge $start_time -and $_.lastwritetime -le $end_time) { move-item $_.fullname $des_folder } }

You can Grab the script here:

https://github.com/RMITBLOG/MSIX_APP_ATTACH/blob/master/Cim%20Scripts/Move_Cimfiles_basedOn_creation.ps1

PowerShell Module to list mountpoints and list mounted CIMs.

I did write a PowerShell Module to help with managing mounted CIM images. You can find here: MSIX_APP_ATTACH/Mount-Point_PSModule MSI at master · RMITBLOG/MSIX_APP_ATTACH (github.com)

The cmdlets:

get-mountpoints 

(lists all mountpoints on the machine and file system types.

Get-cims 

(lists all mounted Cims).

If you want to mount Cims, you can use the following Gui/cli. MSIX_APP_ATTACH/Cimfs tool/Cimutil installer at master · RMITBLOG/MSIX_APP_ATTACH (github.com)

Summary

CIMFS is great in a sense; it offers reduced resource cost on the host. However, the additional file creation output compared to VHD/VHD MSIX images needs to be managed. So remember, create CIMS in a folder per CIM image. If you haven’t, the best way to tidy up and the group is to use the two scripts.

Any questions, feel free to comment.

2 thoughts on “MSIX app attach – How To Manage CIMFS File Sprawl – Tips and Tricks

Add yours

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: