这几天一直在琢磨GPT磁盘的分区表备份的问题,因为打算买个大点的硬盘来存资料。又因为担心数据安全的问题,有必要研究一下GPT磁盘的分区表备份和恢复。google了半天也没有个结果,就在virtualbox里面做了个试验。思路是先建立一个GPT分区,备份分区表后拷点东西进去,然后破坏掉分区表,再恢复,看看里面的东西还在不在。系统就用刚出的中标麒麟6.0了(下来一天才弄下来的,官方没给HASH值,要吐槽一下)1. [root@localhost ~]# parted /dev/sdb //用virtualbox虚拟的磁盘sdb来做试验mklabel //建立分区表gpt //使用GPT分区表unit //选择读取方式s //使用扇区来表示mkpart //建立一个分区分区名称? []? 1 //简单些就叫做1文件系统类型 ? [ext2]? //我输入了ext4,结果没正确建立起来起始点?2048 //从1M处开始,据说这样可以避免4k问题结束点?-1 //所有磁盘分一个区警告: You requested a partition from 2048s to 1023999s. The closest location we can manage is 2048s to 1023966s.Is this still acceptable to you?是/Yes/否/No? y (parted) p //查看一下,已经是GPT了,只是没格式化成我指定的ext4 Model: ATA VBOX HARDDISK (scsi)Disk /dev/sdb: 1024000sSector size (logical/physical): 512B/512BPartition Table: gptNumber Start End Size File system Name 标志1 2048s 1023966s 1021919s 1(parted) q //退出parted
2. [root@localhost ~]# mkfs.ext4 /dev/sdb1 //格式化成ext4mke2fs 1.41.10 (10-Feb-2009)文件系统标签=操作系统:Linux块大小=1024 (log=0)分块大小=1024 (log=0)Stride=0 blocks, Stripe width=0 blocks128016 inodes, 510956 blocks25547 blocks (5.00%) reserved for the super user第一个数据块=1Maximum filesystem blocks=6763315263 block groups8192 blocks per group, 8192 fragments per group2032 inodes per groupSuperblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409正在写入inode表: 完成 Creating journal (8192 blocks): 完成Writing superblocks and filesystem accounting information: 完成This filesystem will be automatically checked every 22 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.3. [root@localhost ~]# dd if=/dev/sdb of=/home/gg/sdb.img bs=512 skip=1 count=32 //备份分区表,跳过前面512字节的保护mbr,不知道这样是不是正确的记录了32+0 的读入记录了32+0 的写出16384字节(16 kB)已复制,0.00189832 秒,8.6 MB/秒4. [root@localhost ~]# mount /dev/sdb1 /home/gg/gz //然后把磁盘挂起来5. [root@localhost ~]# cp /usr/share/sounds/K* /home/gg/gz/ //拷些系统自带的音频过去6. [root@localhost ~]# umount /home/gg/gz //卸载掉7. [root@localhost ~]# dd if=/home/gg/sdb.img of=/dev/sdb bs=512 count=32 seek=1 //把刚才备份的分区表恢复过去记录了32+0 的读入记录了32+0 的写出16384字节(16 kB)已复制,0.00485221 秒,3.4 MB/秒8. [root@localhost ~]# mount /dev/sdb1 /home/gg/gz //挂上去,果然文件都还能用,能放出声音来9. [root@localhost ~]# dd if=/dev/urandom of=/dev/sdb bs=512 count=33 //把前面保护mbr和分区表都填了记录了33+0 的读入记录了33+0 的写出16896字节(17 kB)已复制,0.00560489 秒,3.0 MB/秒10. [root@localhost ~]# mount /dev/sdb1 /home/gg/gz //挂回去,奇怪数据还在,也能用11. [root@localhost ~]# umount /home/gg/gz //卸载掉12. [root@localhost ~]# parted /dev/sdb //再用parted看看GNU Parted 2.1(parted) p 错误: /dev/sdb: unrecognised disk label //已经找不到了 (parted) unit //换成扇区Unit? [compact]? s (parted) p //还是找不到 错误: /dev/sdb: unrecognised disk label (parted) q 13.[root@localhost ~]# dd if=/dev/zero of=/dev/sdb bs=512 count=1 //做个填零记录了1+0 的读入记录了1+0 的写出512字节(512 B)已复制,0.00410604 秒,125 kB/秒14. [root@localhost ~]# parted /dev/sdb //再看,还是不认GNU Parted 2.1(parted) p 错误: /dev/sdb: unrecognised disk label (parted) q15. [root@localhost ~]# dd if=/home/gg/sdb.img of=/dev/sdb bs=512 count=32 seek=1 //写回备份的分区表,但是破坏时前面用了count=33,所以估计还是有错记录了32+0 的读入记录了32+0 的写出16384字节(16 kB)已复制,0.00359624 秒,4.6 MB/秒16. [root@localhost ~]# parted /dev/sdb //再看,已经发现GPT分区,但是没有保护MBR,就是差的那一块,转成扇区查看也是一样的结果GNU Parted 2.1(parted) p 警告: /dev/sdb contains GPT signatures, indicating that it has a GPT table. However, it does not have a validfake msdos partition table, as it should. Perhaps it was corrupted -- possibly by a program that doesn'tunderstand GPT partition tables. Or perhaps you deleted the GPT table, and are now using an msdos partitiontable. Is this a GPT partition table?是/Yes/否/No? yes Model: ATA VBOX HARDDISK (scsi)Disk /dev/sdb: 524MBSector size (logical/physical): 512B/512BPartition Table: gptNumber Start End Size File system Name 标志1 1049kB 524MB 523MB ext4 1(parted) uintalign-check TYPE N check partition N for TYPE(min|opt) alignmentcheck NUMBER do a simple check on the file systemcp [FROM-DEVICE] FROM-NUMBER TO-NUMBER copy file system to another partitionhelp [COMMAND] print general help, or help on COMMANDmklabel,mktable LABEL-TYPE create a new disklabel (partition table)mkfs NUMBER FS-TYPE make a FS-TYPE file system on partition NUMBERmkpart PART-TYPE [FS-TYPE] START END make a partitionmkpartfs PART-TYPE FS-TYPE START END make a partition with a file systemmove NUMBER START END move partition NUMBERname NUMBER NAME name partition NUMBER as NAMEprint [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all foundpartitions, or a particular partitionquit exit programrescue START END rescue a lost partition near START and ENDresize NUMBER START END resize partition NUMBER and its file systemrm NUMBER delete partition NUMBERselect DEVICE choose the device to editset NUMBER FLAG STATE change the FLAG on partition NUMBERtoggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBERunit UNIT set the default unit to UNITversion display the version number and copyright information of GNU Parted(parted) unit Unit? [compact]? s (parted) p //提示大概是已经识别GPT,但是没有找到保护MBR,就是前面多填的那块。 警告: /dev/sdb contains GPT signatures, indicating that it has a GPT table. However, it does not have a validfake msdos partition table, as it should. Perhaps it was corrupted -- possibly by a program that doesn'tunderstand GPT partition tables. Or perhaps you deleted the GPT table, and are now using an msdos partitiontable. Is this a GPT partition table?是/Yes/否/No? yes Model: ATA VBOX HARDDISK (scsi)Disk /dev/sdb: 1024000sSector size (logical/physical): 512B/512BPartition Table: gptNumber Start End Size File system Name 标志1 2048s 1023966s 1021919s ext4 1(parted) mklabel //重新建一次 新的磁盘标签类型? gpt 警告: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want tocontinue?是/Yes/否/No? yes 警告: /dev/sdb contains GPT signatures, indicating that it has a GPT table. However, it does not have a validfake msdos partition table, as it should. Perhaps it was corrupted -- possibly by a program that doesn'tunderstand GPT partition tables. Or perhaps you deleted the GPT table, and are now using an msdos partitiontable. Is this a GPT partition table?是/Yes/否/No? yes (parted) p Model: ATA VBOX HARDDISK (scsi)Disk /dev/sdb: 524MBSector size (logical/physical): 512B/512BPartition Table: gptNumber Start End Size File system Name 标志(parted) unitUnit? [compact]? s (parted) p Model: ATA VBOX HARDDISK (scsi)Disk /dev/sdb: 1024000sSector size (logical/physical): 512B/512BPartition Table: gptNumber Start End Size File system Name 标志(parted) q 信息: You may need to update /etc/fstab. 17. [root@localhost ~]# dd if=/home/gg/sdb.img of=/dev/sdb bs=512 count=32 seek=1 //重新写回备份的分区表记录了32+0 的读入记录了32+0 的写出16384字节(16 kB)已复制,0.00257806 秒,6.4 MB/秒18.[root@localhost ~]# parted //再看,结果从分区角度看已经正常了GNU Parted 2.1使用 /dev/sdaWelcome to GNU Parted! Type 'help' to view a list of commands.(parted) unit Unit? [compact]? s (parted) select 新设备? [/dev/sda]? /dev/sdb 使用 /dev/sdb(parted) p Model: ATA VBOX HARDDISK (scsi)Disk /dev/sdb: 1024000sSector size (logical/physical): 512B/512BPartition Table: gptNumber Start End Size File system Name 标志1 2048s 1023966s 1021919s ext4 1(parted) q 19. [root@localhost ~]# mount /dev/sdb1 /home/gg/gz //准备挂回去,怎么没发现文件系统类型,要求要指定mount: you must specify the filesystem type20. [root@localhost ~]# mount -t ext4 /dev/sdb1 /home/gg/gz //指定了要挂回去,还是不行mount: special device /dev/sdb1 does not exist21. [root@localhost ~]# partprobe //让系统自己再识别一次Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (设备或资源忙). As a result, it may not reflect all of your changes until after reboot.22. [root@localhost ~]# mount /dev/sdb1 /home/gg/gz //这次直接挂上去了,进去看看,所有文件都正常使用。问题:不知道这种方法是不是正确的,主要是dd命令上有没有错误。
posted on 2014-04-07 20:17
回忆之城 阅读(569)
评论(0) 编辑 收藏 引用 所属分类:
unix/linux