In subiquity, when running install-finish task to apply gadget snap to the storage, the defer function of writeFilesystemContent used to unmount the mounted partition may fail because it is busy due to unknown reason.
Following is the snippet of the debug log:
Jun 29 15:32:49 ubuntu snapd[2738]: logger.go:92: DEBUG: starting install-finish for "classic" (using encryption: true) on map[pc:0xc000890e40]
Jun 29 15:32:49 ubuntu snapd[2738]: logger.go:92: DEBUG: writing content to partitions
Jun 29 15:32:49 ubuntu snapd[2738]: logger.go:92: DEBUG: OnDiskStructureFromPartition: p.FilesystemType "crypto_LUKS", p.FilesystemLabel "ubuntu-data-enc"
Jun 29 15:32:49 ubuntu snapd[2738]: logger.go:92: DEBUG: OnDiskStructureFromPartition: p.FilesystemType "crypto_LUKS", p.FilesystemLabel "ubuntu-save-enc"
Jun 29 15:32:49 ubuntu snapd[2738]: logger.go:92: DEBUG: OnDiskStructureFromPartition: p.FilesystemType "ext4", p.FilesystemLabel "ubuntu-boot"
Jun 29 15:32:49 ubuntu snapd[2738]: logger.go:92: DEBUG: OnDiskStructureFromPartition: p.FilesystemType "vfat", p.FilesystemLabel ""
Jun 29 15:32:49 ubuntu snapd[2738]: logger.go:92: DEBUG: OnDiskStructureFromPartition: p.FilesystemType "vfat", p.FilesystemLabel "ubuntu-seed"
Jun 29 15:32:49 ubuntu snapd[2738]: logger.go:92: DEBUG: finding layout for "/dev/nvme0n1p1"
Jun 29 15:32:49 ubuntu snapd[2738]: logger.go:92: DEBUG: when applying layout to disk structure: laidOutStruct.OnDiskStructure: {Name:EFI System partition PartitionFSLabel:ubuntu-seed Type:C12A7328-F81F-11D2-BA4B-00A0C93EC93B PartitionFSType:vfat StartOffset:1048576 Node: DiskIndex:0 Size:786432000}, *onDiskStruct: {Name:EFI System partition PartitionFSLabel:ubuntu-seed Type:C12A7328-F81F-11D2-BA4B-00A0C93EC93B PartitionFSType:vfat StartOffset:1048576 Node:/dev/nvme0n1p1 DiskIndex:1 Size:786432000}
Jun 29 15:32:49 ubuntu snapd[2738]: logger.go:92: DEBUG: writing content on partition /dev/nvme0n1p1
Jun 29 15:32:49 ubuntu snapd[2738]: logger.go:92: DEBUG: mounting "/dev/nvme0n1p1" in "/run/snapd/gadget-install/dev-nvme0n1p1" (fs type "vfat")
Jun 29 15:32:50 ubuntu systemd[1]: run-snapd-gadget\x2dinstall-dev\x2dnvme0n1p1.mount: Deactivated successfully.
Jun 29 15:32:50 ubuntu snapd[2738]: logger.go:92: DEBUG: finding layout for "/dev/nvme0n1p3"
Jun 29 15:32:50 ubuntu snapd[2738]: logger.go:92: DEBUG: when applying layout to disk structure: laidOutStruct.OnDiskStructure: {Name:ubuntu-boot PartitionFSLabel:ubuntu-boot Type:0FC63DAF-8483-4772-8E79-3D69D8477DE4 PartitionFSType:ext4 StartOffset:14930673664 Node: DiskIndex:0 Size:786432000}, *onDiskStruct: {Name:ubuntu-boot PartitionFSLabel:ubuntu-boot Type:0FC63DAF-8483-4772-8E79-3D69D8477DE4 PartitionFSType:ext4 StartOffset:14930673664 Node:/dev/nvme0n1p3 DiskIndex:3 Size:786432000}
Jun 29 15:32:50 ubuntu snapd[2738]: logger.go:92: DEBUG: writing content on partition /dev/nvme0n1p3
Jun 29 15:32:50 ubuntu snapd[2738]: logger.go:92: DEBUG: mounting "/dev/nvme0n1p3" in "/run/snapd/gadget-install/dev-nvme0n1p3" (fs type "ext4")
Jun 29 15:32:50 ubuntu systemd[1]: run-snapd-gadget\x2dinstall-dev\x2dnvme0n1p3.mount: Deactivated successfully.
Jun 29 15:32:50 ubuntu snapd[2738]: logger.go:92: DEBUG: finding layout for "/dev/nvme0n1p4"
Jun 29 15:32:50 ubuntu snapd[2738]: logger.go:92: DEBUG: when applying layout to disk structure: laidOutStruct.OnDiskStructure: {Name:ubuntu-save PartitionFSLabel:ubuntu-save-enc Type:0FC63DAF-8483-4772-8E79-3D69D8477DE4 PartitionFSType:crypto_LUKS StartOffset:15717105664 Node: DiskIndex:0 Size:33554432}, *onDiskStruct: {Name:ubuntu-save PartitionFSLabel:ubuntu-save-enc Type:0FC63DAF-8483-4772-8E79-3D69D8477DE4 PartitionFSType:crypto_LUKS StartOffset:15717105664 Node:/dev/nvme0n1p4 DiskIndex:4 Size:33554432}
Jun 29 15:32:50 ubuntu snapd[2738]: logger.go:92: DEBUG: writing content on partition /dev/mapper/ubuntu-save
Jun 29 15:32:50 ubuntu snapd[2738]: logger.go:92: DEBUG: mounting "/dev/mapper/ubuntu-save" in "/run/snapd/gadget-install/dev-mapper-ubuntu-save" (fs type "ext4")
Jun 29 15:32:50 ubuntu kernel: EXT4-fs (dm-0): mounted filesystem with ordered data mode. Opts: (null). Quota mode: none.
Jun 29 15:32:50 ubuntu snapd[2738]: logger.go:92: DEBUG: unmounting "/run/snapd/snap-content/gadget"
Jun 29 15:32:50 ubuntu systemd[1]: Unmounting /run/snapd/snap-content/gadget...
Jun 29 15:32:50 ubuntu systemd[1]: run-snapd-snap\x2dcontent-gadget.mount: Deactivated successfully.
Jun 29 15:32:50 ubuntu systemd[1]: Unmounted /run/snapd/snap-content/gadget.
Jun 29 15:32:50 ubuntu snapd[2738]: logger.go:92: DEBUG: unmounting "/run/snapd/snap-content/kernel"
Jun 29 15:32:50 ubuntu systemd[1]: Unmounting /run/snapd/snap-content/kernel...
Jun 29 15:32:50 ubuntu systemd[1]: run-snapd-snap\x2dcontent-kernel.mount: Deactivated successfully.
Jun 29 15:32:50 ubuntu systemd[1]: Unmounted /run/snapd/snap-content/kernel.
Jun 29 15:32:50 ubuntu snapd[2738]: logger.go:92: DEBUG: 2023-06-29T07:32:50Z ERROR cannot write content: device or resource busy
Jun 29 15:32:50 ubuntu snapd[2738]: taskrunner.go:289: [change 6 "Finish setup of run system for \"classic\"" task] failed: cannot write content: device or resource busy
In subiquity, when running install-finish task to apply gadget snap to the storage, the defer function of writeFilesystem Content used to unmount the mounted partition may fail because it is busy due to unknown reason.
Following is the snippet of the debug log:
Jun 29 15:32:49 ubuntu snapd[2738]: logger.go:92: DEBUG: starting install-finish for "classic" (using encryption: true) on map[pc: 0xc000890e40] FromPartition: p.FilesystemType "crypto_LUKS", p.FilesystemLabel "ubuntu-data-enc" FromPartition: p.FilesystemType "crypto_LUKS", p.FilesystemLabel "ubuntu-save-enc" FromPartition: p.FilesystemType "ext4", p.FilesystemLabel "ubuntu-boot" FromPartition: p.FilesystemType "vfat", p.FilesystemLabel "" FromPartition: p.FilesystemType "vfat", p.FilesystemLabel "ubuntu-seed" OnDiskStructure : {Name:EFI System partition PartitionFSLabe l:ubuntu- seed Type:C12A7328- F81F-11D2- BA4B-00A0C93EC9 3B PartitionFSType :vfat StartOffset:1048576 Node: DiskIndex:0 Size:786432000}, *onDiskStruct: {Name:EFI System partition PartitionFSLabe l:ubuntu- seed Type:C12A7328- F81F-11D2- BA4B-00A0C93EC9 3B PartitionFSType :vfat StartOffset:1048576 Node:/dev/nvme0n1p1 DiskIndex:1 Size:786432000} gadget- install/ dev-nvme0n1p1" (fs type "vfat") gadget\ x2dinstall- dev\x2dnvme0n1p 1.mount: Deactivated successfully. OnDiskStructure : {Name:ubuntu-boot PartitionFSLabe l:ubuntu- boot Type:0FC63DAF- 8483-4772- 8E79-3D69D8477D E4 PartitionFSType :ext4 StartOffset: 14930673664 Node: DiskIndex:0 Size:786432000}, *onDiskStruct: {Name:ubuntu-boot PartitionFSLabe l:ubuntu- boot Type:0FC63DAF- 8483-4772- 8E79-3D69D8477D E4 PartitionFSType :ext4 StartOffset: 14930673664 Node:/dev/nvme0n1p3 DiskIndex:3 Size:786432000} gadget- install/ dev-nvme0n1p3" (fs type "ext4") gadget\ x2dinstall- dev\x2dnvme0n1p 3.mount: Deactivated successfully. OnDiskStructure : {Name:ubuntu-save PartitionFSLabe l:ubuntu- save-enc Type:0FC63DAF- 8483-4772- 8E79-3D69D8477D E4 PartitionFSType :crypto_ LUKS StartOffset: 15717105664 Node: DiskIndex:0 Size:33554432}, *onDiskStruct: {Name:ubuntu-save PartitionFSLabe l:ubuntu- save-enc Type:0FC63DAF- 8483-4772- 8E79-3D69D8477D E4 PartitionFSType :crypto_ LUKS StartOffset: 15717105664 Node:/dev/nvme0n1p4 DiskIndex:4 Size:33554432} ubuntu- save ubuntu- save" in "/run/snapd/ gadget- install/ dev-mapper- ubuntu- save" (fs type "ext4") snap-content/ gadget" snap-content/ gadget. .. snap\x2dcontent -gadget. mount: Deactivated successfully. snap-content/ gadget. snap-content/ kernel" snap-content/ kernel. .. snap\x2dcontent -kernel. mount: Deactivated successfully. snap-content/ kernel. 29T07:32: 50Z ERROR cannot write content: device or resource busy
Jun 29 15:32:49 ubuntu snapd[2738]: logger.go:92: DEBUG: writing content to partitions
Jun 29 15:32:49 ubuntu snapd[2738]: logger.go:92: DEBUG: OnDiskStructure
Jun 29 15:32:49 ubuntu snapd[2738]: logger.go:92: DEBUG: OnDiskStructure
Jun 29 15:32:49 ubuntu snapd[2738]: logger.go:92: DEBUG: OnDiskStructure
Jun 29 15:32:49 ubuntu snapd[2738]: logger.go:92: DEBUG: OnDiskStructure
Jun 29 15:32:49 ubuntu snapd[2738]: logger.go:92: DEBUG: OnDiskStructure
Jun 29 15:32:49 ubuntu snapd[2738]: logger.go:92: DEBUG: finding layout for "/dev/nvme0n1p1"
Jun 29 15:32:49 ubuntu snapd[2738]: logger.go:92: DEBUG: when applying layout to disk structure: laidOutStruct.
Jun 29 15:32:49 ubuntu snapd[2738]: logger.go:92: DEBUG: writing content on partition /dev/nvme0n1p1
Jun 29 15:32:49 ubuntu snapd[2738]: logger.go:92: DEBUG: mounting "/dev/nvme0n1p1" in "/run/snapd/
Jun 29 15:32:50 ubuntu systemd[1]: run-snapd-
Jun 29 15:32:50 ubuntu snapd[2738]: logger.go:92: DEBUG: finding layout for "/dev/nvme0n1p3"
Jun 29 15:32:50 ubuntu snapd[2738]: logger.go:92: DEBUG: when applying layout to disk structure: laidOutStruct.
Jun 29 15:32:50 ubuntu snapd[2738]: logger.go:92: DEBUG: writing content on partition /dev/nvme0n1p3
Jun 29 15:32:50 ubuntu snapd[2738]: logger.go:92: DEBUG: mounting "/dev/nvme0n1p3" in "/run/snapd/
Jun 29 15:32:50 ubuntu systemd[1]: run-snapd-
Jun 29 15:32:50 ubuntu snapd[2738]: logger.go:92: DEBUG: finding layout for "/dev/nvme0n1p4"
Jun 29 15:32:50 ubuntu snapd[2738]: logger.go:92: DEBUG: when applying layout to disk structure: laidOutStruct.
Jun 29 15:32:50 ubuntu snapd[2738]: logger.go:92: DEBUG: writing content on partition /dev/mapper/
Jun 29 15:32:50 ubuntu snapd[2738]: logger.go:92: DEBUG: mounting "/dev/mapper/
Jun 29 15:32:50 ubuntu kernel: EXT4-fs (dm-0): mounted filesystem with ordered data mode. Opts: (null). Quota mode: none.
Jun 29 15:32:50 ubuntu snapd[2738]: logger.go:92: DEBUG: unmounting "/run/snapd/
Jun 29 15:32:50 ubuntu systemd[1]: Unmounting /run/snapd/
Jun 29 15:32:50 ubuntu systemd[1]: run-snapd-
Jun 29 15:32:50 ubuntu systemd[1]: Unmounted /run/snapd/
Jun 29 15:32:50 ubuntu snapd[2738]: logger.go:92: DEBUG: unmounting "/run/snapd/
Jun 29 15:32:50 ubuntu systemd[1]: Unmounting /run/snapd/
Jun 29 15:32:50 ubuntu systemd[1]: run-snapd-
Jun 29 15:32:50 ubuntu systemd[1]: Unmounted /run/snapd/
Jun 29 15:32:50 ubuntu snapd[2738]: logger.go:92: DEBUG: 2023-06-
Jun 29 15:32:50 ubuntu snapd[2738]: taskrunner.go:289: [change 6 "Finish setup of run system for \"classic\"" task] failed: cannot write content: device or resource busy