LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-19-2019, 05:59 PM   #1
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,432

Rep: Reputation: 110Reputation: 110
How do I clone a bootable partition?


The part that I can't figure out is how to copy not just the partition but also Grub from one disk to a smaller one, which has a very different partition table. I can't just copy the MBR over.

What would the best approach be?
 
Old 07-19-2019, 06:15 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
Couple of comments:
- you should never "just copy the MBR over". Way too much potential for breaking things.
- "clone" implies a sector-by-sector copy. I try to restrict its use to forensic copies.

You could simply copy the data (rsync, cp, whatever you prefer) then chroot in and update grub. Clean and easy - also easy to repeat in need if you get it wrong.
 
Old 07-19-2019, 06:33 PM   #3
verndog
Member
 
Registered: Oct 2007
Posts: 278

Rep: Reputation: 67
fsarchiver will clone your partition copying only used data and can restore to a smaller partition as long as the data fits.

Be advised that it also copies the UUID.

Last edited by verndog; 07-19-2019 at 06:35 PM.
 
1 members found this post helpful.
Old 07-20-2019, 08:02 PM   #4
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,982

Rep: Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626
Some folks have luck shrinking the original partition to just below new disk and use a backup scheme. Clonezilla and others might work then on partition.

gparted of course will copy partition and you might be able to re-install grub to this new disk first or later.
 
1 members found this post helpful.
Old 07-23-2019, 05:44 AM   #5
sharle
LQ Newbie
 
Registered: Jul 2019
Posts: 3

Rep: Reputation: Disabled
Quote:
Originally Posted by lucmove View Post
The part that I can't figure out is how to copy not just the partition but also Grub from one disk to a smaller one, which has a very different partition table. I can't just copy the MBR over.

What would the best approach be?
Do you want to copy a bootable drive with MBR partition table to a new drive with GPT partition table?
 
Old 07-23-2019, 11:00 AM   #6
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,432

Original Poster
Rep: Reputation: 110Reputation: 110
Quote:
Originally Posted by sharle View Post
Do you want to copy a bootable drive with MBR partition table to a new drive with GPT partition table?
Both were GPT or so I thought. Now I'm not so sure anymore.

I copied the partition with xfs_copy, booted some way I forget now and reinstalled Grub.

But I had to convert the new disk to MBR because Grub flat out rejected the GPT table.

Whatever. It's kind of solved. I didn't do exactly what the thread's title says, but now it seems that is not really possible. Even if it is, it has to be done in two separate, unrelated stages.
 
Old 07-23-2019, 12:47 PM   #7
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by lucmove View Post
It's kind of solved. I didn't do exactly what the thread's title says, but now it seems that is not really possible.
As the "boot part" is not IN the partition, you either clone the complete drive (not just the partition) to an identically sized disk (or just a very little bit larger) or you will have to do it in two operations, the partition as an image or archive backup and the boot part separately. As the "whole drive" clone copies the partition table too, no matter if it's MBR or GPT, it is not copyable to a smaller drive, although you may get away with if it's just the itsy bitsy smaller (but don't forget to shrink the fs afterwards, otherwise usage may try to use blocks that just aren't there).
To a really smaller drive (on which even the partition image won't fit) you'll need something like a file-by-file backup.

PS: as both gpt as well as grub use "the blocks inbetween MBR and 1st partition" grub will have to be REinstalled when you go from classic MBR to a disk with GPT, as grub has to know that to avoid using that gpt part of the partition table. It has to write its data behind the gpt blocks.

Last edited by ehartman; 07-23-2019 at 12:54 PM. Reason: Addition about gpt
 
1 members found this post helpful.
Old 07-23-2019, 07:32 PM   #8
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
You don't have to use "that" grub. You can use grub from other bootable media. The "c" CLI mode has a configfile command to use the grub.cfg on another device.

GRUB> ls
GRUB> configfile (hd1,msdos2)/boot/grub/grub.cfg

I tend to go this route so I'm booted to a clone before I install grub FROM the clone. You can install it in a chroot to, but it depends on what you're more "comfortable" with. Granted that you should "update-grub" in the chroot of the clone to have a grub.cfg that works. And update the /etc/fstab so update-grub uses something useful.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Open-spec SBC is a clone of a clone of a clone of a Raspberry Pi 3 LXer Syndicated Linux News 0 04-25-2018 04:56 PM
Linux 64 bit fresh install, created clone on cd, want to use clone on another laptop... apollo1980 Linux - Software 12 10-12-2017 02:59 PM
I need to Clone a Red Hat drive and install clone in HP server drummer54 Linux - Newbie 14 03-07-2009 04:15 PM
Clone a bootable Partition with which itself is a disk of a Xen DomU t-mow Linux - General 1 12-09-2008 04:03 PM
bugzilla: to clone, or not to clone? The00Dustin Linux - Newbie 1 05-24-2008 05:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration