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 if ( grep -q "^flags.*hypervisor" /proc/cpuinfo ); then
20 echo "Not excuting in Virtual machine"
22 function is_partition(){
24 if [ -e $SYS_BLOCK/$device/partition ];then
31 function is_removable(){
33 sysdev=$SYS_BLOCK/$device
34 if ( is_partition $device );then
35 removable=$(readlink -f $sysdev/..)/removable
37 removable=$sysdev/removable
39 if [ -e $removable ] && [ $(cat $removable) -eq 1 ];then
49 if [ -e $SYS_BLOCK/$device/loop ]; then
56 device_list=$(ls $SYS_BLOCK)
57 read -r -a hd_devices <<< $device_list
60 for hd_dev in ${hd_devices[@]}; do
61 if [ -b /dev/$hd_dev ] && (( is_removable $hd_dev ) || ( is_partition $hd_dev ) || ( is_loop $hd_dev )); then
62 echo "Removable or partition $hd_dev. Skipping..."
64 elif ! [ -b /dev/$hd_dev ]; then
67 wipefs --all /dev/$hd_dev
68 sgdisk -Z -o /dev/$hd_dev
69 dd if=/dev/zero of=/dev/$hd_dev bs=1M count=200