Abstract In distributed cyber-physical systems, the data should be stored in a reliable and available manner in the face of multiple kinds of failures. Considering that the storage space is an expensive part, erasure codes are storage-efficient alternatives to replication for fault tolerance. However, traditional erasure codes, e.g. Reed–Solomon (RS) codes, impose a huge burden on disk I/O and network resources for recovering unavailable data in case of node failures. In this paper, we introduce a new set of erasure codes called Sub-packetization Tunable Codes (STC). STC can reduce the amount of required information during recovering a failed block, while still allowing a significant reduction in storage overhead. The customized recovery method in STC needs each block to be sub-packetized, and the repair bandwidth decreases as the number of sub-packets increases. However, high sub-packetization may result in some extra costs. In STC, the sub-packetization level of our codes is tunable so that storage systems can weigh the balance between sub-packetization costs and repair bandwidth. In addition, our STC can be constructed as a family of double regenerating codes (DRC) to improve the repair performance in hierarchical distributed situations, whose idea is to trade the abundant inner-rack bandwidth for constrained cross-rack bandwidth.