blob: 5df2de6842f36885db3d10a841cba3839a63c3d1 [file] [log] [blame]
#!/bin/sh
OPT=$(getopt -n "$0" -o er -l i-really-mean-it,erase-backups -- "$@")
if [ $? != 0 ]; then
echo "getopt failed"
exit 1
fi
eval set -- "$OPT"
. /etc/utils.sh
ireallymeanit=0
erasebackups=0
while true; do
case "$1" in
-r|--i-really-mean-it ) ireallymeanit=1 ;;
-e|--erase-backups ) erasebackups=1 ;;
-- ) shift; break ;;
* ) echo "***Illegal option: $1" >&2; exit 1 ;;
esac
shift
done
if [ $ireallymeanit -eq 0 ]; then
echo
echo " * * *"
echo "THIS PROGRAM WILL WIPE ALL DATA PARTITIONS ON HARD DISK!"
echo " * * *"
echo
echo -n "Are you sure (y/n)? "
read yesno
[ "$yesno" = "y" ] || exit 1
echo
ireallymeanit=1
fi
# partition is kernel or rootfs
is_os_part()
{
ans=$(sgdisk -p $1 2>/dev/null |
while read number start end size unit code name; do
if [ "$number" = "$2" ]; then
case $name in
kernel*)
echo yes
;;
rootfs*)
echo yes
;;
esac
fi
done)
[ a"$ans" = ayes ]
}
sata_dev=$(find_sata_blkdev)
if [ ! -b$sata_dev ] ; then
echo not sata device: $sata_dev
exit 1
fi
# /config is partition 20
config_dev=${sata_dev}20
if is_os_part $sata_dev 20 ; then
echo cannot format software partition: $config_dev
exit 1
fi
for f in /etc/init.d/S[89]* ; do
$f stop
done
# force kill chroot binaries, just in case.
pkill -9 -f buffet_monitor
pkill -9 -f buffet
pkill -9 -f cryptohomed
pkill -9 -f chapsd
pkill -9 -f tcsd
# force kill SpaceCast binaries, just in case.
for f in /app/spacecast/* ; do
pkill -9 -f ${f#/app/spacecast/}
done
# assert TPM physical presence
chroot /chroot/chromeos /bin/tpmc ppon
# clear TPM ownership
chroot /chroot/chromeos /bin/tpmc clear
# enable TPM
chroot /chroot/chromeos /bin/tpmc enable
# activate TPM
chroot /chroot/chromeos /bin/tpmc activate
# try to unmount up to 20 times
for i in $(seq 20) ; do
umount -f /dev/mapper/config
mount | grep -q "/dev/mapper/config on" || break
done
dmsetup remove config
# TODO(erdi): modify cryptdev to find the correct device to remove.
losetup -d /dev/loop0
# try to unmount up to 20 times
for i in $(seq 20) ; do
umount -f $config_dev
mount | grep -q $config_dev || break
done
# format config partition
if ! mkfs.ext4 -q $config_dev ; then
# if we fail at this point, just try to delete everything
rm -rf /config/* /var/config/*
fi
# clear /var/media other than /var/media/data
mv /var/media/data /var/media/.data
rm -rf /var/media/*
mv /var/media/.data /var/media/data