4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 SYS_BLOCK="/sys/class/block"
19 function is_partition(){
21 if [ -e $SYS_BLOCK/$device/partition ];then
28 function is_removable(){
30 sysdev=$SYS_BLOCK/$device
31 if ( is_partition $device );then
32 removable=$(readlink -f $sysdev/..)/removable
34 removable=$sysdev/removable
36 if [ -e $removable ] && [ $(cat $removable) -eq 1 ];then
44 device_list=$(ls $SYS_BLOCK)
45 read -r -a hd_devices <<< $device_list
48 for hd_dev in ${hd_devices[@]}; do
49 if [ -b /dev/$hd_dev ] && (( is_removable $hd_dev ) || ( is_partition $hd_dev )); then
50 echo "Removable or partition $hd_dev. Skipping..."
53 wipefs --all /dev/$hd_dev
54 sgdisk -Z -o /dev/$hd_dev
55 dd if=/dev/zero of=/dev/$hd_dev bs=1M count=200