LINUX LITE 7.2 FINAL RELEASED - SEE RELEASE ANNOUNCEMENTS SECTION FOR DETAILS


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tutorial: cloning your Linux Lite drive using the 'dd' command.
#1
This tutorial is for those of you who:
  • would like to have a solid backup clone of the whole drive (SSD or HDD) containing LL
  • are familiar with at least some basic use of the terminal
  • can use either gparted  (i.e. Partition Drives in Menu) or terminal, to check the drive designation, i.e. /dev/sda, /dev/sdb, /dev/sdc, etc
Reasons I use 'dd' for cloning and what I use it for.

It's a very simple tool for cloning LL, or any other distro, or  Windows OS, including any dual- or multi-booted systems.  The reason I started using 'dd' for cloning, is that I found other dedicated cloning software (e.g. clonezilla) too complicated to use:  the 'dd' command only takes up one line of code in the terminal.
I have LL installed on a 250GB drive. About once-a-week, I clone it to an identical drive (same size & make), via a USB port (the important thing here is that the backup drive has a  storage size that is either the same or bigger than the written space on the drive you want to clone from).  I do this as I have accumulated several virtual machines, important data, packages, symlinks, etc which, if lost, would cost me a huge amount of time and energy to reinstall - doesn't bear thinking about  :-[ .  Should LL on the internal drive on my laptop crash irretrievably (it has done at least a couple of times due to my tinkering around and the odd silly mistake), I just take the drive out of the PC, and replace it with the backup drive.  The backup drive is instantly recognised and works from the get-go.

How long will cloning it take?

Using setup 1 in my signature below as an example (an i7 laptop), where I'm cloning from a 250GB SSD  to an identical external SSD (via USB 3.0 connection)  it takes just under 3 hours, with a copy rate of around 23 to 27 MB/s. With older CPUs this will take longer, and it could be an activity you could just leave to run overnight.  Sometimes, I clone from a 250GB SSD to a 500GB SSD - the cloning time is the same - in this case what you end up with is 250GB of cloned space and 250GB of unallocated space. I have cloned to HHDs, but the copy rate is significantly slower, as you'd expect.  The backup drive doesn't need to be formatted for cloning - you can just leave it as unallocated space - cloning will overwrite it anyway. Also, don't forget to transfer any valuable data files on your backup drive before cloning to it, otherwise these will be lost !
Here's what you do to clone the whole drive:
  • put the back-up drive into a USB caddy and plug into the USB port on your PC
  • open gparted and make a note of the /dev/sdx designation of both drives, i.e.  the one you're copying from (inside your PC) , and the drive you're copying to (external backup drive), e.g. on my PC this  is /dev/sda (from), and /dev/sdc (to) - if you have only one drive bay in your PC then this might be /dev/sda (from) and /dev/sdb (to)
  • close gparted, then open the terminal and type the following, substituting 'x' and 'y' for the  correct designation of your drives:
Code:
sudo dd if=/dev/sdx of=/dev/sdy

So, if you are cloning from /dev/sda to /dev/sdb, you would enter:
Code:
sudo dd if=/dev/sda of=/dev/sdb status=progress

The term status=progress, means that you are given a live on-screen progress of cloning, i.e. the cumulative number of bytes transferred, the time passed from the start of cloning (seconds) and the transfer speed (MB/s). If you leave this term out, cloning will go ahead but without any indication of progress until cloning has completed.

After entering this you'll be asked for your password - type this then hit the ENTER key to start the cloning process.
When cloning is completed, the output from the terminal will have the following format:
Code:
[mike@G750 ~]$ sudo dd if=/dev/sdb of=/dev/sdc status=progress
[sudo] password for mike: 
488397168+0 records in
488397168+0 records out
250059350016 bytes (250 GB, 233 GiB) copied, 10865.2 s, 23.0 MB/s

