Mount a disk image¶
Source · io.systemd.MountFileSystem · systemd v257+ · Root or polkit
File-descriptor passing in both directions. The program opens a disk image
and hands the open file to systemd-mountfsd, which dissects it (GPT,
verity, signatures, image policy) and returns one mount file descriptor
per partition. No paths cross the socket.
Run it¶
Output (illustrative)
image: 536870912 bytes, 512-byte sectors, policy root=verity+signed+encrypted+unprotected+absent:usr=verity+signed+encrypted+unprotected+absent
root ext4 268435456 bytes writable=false fd=7
usr erofs 201326592 bytes writable=false fd=8
The code¶
How it works¶
- Sending.
ImageFileDescriptoris an*os.Filefield taggedvarlink:"imageFileDescriptor,fd". sdvarlink sends it withSCM_RIGHTSin the samesendmsg(2)as the JSON, which carries its index (0). - Borrowed input. The image stays open and owned by the program
(
defer img.Close()); sdvarlink never closes files you pass in. - Owned output. Each
PartitionInfo.MountFileDescriptoris a new*os.File(close-on-exec set) that the caller must close. Attach it withmove_mount(2), or inspect it via/proc/self/fd. - Authorization. mountfsd checks polkit;
AllowInteractiveAuthenticationlets it prompt when run from a terminal.