(&self, disk_crypt_key: &str, opts: &DstackOptions)
| 1112 | } |
| 1113 | |
| 1114 | async fn mount_data_disk(&self, disk_crypt_key: &str, opts: &DstackOptions) -> Result<()> { |
| 1115 | let name = "dstack_data_disk"; |
| 1116 | let mount_point = &self.args.mount_point; |
| 1117 | |
| 1118 | // Determine the device to use based on encryption settings |
| 1119 | let fs_dev = if opts.storage_encrypted { |
| 1120 | format!("/dev/mapper/{name}") |
| 1121 | } else { |
| 1122 | self.args.device.to_string_lossy().to_string() |
| 1123 | }; |
| 1124 | |
| 1125 | cmd!(mkdir -p $mount_point).context("Failed to create mount point")?; |
| 1126 | |
| 1127 | let disk_initialized = self.is_disk_initialized(opts); |
| 1128 | |
| 1129 | if !disk_initialized { |
| 1130 | self.vmm |
| 1131 | .notify_q("boot.progress", "initializing data disk") |
| 1132 | .await; |
| 1133 | |
| 1134 | if opts.storage_encrypted { |
| 1135 | info!("Setting up disk encryption"); |
| 1136 | self.luks_setup(disk_crypt_key, name)?; |
| 1137 | } else { |
| 1138 | info!("Skipping disk encryption as requested by kernel cmdline"); |
| 1139 | } |
| 1140 | |
| 1141 | match opts.storage_fs { |
| 1142 | FsType::Zfs => { |
| 1143 | info!("Creating ZFS filesystem"); |
| 1144 | cmd! { |
| 1145 | zpool create -o autoexpand=on dstack $fs_dev; |
| 1146 | zfs create -o mountpoint=$mount_point -o atime=off -o checksum=blake3 dstack/data; |
| 1147 | } |
| 1148 | .context("Failed to create zpool")?; |
| 1149 | } |
| 1150 | FsType::Ext4 => { |
| 1151 | info!("Creating ext4 filesystem"); |
| 1152 | cmd! { |
| 1153 | mkfs.ext4 -F $fs_dev; |
| 1154 | mount $fs_dev $mount_point; |
| 1155 | } |
| 1156 | .context("Failed to create ext4 filesystem")?; |
| 1157 | } |
| 1158 | } |
| 1159 | } else { |
| 1160 | self.vmm |
| 1161 | .notify_q("boot.progress", "mounting data disk") |
| 1162 | .await; |
| 1163 | |
| 1164 | if opts.storage_encrypted { |
| 1165 | info!("Mounting encrypted data disk"); |
| 1166 | self.open_encrypted_volume(disk_crypt_key, name)?; |
| 1167 | } else { |
| 1168 | info!("Mounting unencrypted data disk"); |
| 1169 | } |
| 1170 | |
| 1171 | match opts.storage_fs { |
no test coverage detected