In the output shown above, the internal drive that has LL installed on it (the drive that's being copied from) has the designation /dev/sdb - I just want to make the point that the designation of the drive, containing the operating system, is not always going to be /dev/sda, though it usually is.


Here's what you do if you want to clone just a specific partition, not the whole driveThe method is the same - you just need to quote the specific partition you want to clone 'from' and 'to' in the dd command.For example, if Linux Lite is installed as root on the partition /dev/sda1 on your PC, and you want to clone this to a partition on another drive named /dev/sdc1, then the command is as follows:
Code:
[mike@G750-mj ~]$ sudo dd if=/dev/sda1 of=/dev/sdc1 status=progress[sudo] password for mike: 48315625984 bytes (48 GB, 45 GiB) copied, 2200 s, 22.0 MB/s[[B94373887+0 records in94373887+0 records out
48319430144 bytes (48 GB, 45 GiB) copied, 2217.25 s, 21.8 MB/s

A WORD OF CAUTION (don't say you haven't been warned)! 

Should you enter the wrong /dev/sdx designation, you could risk wiping your computer clean - this is probably the reason that 'dd' is sometimes nicknamed 'disk-destroyer'. So, my advice is don't do this if you're drinking beers, distracted, or overly tired, otherwise ..! That said, I've been using 'dd' for the last three years and haven't had a problem with it. Just make sure the USB connection of the backup drive is secure (as a precaution don't move the PC or external drive during cloning). If the USB disconnects during cloning, even just momentarily, you'll have to restart the cloning process.
64bit OS (32-bit on Samsung[i] netbook) installed in [i]Legacy mode on MBR-formatted SSDs (except pi which uses a micro SDHC card):
2017 - Raspberry pi 3B (4cores) ~ [email protected] - LibreElec, used for upgrading our Samsung TV (excellent for the task)  
2012 - Lenovo G580 2689 (2cores; 4threads] ~ [email protected] - LL3.8/Win8.1 dual-boot (LL working smoothly)
2011 - Samsung NP-N145 Plus (1core; 2threads) ~ Intel Atom [email protected] - LL 3.8 32-bit (64-bit too 'laggy')
2008 - Asus X71Q (2cores) ~ Intel [email protected] - LL4.6/Win8.1 dual-boot, LL works fine with kernel 4.15
2007 - Dell Latitude D630 (2cores) ~ Intel [email protected] - LL4.6, works well with kernel 4.4; 4.15 doesn't work
Reply
#2
Thank You for the tutorial 8) , bookmarked.
Reply
#3
So you copy the whole disk? I like to clone only what is relevant, so for example the OS or data. The way Clonezilla does it. Livecd/-usb is also nice.
Or maybe I don't read you right?  Smile
Reply
#4
(03-30-2018, 09:46 AM)rijnsma link Wrote: So you copy the whole disk? I like to clone only what is relevant, so for example the OS or data. The way Clonezilla does it. Livecd/-usb is also nice.
Or maybe I don't read you right?  Smile

Thanks rijnsma.
Yes I copy the whole disk. The objective of the tutorial was to simply clone the whole OS drive as, in my case, LL occupies the whole drive. Sorry for not making that a bit clearer at the outset, though the title does refer to cloning a drive - not a partition.

Apparently, you can use 'dd' to clone specific partitions but I haven't had the need to do this yet.
I assume (NB: this is an assumption as I haven't checked it yet !)  that if you wanted to clone a specific partition (let's call it /dev/sda7 on drive /dev/sda) to drive /dev/sdb, then it would probably be as follows:

Code:
sudo dd if=/dev/sda7 of=/dev/sdb
64bit OS (32-bit on Samsung[i] netbook) installed in [i]Legacy mode on MBR-formatted SSDs (except pi which uses a micro SDHC card):
2017 - Raspberry pi 3B (4cores) ~ [email protected] - LibreElec, used for upgrading our Samsung TV (excellent for the task)  
2012 - Lenovo G580 2689 (2cores; 4threads] ~ [email protected] - LL3.8/Win8.1 dual-boot (LL working smoothly)
2011 - Samsung NP-N145 Plus (1core; 2threads) ~ Intel Atom [email protected] - LL 3.8 32-bit (64-bit too 'laggy')
2008 - Asus X71Q (2cores) ~ Intel [email protected] - LL4.6/Win8.1 dual-boot, LL works fine with kernel 4.15
2007 - Dell Latitude D630 (2cores) ~ Intel [email protected] - LL4.6, works well with kernel 4.4; 4.15 doesn't work
Reply
#5
You might also want to add the following to your command:


Code:
status=progress
Want to thank me?  Click my [Thank] link.
Reply
#6
(03-31-2018, 02:43 AM)torreydale link Wrote: You might also want to add the following to your command:
Code:
status=progress

Many thanks Torreydale.
That looks very useful, but could you add some detail about how to use it, i.e. do you add it to the 'dd' line of code as:

sudo dd if=/dev/sda of=/dev/sdb && sudo status=progress ?
64bit OS (32-bit on Samsung[i] netbook) installed in [i]Legacy mode on MBR-formatted SSDs (except pi which uses a micro SDHC card):
2017 - Raspberry pi 3B (4cores) ~ [email protected] - LibreElec, used for upgrading our Samsung TV (excellent for the task)  
2012 - Lenovo G580 2689 (2cores; 4threads] ~ [email protected] - LL3.8/Win8.1 dual-boot (LL working smoothly)
2011 - Samsung NP-N145 Plus (1core; 2threads) ~ Intel Atom [email protected] - LL 3.8 32-bit (64-bit too 'laggy')
2008 - Asus X71Q (2cores) ~ Intel [email protected] - LL4.6/Win8.1 dual-boot, LL works fine with kernel 4.15
2007 - Dell Latitude D630 (2cores) ~ Intel [email protected] - LL4.6, works well with kernel 4.4; 4.15 doesn't work
Reply
#7
I have used this method to clone one SDHC to another kept as a standby sysytem, where both cards are the same size. If I copy from my working system card to a partition on a hard disk, does the partition size have to be the same size as the card? E.g. 32GB sdhc  copied to 500GB HDD, do I have to create a 32GB partition on the HDD or can I just 'dd' without worrying about the HDD size? I'm confused by conflicting info from google.
1) Lenovo T520 i5 LL3.8 8GB ram, fast & stable
2) Medion P4 32bit LL3.8 1GB ram, quite fast & stable
3) eeePC 901 32bit LL3.8 1GB ram, fast & stable
4) eeePC 701 32bit LL3.8 1GB ram, slower & stable but small and light enough to travel with me to New Zealand when visiting family in Blenheim.
Reply
#8
(03-31-2018, 06:33 PM)justme2 link Wrote: If I copy from my working system card to a partition on a hard disk, does the partition size have to be the same size as the card?
E.g. 32GB sdhc  copied to 500GB HDD, do I have to create a 32GB partition on the HDD or can I just 'dd' without worrying about the HDD size? I'm confused by conflicting info from google.

