| 1052 | } |
| 1053 | |
| 1054 | fn is_disk_initialized(&self, opts: &DstackOptions) -> bool { |
| 1055 | let device = &self.args.device; |
| 1056 | |
| 1057 | // For encrypted storage, just check if LUKS header exists |
| 1058 | // The filesystem check happens after the LUKS device is opened |
| 1059 | let has_luks = if opts.storage_encrypted { |
| 1060 | let result = cmd!(cryptsetup isLuks $device).is_ok(); |
| 1061 | if result { |
| 1062 | info!("LUKS header detected on {}", device.display()); |
| 1063 | } |
| 1064 | result |
| 1065 | } else { |
| 1066 | false |
| 1067 | }; |
| 1068 | |
| 1069 | // Check if filesystem exists |
| 1070 | let has_fs = match opts.storage_fs { |
| 1071 | FsType::Zfs => { |
| 1072 | // Check if zpool exists by trying to import it in readonly mode |
| 1073 | if cmd!(zpool import -N -o readonly=on dstack).is_ok() { |
| 1074 | cmd!(zpool export dstack).ok(); |
| 1075 | info!("ZFS pool 'dstack' detected"); |
| 1076 | true |
| 1077 | } else { |
| 1078 | false |
| 1079 | } |
| 1080 | } |
| 1081 | FsType::Ext4 if !opts.storage_encrypted => { |
| 1082 | // For unencrypted ext4, check the device directly |
| 1083 | if cmd!(blkid -s TYPE -o value $device) |
| 1084 | .map(|out| out.trim() == "ext4") |
| 1085 | .unwrap_or(false) |
| 1086 | { |
| 1087 | info!("ext4 filesystem detected on {}", device.display()); |
| 1088 | true |
| 1089 | } else { |
| 1090 | false |
| 1091 | } |
| 1092 | } |
| 1093 | FsType::Ext4 => { |
| 1094 | // For encrypted ext4, we can only check after LUKS is opened |
| 1095 | // So we rely on LUKS header presence as indicator |
| 1096 | has_luks |
| 1097 | } |
| 1098 | }; |
| 1099 | |
| 1100 | // For encrypted filesystems, we can only detect the filesystem after LUKS is opened |
| 1101 | // So we rely on LUKS header presence as the indicator for both ext4 and ZFS |
| 1102 | let initialized = if opts.storage_encrypted { |
| 1103 | has_luks |
| 1104 | } else { |
| 1105 | has_fs |
| 1106 | }; |
| 1107 | |
| 1108 | if !initialized { |
| 1109 | info!("No existing filesystem detected on {}", device.display()); |
| 1110 | } |
| 1111 | initialized |