當咱們租用Linux雲主機時,若是服務即將到期,怎樣完全銷燬你所租用Linux雲主機呢?本文所轉載的shell腳本能夠很是完全地銷燬Linux雲主機,而且對當前所使用硬盤採用執行N次覆蓋寫操做對數據進行完全破壞(固然,對備份和快照沒有做用)。
html
如下是shell腳本內容:c++
#!/bin/bash # # This script will absolutely kill a RHEL/CentOS/Fedora server. Use with extreme caution. # Tested with several CentOS/RHEL versions only. Run as root user. # 10.20.11 Paul Venezia (pvenezia@pvenezia.com) # zeroscript="/var/ramdisk/zeroscript.sh" echo "******************************************************************* ** This will permanently kill this Linux system and erase every ** ** local disk and filesystem. In other words, you better be ** ** REALLY REALLY SURE you want to do this on this system. ** *******************************************************************" echo -n "Are you absolutely sure you want to do this? [yes|no]: "; read yn if [ -z $yn ] || [ $yn != "yes" ]; then echo "Aborting" exit 1 fi echo -n "How many zeroing passes? "; read zeropass if [ -z $zeropass ] || [ $zeropass -lt 1 ]; then echo "Invalid number of passes specified. Aborting." exit 1 fi echo -n "Automatically shutdown? [yes|no] "; read asd echo "Okay, here we go..." echo "Making and populating ramdisk (512MB)..." mkdir -p /var/ramdisk mount -t tmpfs none /var/ramdisk -o size=512m # You may need to adjust this depending on the amount of RAM in the box mkdir -p /var/ramdisk/var/run for f in dev bin lib lib64 sbin etc; do cp -pr /$f /var/ramdisk done cp -pr /var/run /var/ramdisk/var echo "Stopping services, it's probably safe to ignore any errors..." for s in httpd acpid anacron atd auditd autofs avahi-daemon bluetooth cpuspeed crond cups firstboot gpm haldaemon hidd hplip irqbalance iscsi iscsid kudzu lm_sensors lvm2-monitor mcstrans mdmonitor messagebus microcode_ctl netfs nfslock pcscd portmap rawdevices readahead_early restorecond rpcgssd rpcidmapd sendmail smartd sshd syslog vmware-tools xfs yum-updatesd; do service $s stop done echo "Placing zeroing script..." echo "#!/bin/bash" > $zeroscript for i in `fdisk -l | grep Disk | awk '{print$2}' | sed -e s/:// | grep -v /dev/md`; do DU=$DU" "$i DSK=`basename $i` BLKS=$((`grep -w $DSK /proc/partitions | awk '{print$3}'` * 2)) # account for 512/1k blocksizes BS=512 echo "echo \"Zeroing $i (dd if=/dev/zero of=$i bs=$BS count=$BLKS) ...\"" >> $zeroscript for (( c=1; c<=$zeropass; c++ )); do echo "echo \"Pass $c...\"" >> $zeroscript echo "dd if=/dev/zero of=$i bs=$BS count=$BLKS" >> $zeroscript done echo "dd if=/dev/zero of=$i bs=512 count=1" >> $zeroscript # Just to make sure done echo "echo \"Disk(s)$DU have been zeroed $zeropass times\"" >> $zeroscript if [ $asd = 'yes' ]; then echo "echo \"Shutting down...\"" >> $zeroscript echo "sleep 5 && /sbin/poweroff -n -d -f" >> $zeroscript fi chmod +x $zeroscript echo "Turning off swap..." && swapoff -a echo "Entering chroot..." chroot /var/ramdisk /`basename $zeroscript`
將上述shell保存爲shell文件(如:destroyLinuxOS.sh)並授予可執行權限(chmod +x destroyLinuxOS.sh),執行該腳本時,要依次回答 「yes 、 2 、 yes」 纔會真正開始完全銷燬Linux主機的程序,其中第一個 yes 表示贊成開始執行shell(防止誤執行),「2「爲指定「覆蓋寫」的寫次數(須要大於0),最後的 yes 表示完成「覆蓋寫」操做之後直接關機,若是回答不爲 yes 則不關機。shell
分析上述腳本可知,首先(1)在內存中建立內存磁盤(可在執行上述腳本前根據當前系統的相關文件夾的磁盤佔用狀況修改上述腳本中的 mount 語句的 size 屬性值爲合適大小);而後(2)從當前系統的相應目錄中複製相關文件到內存磁盤中;以後(3)開始中止當前系統中的已啓動服務(可根據你的主機服務狀況進行修改,注意不要中止 sshd 服務);最後(4)開始輸出相關shell腳本到變量 zeroscript 指定的腳本文件中(該腳本用來(a)完成對磁盤進行覆蓋寫操做 [即:銷燬磁盤數據],根據第三個輸入內容決定(b)是否直接關機);在完成前面四項操做之後,(5)切換系統根路徑到內存磁盤,並執行在 變量 zeroscript 中指定的腳本文件。over...bash
PS: 上述腳原本源於《如何將你的Linux服務器清空》文章所轉載的內容。
服務器