Thanks for your question justme2.
No, the HDD partition size doesn't have to be the same size as the card (i.e. 32GB), unless the card has, or almost has, 32GB of written space on it.

The partition on the 500GB HDD that you're cloning to,  must either be the same size or larger (never smaller) than the written space you're cloning from on your 32GB SDHC.

Let's take a hypothetical example ...

The HDD could have say just a single partition spanning the whole drive.  If  the written space on your SDHC only takes up  say 20 out of the 32GB, then it will take up 20GB on the HDD following cloning, with 480 GB either left unused or, if your HDD is unformatted, then the remaining 480GB will be left as unallocated space.

Using the same example above, you could of course clone the 20GB of written space on your SDHC, to a partition smaller than 500GB on your HDD. The important thing here is  that the partition you're cloning to is  at least the same size or larger than 20GB. Just because the device you're cloning from has a 32GB capacity, doesn' t mean your partition on the HDD has to be 32GB. 

The key thing is that the size of the written space that you're copying from your SDHC will determine the minimum size  needed for the partition receiving the cloned copy on your HDD.

Hope this helps  Smile

Mike
64bit OS (32-bit on Samsung[i] netbook) installed in [i]Legacy mode on MBR-formatted SSDs (except pi which uses a micro SDHC card):
2017 - Raspberry pi 3B (4cores) ~ [email protected] - LibreElec, used for upgrading our Samsung TV (excellent for the task)  
2012 - Lenovo G580 2689 (2cores; 4threads] ~ [email protected] - LL3.8/Win8.1 dual-boot (LL working smoothly)
2011 - Samsung NP-N145 Plus (1core; 2threads) ~ Intel Atom [email protected] - LL 3.8 32-bit (64-bit too 'laggy')
2008 - Asus X71Q (2cores) ~ Intel [email protected] - LL4.6/Win8.1 dual-boot, LL works fine with kernel 4.15
2007 - Dell Latitude D630 (2cores) ~ Intel [email protected] - LL4.6, works well with kernel 4.4; 4.15 doesn't work
Reply
#9
Mike, thanks for clarifying, the partition I wish to clone to is much larger than the data size on the SDHC. A further thought has raised its head though, if I want to clone FROM a 500GB HD would I then need a destination device not less than 500GB. I think I need to make a much smaller partition on the HDD for linux lite (the total size on the SDHC is only about 26GB including data and lots of additional apps). So if I create a 32GB partition on the HDD, that will allow me to create clones from HDD back to SDHC. Does that sound feasible?

