DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 8th July 2008
spiderpig spiderpig is offline
Port Guard
 
Join Date: May 2008
Posts: 29
Default Cloning an entire drive?

I've had this question for some time, but have never asked...

There is an article from the OpenBSD Journal which covered cloning drives:

http://undeadly.org/cgi?action=artic...20080319204706

The author advocates using dump & restore on each partition, but if cloning the entire drive is the goal, why not simply back up the c partition?

Reply With Quote
  #2   (View Single Post)  
Old 8th July 2008
Eam404 Eam404 is offline
Port Guard
 
Join Date: May 2008
Posts: 21
Default

Well if by C drive you mean /root partition then no you cant just backup your root partition. Things like usrland apps and /etc configuration files are all items that most people like to back up; at lest generally. Dump/Restore works great on BSD systems. If you are wanting a more universal way to "clone" your hard drive the dd command works wonders. Heres a small example: http://www.linuxweblog.com/dd-image

Last edited by Eam404; 8th July 2008 at 07:57 PM. Reason: Fsck
Reply With Quote
  #3   (View Single Post)  
Old 8th July 2008
spiderpig spiderpig is offline
Port Guard
 
Join Date: May 2008
Posts: 29
Default

Quote:
Originally Posted by Eam404 View Post
Well if by C drive you mean /root partition then no you cant just backup your root partition.
Actually, my terminology was quite precise. I assume what you refer to /root is typically /dev/wd0a on a bootable IDE drive, or /dev/sd0a is the bootable drive is SCSI. Otherwise, /root is merely a directory, not a partition.

Again, given that /dev/wd0c or /dev/sd0c both covers the entire disk and is accessible, why not clone it instead of each individual partition?
Reply With Quote
  #4   (View Single Post)  
Old 8th July 2008
revzalot's Avatar
revzalot revzalot is offline
Shell Scout
 
Join Date: May 2008
Posts: 123
Default

Thanks for bringing this up and I've always wanted to find a way to clone drives. One way is using g4u but I want to clone a drive by using the same box. Is it possible to just go into single user mode, mount the two drives:

# mount -a /dev/wd0
# mount -a /dev/wd1

then use the copy command:

# cp /dev/wd0 /dev/wd1


Is this possible assuming both drives are the same capacity.

Last edited by revzalot; 8th July 2008 at 08:43 PM.
Reply With Quote
  #5   (View Single Post)  
Old 8th July 2008
spiderpig spiderpig is offline
Port Guard
 
Join Date: May 2008
Posts: 29
Default

Quote:
Originally Posted by revzalot View Post
Is this possible assuming both drives are the same capacity.
No, for at least two reasons. One, cp(1) copies relative to the user that invoked the command. If cp is invoked as a user other than root, then permissions may be set which will not allow that user to read and copy. If root is used to copy files, then individual user ownership is lost. Two, consider all the device nodes residing in /dev. The script /dev/MAKEDEV is executed at installation time for a reason.
Reply With Quote
  #6   (View Single Post)  
Old 8th July 2008
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 3,319
Default

Quote:
Originally Posted by spiderpig View Post
No, for at least two reasons.
If the drive being cloned is a boot drive, you should also consider running installboot(8) as the article suggests.
Reply With Quote
  #7   (View Single Post)  
Old 8th July 2008
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Banned
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Default

For one revzalot, /dev/{wd0,wd1} don't exist.. and you can't use "cp" like that either.

To backup a partition, I use either tar or dump, if I'm trying to recover something.. like lost data off a friends thumb drive or w/e, I duplicate the partition with dd...

$ dd if=/dev/rsd0i of=partition-image.img
Then work on the image instead of risking the drive..
Reply With Quote
  #8   (View Single Post)  
Old 8th July 2008
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,167
Default

Quote:
Originally Posted by spiderpig View Post
The author advocates using dump & restore on each partition, but if cloning the entire drive is the goal, why not simply back up the c partition?
dump and restore act on filesystems.From the dump man page
Code:
NAME
     dump - filesystem backup
Label "c" does not have a filesystem, it is just a virtual label encompassing the complete disk, which could have other operating systems installed.

From one of my systems
Code:
$ disklabel wd0
# Inside MBR partition 0: type A6 start 63 size 81915372
# /dev/rwd0c:
type: ESDI
disk: ESDI/IDE disk
label: WDC WD3200AAKS-2
flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 255
sectors/cylinder: 16065
cylinders: 38913
total sectors: 625142448
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0           # microseconds
track-to-track seek: 0  # microseconds
drivedata: 0 

16 partitions:
#                size           offset  fstype [fsize bsize  cpg]
  a:         81787372               63  4.2BSD   2048 16384    1 
  b:           128000         81787435    swap                   
  c:        625142448                0  unused      0     0      
  i:        204796620        163830870 unknown                   
  j:        256509855        368627490   MSDOS
