Barrier coverage is a fundamental application in wireless sensor networks, which are widely used for smart cities. In applications, the sensors form a barrier for the intruders and protect an area through intrusion detection. In this paper, we study a new branch of barrier coverage, namely warning barrier coverage (WBC). Different from the classic barrier coverage, WBC has the inverse protect direction, which moves the sensors surrounding a dangerous region and protects any unexpected visitors by warning them away from the dangers. WBC holds a promising prospect in many danger keep out applications for smart cities. For example, a WBC can enclose the debris area in the sea and alarm any approaching ships in order to avoid their damaging propellers. One special feature of WBC is that the target region is usually dangerous and its boundary is previously unknown. Hence, the scattered mobile nodes need to detect the boundary and form the barrier coverage themselves. It is challenging to form these distributed sensor nodes into a barrier because a node can sense only the local information and there is no global information of the unknown region or other nodes. To this end, in response to the newly proposed issue of the formation of barrier cover, we propose a novel solution AutoBar for mobile sensor nodes to automatically form a WBC for smart cities. Notably, this is the first work to trigger the coverage problem of the alarm barrier, wherein the regional information is not pre-known. To pursue the high coverage quality, we theoretically derive the optimal distribution pattern of sensor nodes using convex theory. Based on the analysis, we design a fully distributed algorithm that enables nodes to collaboratively move toward the optimal distribution pattern. In addition, AutoBar is able to reorganize the barrier even if any node is broken. To validate the feasibility of AutoBar, we develop the prototype of the specialized mobile node, which consists of two kinds of sensors: one for boundary detection and another for visitor detection. Based on the prototype, we conduct extensive real trace-driven simulations in various smart city scenarios. Performance results demonstrate that AutoBar outperforms the existing barrier coverage strategies in terms of coverage quality, formation duration, and communication overhead.