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.
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,606
Rep:
AwesomeMachine, what happens if one copies a given partition onto a smaller partition? I was going to test this because I want to backup a partition which is far from full onto a smallish partition that I know is big enough to take all the data.
dd if=/dev/hda5 (30gb but only 3 gb of data) of=/dev/hdb14 (5gb of space)
Will this work? Will dd spit an error and stop when the destination is full? (wihthout trying to write to the next partition for example).
I'd rather know beforehand than being sorry
Last edited by Emmanuel_uk; 11-28-2005 at 07:07 AM.
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
Original Poster
Rep:
Bigger Partition to Smaller Partition With DD
Quote:
Originally posted by Emmanuel_uk AwesomeMachine, what happens if one copies a given partition onto a smaller partition? I was going to test this because I want to backup a partition which is far from full onto a smallish partition that I know is big enough to take all the data.
dd if=/dev/hda5 (30gb but only 3 gb of data) of=/dev/hdb14 (5gb of space)
Will this work? Will dd spit an error and stop when the destination is full? (wihthout trying to write to the next partition for example).
I'd rather know beforehand than being sorry
The only difference between a big partition and a small partition, besides size, is the partition table. If you are copying say sda to sdb, an entire drive with a single partition, sdb being smaller than sda, then you have to do:
You can put the skip and seek anywhere you want, I just put them there to show what they go to. Skip skips input blocks at the beginning of the media(sda). Seek skips over so many blocks on the output media before writing(sdb). By doing this, you leave the first 4k bytes on each drive the same. This is eight sectors. The first sector is the Master Boot Record (MBR). This contains the partition table. You don't want to tell a drive it is bigger than it really is by writing a partition table from a larger drive to a smaller drive. In my example, we wanted to use a byte size (bs) of 4k or 4096 bytes. This speeds up the copy from the default 512 byte bs. But, your are limited in how small of a skip or seek you can make. In this example, the smallest skip or seek is 1, or 4096 bytes. Since the first 63 sectors of the drives are empty, except sector 1, the MBR, we can skip eight sectors without any problem missing part of the boot sector. One sector on a hard drive is 512 bytes.
Now, if you are copying say sda3 to sda2, this is different. What you want to do is this:
dd if=/dev/sda3 of=/dev/sda2 bs=4096 conv=noerror
Even if these are primary partitions, they are still logical to the main partition. Do not use the conv=notrunc option. Without notrunc, multiple blocks of zeros get abbreviated with a string of asterisks, saving a lot of space. if you use notrunc, all the zeros will be written out. On a smaller partition you want to save room. If you write out all the zeros, the smaller partition won't be big enough.
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,606
Rep:
Thanks. This was eductional. And my little test went half ok
As expected
Code:
dd: writing `/dev/hdb15': No space left on device
3957708+0 records in
3957707+0 records out
This was from ext3 to ext3, different size partitions (source 12Gb onto 4 Gb destination, on purpose,
although I want to test 12 Gb onto 14 Gb as well)
Fdisk says the destination was 15830829 blocks
3957708 * 4=15830832
So about ok
#ls -l
ls: blablafolder: Input/output error
some files and folder are visible are catable good
Filesystem Size Used Avail Use% Mounted on
/dev/hdb15 51G 12G 39G 24% /mnt/toto
Look really wrong because hdb15 is only 4 Gb/ So it took the info from the source directory
Not good
Code:
# e2fsck -f /dev/hdb15
e2fsck 1.36 (05-Feb-2005)
/dev/hdb15: recovering journal
e2fsck: unable to set superblock flags on /dev/hdb15
If this fails, try looking toward the end of the post for a link to dd_rescue. dd_rescue can start at the end of the tape, and restore backwards. You can also try "skip=1" to skip the first sector of the tape. If the tape is bad, at least the first sector is bad because you are getting 0 + 0 records. That means the tape fails before sector 1. If this fails, Sanderson Forensics sells a utility to get data off damaged tape media. Once you buy it, you can just download it. I've never used it, but I have used other programs made by Paul Sanderson and they are good.
I have also heard, but not verified, that dd has trouble with QIC-80 drives.
I'd like to back up my root partition, so as to be able to resize the partition, and I want to make sure I'd be doing this right before I mess anything up.
I'd need to run
Code:
dd if=/dev/hda3 of=/backup<an HD mounted across a network> bs=4096 conv=notrunc,noerror
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
Original Poster
Rep:
Quote:
Originally Posted by microsoft/linux
I'd like to back up my root partition, so as to be able to resize the partition, and I want to make sure I'd be doing this right before I mess anything up.
I'd need to run
Code:
dd if=/dev/hda3 of=/backup<an HD mounted across a network> bs=4096 conv=notrunc,noerror
If you are going across a network, there are instructions in my original post for using netcat with dd. Just go back to the first page and do a search for "netcat" with you browser. I don't think dd works with NFS mount points. With netcat you can specify the actual device file on the remote backup machine. Also, you can back up root to a file, and even mount the file as a file system, which is a good test to see if the backup file is any good, on the remote machine. If you want the new partition smaller, don't use notrunc. Notrunc copies all the zeroes in empty sectors. Without notrunc, sections of the disk which are solid zeroes are abbreviated with a string of asterisks. So if you have 3000 sectors in a row, which are all blank, without notrunc, all 3000 sectors only consume 10 bytes. Any sector that has anything in it besides zeroes will not be truncated. I use notrunc for copying complete drives where everything has to end up in the right spot. For a single partition you don't need notrunc. If you want to see how much is on the root partition now do a <df -h>. Then you'll have some idea of the actual space needed. I really appreciate these replies because they give me all kinds of new ideas.
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
Original Poster
Rep:
dd netcat
Yes, that is how you do it. The "bs=16065b" is an example of how to specify one cylinder per block. In reality, smaller bs values, such as 2048 or 2k, 4096 or 4k, 8192 or 8k are good for network backups. In fstab, make sure the NFS drives specify "rsize=8192,wsize=8192". This will make the backup work better.
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
Original Poster
Rep:
Blocks
Quote:
Originally Posted by microsoft/linux
what does all of that mean? A block is just a section of an HD right? Why do I need to be worried about the blocks?
Optimal block size, specified in the dd command by bs= gives optimal transfer rates. On a machine with even a minimal amount of ram, dd's default bs=512 is quite slow. 512 is one sector at a time. I have found this to be slow. I prefer larger block sizes to speed transfers. These larger block sizes, specified with bs=, enable less read/writes, because the dd program reads and writes larger chuncks of data. Of course, too big of a block size will slow things down because flushing the dd buffers does take some time.
With urandom it is possible to read a byte size of 100. With /dev/random you need to do bs=1. urandom does not have this restriction.
This is not correct. Both random and urandom can in theory produce output of any byte size. They use the kernel's entropy pool to compute the random numbers. This entropy pool is filled with random noise gathered from device drivers and other sources. The important difference between the two is that /dev/random produces only as many random bits as the entropy pool contains. This results in high quality randomness, which is neccessary for kryptographic keys. In case the user demands more random bytes than currently contained in the entropy pool, the process stops until the entropy pool is refilled (waggling your mouse helps). /dev/urandom, however, does not have this restriction. If the user demands more bits than currently in the entropy pool, it produces them using a pseudo random number generator. These pseudo random numbers should not be used as cryptographic keys.[/quote]
I would like to clone my 13 gb windows 98 drive, divided into c: programs and d: data to a 100 gb drive via usb which I would pre-partition to say, c: 20gb , d: 30 gb.
The goal would be to then simply pop the 100 gb drive into the ide ribbon in place of the 13 gb drive. My Linux drive is currently 30gb which is sufficient for my purposes. Here's the output of df currently:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.