Some descriptions of the use of dd indicate that the whole drive is copied, including empty space, so I'm still not certain.

Thanks for your time,
another UK Mike!
1) Lenovo T520 i5 LL3.8 8GB ram, fast & stable
2) Medion P4 32bit LL3.8 1GB ram, quite fast & stable
3) eeePC 901 32bit LL3.8 1GB ram, fast & stable
4) eeePC 701 32bit LL3.8 1GB ram, slower & stable but small and light enough to travel with me to New Zealand when visiting family in Blenheim.
Reply
#10
(04-01-2018, 08:57 AM)justme2 link Wrote: if I want to clone FROM a 500GB HD would I then need a destination device not less than 500GB
Yes, that's true if you're selecting the whole of the 500GB drive to be cloned

Quote:I think I need to make a much smaller partition on the HDD for linux lite (the total size on the SDHC is only about 26GB including data and lots of additional apps). So if I create a 32GB partition on the HDD, that will allow me to create clones from HDD back to SDHC. Does that sound feasible?
Yes, that's sounds feasible. To be on the safe side you could make your partition on the HDD a bit smaller than your destination drive: maybe 30 or 31GB. It may well work with 32GB - perhaps I'm just being over-cautious ...

Have a good Easter Sunday  & don't eat too many chocolate eggs  8)
64bit OS (32-bit on Samsung[i] netbook) installed in [i]Legacy mode on MBR-formatted SSDs (except pi which uses a micro SDHC card):
2017 - Raspberry pi 3B (4cores) ~ [email protected] - LibreElec, used for upgrading our Samsung TV (excellent for the task)  
2012 - Lenovo G580 2689 (2cores; 4threads] ~ [email protected] - LL3.8/Win8.1 dual-boot (LL working smoothly)
2011 - Samsung NP-N145 Plus (1core; 2threads) ~ Intel Atom [email protected] - LL 3.8 32-bit (64-bit too 'laggy')
2008 - Asus X71Q (2cores) ~ Intel [email protected] - LL4.6/Win8.1 dual-boot, LL works fine with kernel 4.15
2007 - Dell Latitude D630 (2cores) ~ Intel [email protected] - LL4.6, works well with kernel 4.4; 4.15 doesn't work
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)