LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-18-2012, 07:00 PM   #1
shakira19
Member
 
Registered: Sep 2012
Posts: 34

Rep: Reputation: Disabled
dd


hi,

I have bought a new ssd (240GB). I'd like to copy my system there and start using it. So far I had only one 3TB disk, which is composed of (from gparted):
/dev/sda5 - unknown (977KiB) flags: bios_grub
/dev/sda1 - ntfs (1TiB)
/dev/sda2 - ext4 (1TiB)
/dev/sda3 - ntfs (766.58GiB)
/dev/sda4 - ext4 (27.94GiB, the system)

sdb - unallocated (no fs).

I'd like to copy the sytem to my new hard drive, which is /dev/sdb. I have initialized its new partition table with msdos, so it's ready to use I guess.

I am opened to suggestions as to how many partitions I should create, but I think one for everything (/) is enough, so I want the whole system to be copied to sdb and the rest of the space available there should be part of the new partition (so say, the system is currently using 12 of the 27GB available, and then on the ssd it would be 12 of the 250 available).

Thanks
 
Old 10-18-2012, 07:31 PM   #2
Basher52
Member
 
Registered: Mar 2004
Location: .SE
Distribution: Fedora, CentOS, Scientific Linux
Posts: 275

Rep: Reputation: 10
http://www.linuxquestions.org/questi...ommand-362506/

Quote:
To clone an entire hard disk. /dev/sda is the source. /dev/sdb is the target:
Code:

dd if=/dev/sda of=/dev/sdb bs=4096 conv=notrunc,noerror
With this you don't need to do anything with the new drive, it's all copied from the old
 
Old 10-18-2012, 07:38 PM   #3
shakira19
Member
 
Registered: Sep 2012
Posts: 34

Original Poster
Rep: Reputation: Disabled
hi, thanks for the answer. Could you elaborate on the options please ? I knew dd was to be used (as hinted in the title) but not how to use it. bs is the block size, right? Does it matter if that's not the block size of /dev/sda ? Also, what is notrunc, noerror ? And more importantly, /dev/sda is larger than /dev/sdb. Is that not an issue ?

I knew dd was to be used so what I wanted is not just a copy-pasted answer but rather an answer that corresponds to my issue. I'm not a developer and I don't want to make a mistake, my system/data is at risk.

Thanks.
 
Old 10-18-2012, 07:50 PM   #4
Basher52
Member
 
Registered: Mar 2004
Location: .SE
Distribution: Fedora, CentOS, Scientific Linux
Posts: 275

Rep: Reputation: 10
Oh the new disk is smaller, didn't pick up on that, well then you can't use this
You could just clone the sda4 and sda5 also using dd and in this case clone the partitions.
Create them on the SSD, at same size, then use dd for it: dd if=/dev/sda4 of=/dev/sdb4 bs=4096 conv=notrunc,noerror

You can read up on dd, ex. here: http://en.wikipedia.org/wiki/Dd_%28Unix%29 and http://linux.about.com/od/commands/l/blcmdl1_dd.htm
 
Old 10-18-2012, 11:20 PM   #5
mreff555
Member
 
Registered: Sep 2011
Location: Philly
Distribution: Gentoo
Posts: 470