See, no fstype defined for label "c"

I have some other OS's installed
Code:
]fdisk wd0
Disk: wd0       geometry: 38913/255/63 [625142448 Sectors]
Offset: 0       Signature: 0xAA55
          Starting         Ending        LBA Info:
 #: id      C   H  S -      C   H  S [       start:        size ]
------------------------------------------------------------------------
*0: A6      0   1  1 -   5098 254 63 [          63:    81915372 ] OpenBSD     
 1: A9   5099   0  1 -  10197 254 63 [    81915435:    81915435 ] NetBSD      
 2: A5  10198   0  1 -  22945 254 63 [   163830870:   204796620 ] FreeBSD     
 3: 05  22946   0  1 -  38912 254 63 [   368627490:   256509855 ] Extended DOS
These all lie within the boundaries of the label "c" size of 625,142,448 sectors.
dump is not so smart it can backup NetBSD, FreeBSD and the extended DOS partitions in one go
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
  #9   (View Single Post)  
Old 8th July 2008
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Banned
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Default

What J65nko posted *should* be common knowledge, I'm not even going to comment on Eam404's reply.
Reply With Quote
Old 9th July 2008
Eam404 Eam404 is offline
Port Guard
 
Join Date: May 2008
Posts: 21
Default

Welp, I guess thats what I get for not reading the whole post...
Reply With Quote
Old 7th May 2012
neant neant is offline
New User
 
Join Date: Apr 2012
Posts: 4
Default

I hope there's no problem necroing this thread since it's a sticky.

For the record, cloning an entire disk through the c partition can be done, using dd(1), HOWEVER, this can be dangerous. There's this post from 2001* by Randy Lewis, it basically says:

Code:
Example:
                                       +----------- bytes/sector value
                                      /    +------- sectors/cylinder value
                                     /    /
% dd if=/dev/rsd0c of=/dev/rsd1c bs=512x4520 count=7931 <cr>
                                                    /
                 total cyliders to copy value -----+

First, the obvious, dd is dumb, it shouldn't be run on a mounted/live disk. Incomplete files, inconsistent fs and partitions marked unclean since they were never unmounted are to be expected. Which means the clone will have to be fscked before use.
Second, OpenBSD 5.0+ (AFAIK) uses disk UIDs, fstab by default doesn't have /dev/sd0 in it, it has the ID of the disk instead. The clone, since it's an exact copy, will end up having the same DUID as the original, not good if the clone isn't pulled out of the system right away. The ID can be changed using disklabel(8)'s "i" command in the editor.

On the other hand, assuming two identical disks, reboot the system from a live cd (single-user works too I guess), run dd, pull out the clone and keep it in storage, and you've got a full system backup ready to go in as long as it takes to change a disk.
Didn't actually try this last part yet, but there's no reason it shouldn't work, right?

* Can't post links. The post can be found at marc.info /?l=openbsd-tech&m=100765187914137&w=2, or just search for "Re: Cloning OpenBSD disks (amended / expanded explanation)" on google.
Reply With Quote
Old 14th August 2019
joancatala joancatala is offline
Port Guard
 
Join Date: Jun 2011
Posts: 34
Default

Some days ago I wrote a brief article on my personal blog about cloning easily disks (whether they are SATA or SSD). The article is in catalan: http://joancatala.net/node/1419

Basically, I burned an Ubuntu (live) image.
I did dd if=MY_DISK of=BACKUP_COPY_IMAGE bs=32M
I changed the disk, from SATA3 to SSD.
Finally I did if=BACKUP_COPY_IMAGE of=MY_NEW_DISK bs=32M

Simple solution.
Buy some beers, because is a lot of time (about 4/5 hours).
Reply With Quote
Old 14th August 2019
bsd-keith bsd-keith is offline
Real Name: Keith
Open Source Software user
 
Join Date: Jun 2014
Location: Surrey/Hants Border, England
Posts: 362
Default

My 'cloning' program has been dd for quite some time, on both BSDs & Linux distros.

Fairly easy to learn to use, & found on most, if not all, unix like systems, just double check your input & output before committing.
__________________
Linux since 1999, & also a BSD user.
Reply With Quote
Reply

Thread Tools
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
which drive is what? knasbas OpenBSD Installation and Upgrading 2 20th July 2009 09:48 PM
cannot open cloning pty l2fl2f FreeBSD General 2 10th December 2008 07:30 PM
How can I tell if my USB drive is bad? JMJ_coder General Hardware 4 3rd November 2008 04:12 AM
backing up an entire system mwotsch FreeBSD General 5 14th July 2008 03:00 PM
Cloning FreeBSD tomcatf14 FreeBSD Installation and Upgrading 5 10th June 2008 09:26 PM


All times are GMT. The time now is 02:42 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick