Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
debian-test:~# fdisk -l
Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000d4a5e
Device Boot Start End Blocks Id System
/dev/hda1 * 1 2188 17575078+ 83 Linux
/dev/hda2 2189 9729 60573082+ 5 Extended
/dev/hda5 2189 2310 979933+ 82 Linux swap / Solaris
/dev/hda6 2311 9729 59593086 83 Linux
Disk /dev/hdb: 20.4 GB, 20404101120 bytes
16 heads, 63 sectors/track, 39535 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Disk identifier: 0x00000000
Disk /dev/hdb doesn't contain a valid partition table
With the following command I made an image with the operating (debian) and partitions:
Code:
dd if = / dev / sda of = ~ / disk1.img
After I restore it in another disk with the command:
Code:
dd if = disk1.img of = / dev / sda
but does not boot.
I think it's the mbr.
Can you tell me a command to save the image and the mbr
and how to restore the image with the mbr ?
Thank you.
Click here to see the post LQ members have rated as the most helpful post in this thread.
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
Original Poster
Rep:
DD and the MBR
Quote:
Originally Posted by schneidz
@ awesome-machine, using dd is there a way to copy a 2 gb drive (boot sector + 1 partition) so that when it is restored to a 100 gb drive, it can be expanded to read/write the whole drive ?
You never want to use dd to duplicate the MBR of a drive together with only (1) only one of two or more partitions currently on the drive. DD is a real lifesaver in certain situations, but this isn't one of them!
Frequently it's better to partition and format the target drive and then copy the files as files rather than a whole file system.
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
Original Poster
Rep:
Can't image drive AND write the image to the same drive
Quote:
Originally Posted by dgi
Hello everyone.
Great job.
I have 2 hard disks.
Code:
debian-test:~# fdisk -l
Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000d4a5e
Device Boot Start End Blocks Id System
/dev/hda1 * 1 2188 17575078+ 83 Linux
/dev/hda2 2189 9729 60573082+ 5 Extended
/dev/hda5 2189 2310 979933+ 82 Linux swap / Solaris
/dev/hda6 2311 9729 59593086 83 Linux
Disk /dev/hdb: 20.4 GB, 20404101120 bytes
16 heads, 63 sectors/track, 39535 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Disk identifier: 0x00000000
Disk /dev/hdb doesn't contain a valid partition table
With the following command I made an image with the operating (debian) and partitions:
Code:
dd if = / dev / sda of = ~ / disk1.img
After I restore it in another disk with the command:
Code:
dd if = disk1.img of = / dev / sda
but does not boot.
I think it's the mbr.
Can you tell me a command to save the image and the mbr
and how to restore the image with the mbr ?
Thank you.
Ok, well, you can't make a disk image of an entire hard drive AND write it to the same drive, because you can't fit 2x the capacity of the drive on the drive. The notation '~/' means the user's home directory, such as /home/sam.
You must write the image file to a different drive. And, even if you do that, an image of an 80 Gig drive is not going to boot on a 20 Gig drive.
If you're trying a usb drive, it probably has U3 on it. You have to prepare the drive by getting rid of U3. Just write zeros to about 500 MB of it, maybe three times. Then, unplug the drive, plug it back in, partition and format it.
Last edited by AwesomeMachine; 10-01-2011 at 02:10 PM.
I notice that you mentioned the original drive was /dev/hda - you would need to use if=/dev/hda.
If you do want to use dd to clone a drive, it is probably best to use a live cd rather than using it on a mounted drive. In this case it would be:
Code:
dd if=/dev/sda of=/dev/sdb
The destination drive should be the larger drive. Once it has been copied, use gparted to resize the partitions to fill the new drive or alternatively add a new partition and move youre home directory to it.
very informative thread, indeed, sir!
I managed to get through 30 pages of commentary and search results before finally giving up and daring to post a n00besque question. I have an 8GB flash drive that I cannot re-format. Would not normally be crying in my beer, but I shelled out for a Lacie imakey that I don't want to just trash without putting up a fight, and in searching for an answer happened upon your thread.
Have used osx diskutil, gparted boot disk & even doze utils to try and re-format/re-partition, but they all come up with this (or similar) error:
Partition failed with the error: Unable to write to the last block of the device.
From what I gather, I can use the following command to zero out the thumbdrive.
Code:
dd if=/dev/zero of=/dev/disk2 bs=4k conv=notrunc
Is there anything else I can try so as to breathe some life back into the thing?
thanks,
pato
UPDATE: well, the command ran overnight and finished with:
Quote:
dd: /dev/disk2: end of device
1971467+0 records in
1971466+0 records out
8075124736 bytes transferred in 30762.418721 secs (262500 bytes/sec)
Running sudo diskutil eraseDisk FAT32 BLANK /dev/disk2 I get this:
Quote:
Error: -69760: Unable to write to the last block of the device
When I mount it in DiskUtility it still shows the previous volumes (i.e. disk2s1 disk2s2)
Of note are the differences in volume size, currently 7.73GB, but if I choose to re-partition and create 1 new volume in Disk Utility, it claims 8.08GB is the actual size.
Bueller... Bueller... Bueller...?
Last edited by patoperro; 10-13-2011 at 02:51 AM.
Reason: updated status
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
Original Poster
Rep:
Quickie copy to larger drive + defrag linux
Quote:
Originally Posted by schneidz
@ awesome-machine, using dd is there a way to copy a 2 gb drive (boot sector + 1 partition) so that when it is restored to a 100 gb drive, it can be expanded to read/write the whole drive ?
Here's the way I do it. And this is also how to defragment a linux file system. Use rsync.
Partition and format the 100 GB drive. I usually boot a live CD--Knoppix or so. Mount the hard drives, and:
#rsync -avH mount_point_one/*<sp>mount_point_two/
If you want to use dd, you must edit the partition table, which for all practical purposes requires too much care, precision and skill to make it feasible except in cases where valuable data is at stake.
You have to manually edit CHS and LBA boundaries in hex values expressed right to left. If you must add a byte to get the correct value, you have to know exactly how to shift the entire value.
It's kind of like training ill-mannered, vicious monkeys to climb sheer cliffs and pick tea leaves.
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
Original Poster
Rep:
Duplicating a drive to an image file on itself . . .
Quote:
Originally Posted by dgi
Hello everyone.
Great job.
I have 2 hard disks.
Code:
debian-test:~# fdisk -l
Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000d4a5e
Device Boot Start End Blocks Id System
/dev/hda1 * 1 2188 17575078+ 83 Linux
/dev/hda2 2189 9729 60573082+ 5 Extended
/dev/hda5 2189 2310 979933+ 82 Linux swap / Solaris
/dev/hda6 2311 9729 59593086 83 Linux
Disk /dev/hdb: 20.4 GB, 20404101120 bytes
16 heads, 63 sectors/track, 39535 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Disk identifier: 0x00000000
Disk /dev/hdb doesn't contain a valid partition table
With the following command I made an image with the operating (debian) and partitions:
Code:
dd if = / dev / sda of = ~ / disk1.img
After I restore it in another disk with the command:
Code:
dd if = disk1.img of = / dev / sda
but does not boot.
I think it's the mbr.
Can you tell me a command to save the image and the mbr
and how to restore the image with the mbr ?
Thank you.
You're trying to image the entire drive to a file on a partition on itself. So, there isn't enough space to hold the file.
The entire contents of the drive + an image file of the entire contents of the drive will not fit on the drive!
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
Original Poster
Rep:
Quote:
Originally Posted by patoperro
very informative thread, indeed, sir!
I managed to get through 30 pages of commentary and search results before finally giving up and daring to post a n00besque question. I have an 8GB flash drive that I cannot re-format. Would not normally be crying in my beer, but I shelled out for a Lacie imakey that I don't want to just trash without putting up a fight, and in searching for an answer happened upon your thread.
Have used osx diskutil, gparted boot disk & even doze utils to try and re-format/re-partition, but they all come up with this (or similar) error:
Partition failed with the error: Unable to write to the last block of the device.
From what I gather, I can use the following command to zero out the thumbdrive.
Code:
dd if=/dev/zero of=/dev/disk2 bs=4k conv=notrunc
Is there anything else I can try so as to breathe some life back into the thing?
thanks,
pato
UPDATE: well, the command ran overnight and finished with:
Running sudo diskutil eraseDisk FAT32 BLANK /dev/disk2 I get this:
When I mount it in DiskUtility it still shows the previous volumes (i.e. disk2s1 disk2s2)
Of note are the differences in volume size, currently 7.73GB, but if I choose to re-partition and create 1 new volume in Disk Utility, it claims 8.08GB is the actual size.
Bueller... Bueller... Bueller...?
If you use dd from the gnu coreutils package, which requires a C compiler and object linker, it will probably wipe the drive, but you need Linux.
OS X is BSD Unix covered in Apple's custom dessert topping, window dressing, and afflicted by Apple operating-system paralysis to make it safe for closed-source software publishers.
That's not quite Linux. Gparted doesn't work because the drive is reporting incorrect size parameters (last block is beyond the end of the drive).
Might wreck the proprietary magic, but that also means freedom from proprietary oppression:
dd if=/dev/zero of=/dev/sdb bs=64k count=1000
Hit the up arrow and repeat the command a few times. Only works in Linux! Right at the very beginning of the OP are instructions to use Linux to make any flash drive, or any drive, completely or partially encrypted.
It employs the same AES-256 encryption as LaCie's application, but you get the security of knowing that the government didn't pay you to create a backdoor key for your encrypted drives!
Commercial software offers empty promises, but Linux delivers open-source, so programmers have read the code, and if it weren't secure, any programmer is at liberty to correct the flaw.
The U.S government is able to securely approach proprietary-software enterprises and request that secret access be built in for use only by government.
But if it approached the open-source software community with such a request, everyone would know!
However, there is a software publisher that offers a distributed-computing password recovery application. So, every idle cpu cycle on every computer used by the government can be harnessed to recover passwords for encrypted volumes, any encrypted volume.
AES-256 encryption is secure, the passwords are not. So, here's a little trick: write the encrypted partition header to a flash drive and then write zeroes over the encrypted partition header on the HDD.
When you want to access the drive, write the header back before you open it.
Thanks for the reply. I'm not sure Ubuntu is Linux enough for you (too much pretty GUI), but I did check to make sure the gnu coreutils package is installed (there wouldn't be but one dd, right?). Unfortunately it didn't help. The partitions are still there with same error message as before. I appreciate the suggestion anyway and it's been a learning experience. Wasn't so keen on having an encrypted drive (the original wasn't encrypted either) but it's interesting to learn what it would take to make something truly safe from prying eyes.
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
Original Poster
Rep:
I don't mind Ubuntu . . .
Quote:
Originally Posted by patoperro
Hey Awesome,
Thanks for the reply. I'm not sure Ubuntu is Linux enough for you (too much pretty GUI), but I did check to make sure the gnu coreutils package is installed (there wouldn't be but one dd, right?). Unfortunately it didn't help. The partitions are still there with same error message as before. I appreciate the suggestion anyway and it's been a learning experience. Wasn't so keen on having an encrypted drive (the original wasn't encrypted either) but it's interesting to learn what it would take to make something truly safe from prying eyes.
pato
I just wish Ubuntu would quit calling itself an os and admit it's a bunch of propeller beanie candidates covering Debian with dessert topping.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.