0

I have a HDD with 2 OS partitions. Together they are too large to clone onto my flash drive. And I just want to clone the smaller one anyway.

/dev/sda1: 120GB HDD partition 1(Lubuntu)
/dev/sda2: 8GB HDD partition 2(Debian) <-- want to clone this one
/dev/sdb: 32GB flash drive

I have tried cloning the single partition via dd, but it does not seem bootable:

sudo dd if=/dev/sda2 of=/dev/sdb status=progress bs=1M

When I try to boot into this flash drive, I click on "boot USB", but the bios menu resets to the grub boot menu where my only 2 options are the 2 HDD OS's.

  1. Is the issue that I am trying to clone a single partition (sda2) to a drive (sdb)? Should I be using sdb1 instead?

  2. Since I am only cloning a single partition, does that mean the boot (grub) content is missing?

How do I successfully clone a single OS partition to a bootable flash drive?

1

Kind of both of your hypothesis were correct. As you dumped a partition directly to your thumb drive, there was no partition table and, consequently, no boot sector.

To make it work there are a few ways you can go. Generally, first create a partition table on the drive, then create the actual partition (/dev/sdb1) that will have the OS data and then copy the data there. Once you have all the data you can install grub to the drive also.

That could be done rather quickly with a few commands, but it's easy to make (terrible) mistakes if you're not used to the terminology and concepts. So I'll suggest you the following, which should be easier:

  1. BACKUP! EVERYTHING! You may lose ALL data, permanently, by missing a single character sometimes.
  2. Install and open gparted:
    • Select your thumb drive (make sure it's not selecting your disk)
    • Menu Device > Create partition table
    • You can go with msdos
    • Create a primary partition, as ext4, on your unallocated space
    • Set the new partition as bootable
    • Apply and exit
  3. Run sudo dd if=/dev/sda2 of=/dev/sdb1; sudo resize2fs /dev/sdb1.
  4. Boot into your debian system (I'm assuming your thumb drive is still /dev/sdb after booting Debian)
    • Run blkid /dev/sdb1 to get the UUID of the partition you've cloned.
    • Backup your current /etc/fstab file.
    • Update it so that it refers the / path to the UUID you got, like the following:
...
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda1 during installation
UUID=5405ba56-dd62-48b4-b381-976162b4957c /               ext4    errors=remount-ro 0       1
  • Run sudo mount /dev/sdb1 /mnt; sudo cp -p /etc/fstab /mnt/etc/fstab; sudo umount /mnt to copy this new fstab to your thumb drive Debian.
  • Run sudo grub-install /dev/sdb
  • Restore the backup you made of the /etc/fstab file to the original state (with the UUID of the disk partition, not thumb drive partition).
  • These commands should not have messed up with the boot of your disk Debian, but now that the fstab is back to what it was, run sudo update-grub just to make sure, as updates can have read the /etc/fstab file while it was set to the thumb drive.

This should have cloned the contents of your debian partition to the thumb drive and created a boot environment for it. I cannot validate this procedure here right now, so be aware that, even though I've done such things a few times, the commands here are untested right now.

3
  • Thank you. I am getting an error on the last step sudo grub-install /dev/sdb. "Installing for i386-pc platform. grub-install: error: failed to get canonical path of /cow". Also, I am using a live usb to do these commands.
    – rys
    Jan 3 at 16:37
  • @rys , I have updated the answer to comprehend the fstab part. Note that I have instructed the use of the original Debian system to avoid configuration issues (grub will setup based on the running system, and ideally it should be the exact same system). Most times grub worked "universally" for me though. You can try your luck with the live system following the same instructions I have updated. The error you mention is related to be running from the live system and the new instructions may solve it.
    – Zip
    Jan 3 at 17:14
  • 1
    Before I read your comment, I followed askubuntu.com/a/1258461. But I had some grub issue. I decided to run grub-install, as you mentioned, from the original Debian system and still had a grub issue (forget the exact error). But from there I was able to follow your directions for fstab and it worked :). I did it in a slightly different way, I mounted the flash drive and used chroot and updated fstab directly. Thanks so much.
    – rys
    Jan 3 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.