我有一个运行在1024 GB磁盘(磁盘A)上的Ubuntu 14.04,该磁盘最多只能使用130 GB的空间。我想将其克隆到256 GB SSD磁盘(磁盘B)。但是失败了。
gparted
为了成功准备磁盘B,我曾经将磁盘A上的分区缩小到只有180 GB。
你能告诉我哪里错了吗?
我确实备份了磁盘A的分区表。
└──╼ $ sudo sfdisk -d /dev/sda
# partition table of /dev/sda
unit: sectors
/dev/sda1 : start= 2048, size= 997376, Id=83, bootable
/dev/sda2 : start= 999424, size= 15624192, Id=82
/dev/sda3 : start= 16623616, size=337020928, Id=83
/dev/sda4 : start= 0, size= 0, Id= 0
/dev/sda1
为/boot
,/dev/sda2
为swap
,/dev/sda3
为/
。
sudo sfdisk -d /dev/sda > partition.table
然后,我尝试将分区表还原到磁盘B(/dev/sdc
在这种情况下)。
我替换sda
为sdc
in file partition.table
。然后看起来像:
# partition table of /dev/sdc
unit: sectors
/dev/sdc1 : start= 2048, size= 997376, Id=83, bootable
/dev/sdc2 : start= 999424, size= 15624192, Id=82
/dev/sdc3 : start= 16623616, size=337020928, Id=83
/dev/sdc4 : start= 0, size= 0, Id= 0
然后,成功执行还原。
sudo sfdisk /dev/sdc < partition.table
sudo dd if=/dev/sda1 of=/dev/sdc1
sudo dd if=/dev/sda2 of=/dev/sdc2
sudo dd if=/dev/sda3 of=/dev/sdc3
迁移之后,可以挂载和查看/ dev / sdc上的那些分区。
但是,如果我将SSD磁盘(磁盘B)插入笔记本电脑,则在某些Thinkpad BIOS输出后它将无法启动。没有错误出现,但光标闪烁...
我敢打赌,引导时BIOS甚至没有检测到/boot
磁盘B。
你能帮助我吗?非常感谢!
有人建议我用grub-install /dev/sdc
这个技巧。
我搜索了grub-install
有能力的-链接让我尝试。而且我非常确定磁盘A(已安装MBR)。
完成后dd if=/dev/sda of=/dev/sdc bs=512 count=1
,仅插入磁盘B,它仍然是闪烁的光标。完全没有BIOS之后。
完成后,grub-install --boot-directory=/mnt/mypartition/boot /dev/sdc
我只启动了磁盘B。
但是grub控制台出来了。并报告
现在它正在工作!!!
这是我的操作方法,在运行磁盘A作为OS以及磁盘B(/dev/sdc
)作为USB硬盘的PC上。
sudo mount /dev/sdc3 /mnt
sudo mount /dev/sdc1 /mnt/boot
sudo grub-install --boot-directory=/mnt/boot /dev/sdc3
然后去了/mnt/boot/grub/grub.cfg
,我确实替换了文件中的2件事grub.cfg
。(请记住要授予该文件的写许可权grub.cfg
)
hd1
为hd0
/dev/sdc3
为/dev/sda3
然后保存文件。->关闭计算机电源->通过SATA插入磁盘B,并永久取出磁盘A。->启动->看到grub错误,但仍然启动
如果遇到错误Error: invalid environment block. Press any key to continue
,请检查此问题以解决。按任意键将引导您的系统。https://askubuntu.com/questions/191852/error-invalid-environment-block-press-any-key-to-continue
sudo -i
然后,逐个运行每个命令。
cd /boot/grub
rm grubenv
grub-editenv grubenv create
grub-editenv grubenv set default=0
grub-editenv grubenv list
update-grub
现在重新启动,它将起作用!
This is how I shrank my 1024GB disk hard drive and migrated the entire system to a new 256GB SSD disk.
I am not familiar with sfdisk
, but you could accomplish the same thing, partition table AND MBR back up using dd
.
This was in my notes and I am not the author...
Backing up the MBR
The MBR is stored in the the first 512 bytes of the disk. It consist of 3 parts:
Clone the MBR as mbr.img:
dd if=/dev/sdX of=/path/mbr_file.img bs=512 count=1
Clone partition as pX.img
dd if=/dev/sdX of=/path/pX.img bs=1024
Restore the MBR to new disk
dd if=/path/mbr_file.img of=/dev/sdY bs=512
Restore Partition to new disk
dd if=/path/pX.img of=/dev/sdX bs=1024
OR
You could use clonezilla
to make an image of the OS and restore it on a disk that already has the partitions created.
这样,您可能需要在新磁盘上重新安装grub
grub-install
grub-mkconfig
并在“新”操作系统中设置交换分区。
mkswap
swapon
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句