Rep: Reputation: Disabled
noerror continues writing in the event of an error.
notrunc tells dd to continue writing (zero's I think) to the drive after it has finished the input

I generally don't use noerror. notrunc is usually a good idea when cloning drives. Any other time, you probably wouldn't want to use it.
 
Old 10-19-2012, 12:10 AM   #6
shakira19
Member
 
Registered: Sep 2012
Posts: 34

Original Poster
Rep: Reputation: Disabled
So suming up, I have to create a new partition of sdb first, to the exact same size of sda4, and then use dd if=/dev/sda4 of=/dev/sdb1 bs=4096, right ?
What's the bs=4096, is it significant ? What if sdb1 or sda4 is not of size 4066?
And what is sda5, should it be copied too ?
 
Old 10-19-2012, 12:56 AM   #7
ukiuki
Senior Member
 
Registered: May 2010
Location: Planet Earth
Distribution: Debian
Posts: 1,030

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by shakira19 View Post
...
/dev/sda5 - unknown (977KiB) flags: bios_grub
/dev/sda1 - ntfs (1TiB)
/dev/sda2 - ext4 (1TiB)
/dev/sda3 - ntfs (766.58GiB)
/dev/sda4 - ext4 (27.94GiB, the system)
...
Here a DD guide: http://www.linuxquestions.org/questi...ommand-362506/.
Also take a look at Clonezilla.
Do you have 2 systems installed? Windows and GNU/Linux? My suggestion is to use about 3 partitions(if you want to keep things really simple), if you do have dual boot, so for your GNU/Linux side, / and swap(same size of you RAM for swap, some people might think different on this one thou), still you could use the swap partition on your HDD(if you plan to keep both) also it is a good idea to have your temp directories mounted on tmpfs(or on your HDD), for your Windows just 1 partition.
Here one good reading about partitions: http://linuxmafia.com/~karsten/Linux...partition.html
Normally when I set up partitions I create 4: /boot, /, swap and /home, but that is me, some people like to have some other partitions for other things.
About its size, for /boot 300MB will normally be enough, for / well that depends on how much you plan to install and which distribution is in use, usually goes between 10MB and 50MB for a desktop computers, /home all the space left. Well this on a single hard drive, but it is possible to spread partitions to more than one drive, all just depends on what you want to do.

Here some recommended links about SSDs:
https://wiki.archlinux.org/index.php...tion_Alignment
http://chriseiffel.com/everything-li...-ssd-on-linux/
http://www.linuxquestions.org/questi...rth-it-892817/

Regards
 
Old 10-20-2012, 07:35 PM   #8
mreff555
Member
 
Registered: Sep 2011
Location: Philly
Distribution: Gentoo
Posts: 470

Rep: Reputation: Disabled
Yes, that dd resource is great. you should definitely read.

Now as far as your current setup, I didn't really pay attention to that until now. You have two extremely large ext4 partitions, and no swap. The impression I have is that you want to duel boot your systems, /dev/sdb1 would be you linux root. /dev/sda2 will stay where it is.
Is that your home directory?

here is what I would recommend if that is the case. You need a swap, that is going to make this a little tricky. You are also going to have to reconfigure grub.
Open gparted or whatever. Make two partitions

/sdb1 >28GB type technally doesn't matter
/sdb2 4-8GB SWAP(type 82) and that actually just my opinion but should have at least 2GB

start the machine with a boot disk. (you need to have /dev/sda4 unmounted)

double check your partition information to make sure it's the same with the boot disk
assuming it is:
Code:
dd if=/dev/sda4 of=/dev/sdb1 conv=notrunc
every person you talk to will give you a different recommendation about byte sizes. The bottom line is that the slower the read the longer the copy takes but the safer it is. There is also the opinion that it is better for your write to be slower than your read. The default options are pretty slow 512 bytes. Modern machine should be able to handle simultaneous read/writes without a problem.

Next you need to make your swap

Code:
mkswapfs /dev/sdb2
if this command doesn't work you may have to wait til you boot your system.

You are also going to have to modify grub so it knows where to find your kernel and root partition.

I'm hesitant to tell you how to do that because I don't like grub2, which I assume you are using.
So do it the old fashioned way. I know it's pretty easy, I'm sure you can find a tutorial on it.

you will also need to update /etc/fstab with your new partition information.
don't forget to include the swap

If you've managed to do all that you "should" be able to boot into your new system.

Good luck
 
Old 10-22-2012, 01:32 AM   #9
shakira19
Member
 
Registered: Sep 2012
Posts: 34

Original Poster
Rep: Reputation: Disabled
I actually have just one partition (/dev/sda4, of size roughly 30GB, of which 15 GB are used) that holds my whole system (/). I don't have extra partitions for /home, /boot or anything else. The 3 other partitions in my disk are just for data, they're not related to the linux system. I don't have a swap partition either, I have more memory than I will ever need (8GB).

So all I want is to copy these 15 GB into my new disk, and start using this new disk as my system. The system should then show that 15 out of 240 GB are used (as opposed to 15 out of 30 GB right now).

From what I understand (please tell me if I'm right), I have to:
1. create a new partition of size 240 GB in this new disk, with the same characteristics (file system type, block size, ...) as sda4 (the partition where my current system resides).
2. Use a live cd to issue the following command: dd if=/dev/sda4 of=/dev/sdb1 conv=notrunc
3. (??) I didn't really understand the grub/fstab part. What am I to do exactly ?

Thanks.
 
Old 10-22-2012, 10:29 AM   #10
mreff555
Member
 
Registered: Sep 2011
Location: Philly
Distribution: Gentoo
Posts: 470

Rep: Reputation: Disabled
1. yes, you should create a new partition on sdb. it should be the first. Honestly the settings shouldn't really matter. dd overwrites everything in it's path including partition information. The only reason you are actually making sdb1 is so you can tell dd exactly where you want to put it.
Now that I realize you are copying a larger system to a smaller system, after you have made your 30G partition and loaded the system with a boot disk
I would issue your dd command like this.

Code:
dd if=/dev/sda4 of=/dev/sdb1 bs=1M count=16000
The extra entries tell dd to read and write exactly 1024 bytes at a time. Count tells it to repeat this process 16000 times. This way dd is only trying to copy 16GB
Another thing you may want to do after this step is run gparted and make sure /dev/sdb1 is flagged as bootable.

As for grub and fstab.

Grub is installed on your MBR of /dev/sda, but it looks for the configuration files on a hard drive. A hard drive which is about to move. You need to update this otherwise you will get an "operating system not found" message.
Depending on the version of grub you have the instructions are a bit different, but this will need to be updated.

/etc/fstab is a file that tells your system what to mount, where it is and how to do it. Once again, those files are about to move. This will need to be updated.
 
Old 10-22-2012, 12:51 PM   #11
shakira19
Member
 
Registered: Sep 2012
Posts: 34

Original Poster
Rep: Reputation: Disabled
Ok thanks, but I still don't know how to 'update' grub and fstab. How can I do that ? I think I have grub2, if it matters.
And the systems are not of different sizes, because the system is in a partition of 30 GB, and the new disk has 250GB. So there is plenty of space for the system to be copied to the new disk. The other partitions of the first disk should remain still, they contain data.
 
Old 10-22-2012, 06:35 PM   #12
mreff555
Member
 
Registered: Sep 2011
Location: Philly
Distribution: Gentoo
Posts: 470

Rep: Reputation: Disabled
You know you would save yourself a whole lot of time if you just copied your home directory to a flash drive and re installed linux.
 
Old 10-22-2012, 06:42 PM   #13
shakira19
Member
 
Registered: Sep 2012
Posts: 34

Original Poster
Rep: Reputation: Disabled
hehe. I guess. But I would like to know how this dd works, I might want to do it some other time and it's good to know how it works. Besides, I don't want to have to reconfigure my whole system, reinstall the packages/software, etc. Can you please just tell me how to update grub2 and fstab ?
 
Old 10-22-2012, 10:26 PM   #14
mreff555
Member
 
Registered: Sep 2011
Location: Philly
Distribution: Gentoo
Posts: 470

Rep: Reputation: Disabled
Unlike old grub, grub 2 requires a configuration script to be run. that will be a problem since you are updating it from a boot disk. Honestly, I'm not sure how to do it. That's why I stick with old grub. As for /etc/fstab, basically just change the entry that has /dev/sda4 to /dev/sdb1.

However, honestly, whatever you have configured it couldn't take that long to restore. you are much better off starting from scratch. and while you're at it, give yourself some swap.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off




All times are GMT -5. The time now is 04:01 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration