sh 备份和恢复guid分区表(GPT)的危险方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 备份和恢复guid分区表(GPT)的危险方法相关的知识,希望对你有一定的参考价值。

#!/bin/sh

# The number of partitions in the partition table could be varied and uncertain. 
#    So is the length of backup file.

# Only works in limited situations
# Won't work if any new partition table is added to the partition table later
# Require sudo privilege
# Use the code only after you know what you're doing. Use at your own risk.
# Change the variables in the script if necessary
# Erase the disk with disk manager and reinstall if the restoration of GPT file doesn't work. 
#    But first back up the data.

# https://askubuntu.com/questions/57908/how-can-i-quickly-copy-a-gpt-partition-scheme-from-one-hard-drive-to-another

# Get the number of partitions in the partition table and save it in a file.
parted -ms /dev/sda print |tail -1|cut -b1 > ./partition_count.txt
# parted -ms sed '$s/:.*//p;d' > ./partition_count.txt


read -r partition_count < ./partition_count.txt
echo "partition_count: " $partition_count

byte_size=$(((128 * $partition_count) + 1024))
echo "byte size: " $byte_size

dd if=/dev/sda of=./GPT_TABLE_BACKUP bs=1 count=$byte_size

echo "Done."

以上是关于sh 备份和恢复guid分区表(GPT)的危险方法的主要内容,如果未能解决你的问题,请参考以下文章

备份和恢复Android手机分区的方法

Windows GPT磁盘GUID结构详解

UUID和GUID有啥区别?属于分区还是属于整块硬盘?在GPT模式硬盘上微软用16字128位节表

分区表GPT和MBR有什么区别

thinkpad--Windows8 F11一键恢复方法

GUID Partition Table (GPT)