1 00:00:07,217 --> 00:00:08,760 - Sartar is useful. 2 00:00:08,760 --> 00:00:12,450 Rsync is cool, but dd is really awesome. 3 00:00:12,450 --> 00:00:14,070 Let me tell you about dd, 4 00:00:14,070 --> 00:00:18,097 which is really one of the most powerful utilities on Linux. 5 00:00:18,097 --> 00:00:21,180 Dd was developed to work with complete devices 6 00:00:21,180 --> 00:00:23,880 so you can use it to clone devices, 7 00:00:23,880 --> 00:00:25,560 and using dd makes it possible 8 00:00:25,560 --> 00:00:27,960 to make an ISO of an optical disk 9 00:00:27,960 --> 00:00:29,673 or to clone a complete hard disk. 10 00:00:30,900 --> 00:00:35,130 Never use dd for copying files or making archives of files. 11 00:00:35,130 --> 00:00:37,260 That's what Rsync and TAR are for. 12 00:00:37,260 --> 00:00:40,210 But dd is for the most powerful of all things. 13 00:00:40,210 --> 00:00:41,850 Let me demonstrate. 14 00:00:41,850 --> 00:00:44,700 But before demonstrating, let me warn you. 15 00:00:44,700 --> 00:00:45,990 Things might go wrong. 16 00:00:45,990 --> 00:00:48,690 If things do go wrong, you lose everything. 17 00:00:48,690 --> 00:00:51,090 So only do this on an isolated system 18 00:00:51,090 --> 00:00:53,440 where it doesn't matter if you lose everything. 19 00:00:56,190 --> 00:00:57,963 So I'm going to open a root cell, 20 00:01:00,030 --> 00:01:02,904 and before doing anything I'm going to use dd, 21 00:01:02,904 --> 00:01:05,043 IF is dev SDA. 22 00:01:06,560 --> 00:01:11,560 OF is slash boot slash MBR backup. 23 00:01:12,030 --> 00:01:15,393 BS is 512, 24 00:01:16,230 --> 00:01:17,940 and count is one. 25 00:01:17,940 --> 00:01:18,810 You know what? 26 00:01:18,810 --> 00:01:22,290 Let's make this compatible to GPT systems 27 00:01:22,290 --> 00:01:25,083 and make a backup of first megabyte. 28 00:01:26,850 --> 00:01:28,020 So what did I just do? 29 00:01:28,020 --> 00:01:31,290 Well, I made a backup of the critical data that is required 30 00:01:31,290 --> 00:01:32,583 while booting your disk. 31 00:01:33,540 --> 00:01:37,740 Good. LSBLK is showing that we have an SDB device. 32 00:01:37,740 --> 00:01:41,550 SDA is 20 gigabytes, SDB is 20 gigabytes. 33 00:01:41,550 --> 00:01:42,383 And you know, 34 00:01:42,383 --> 00:01:46,539 that means that we can use dd IF is dev SDA, 35 00:01:46,539 --> 00:01:51,539 OF is dev SDB. 36 00:01:51,900 --> 00:01:54,930 Then very important, BS is 1M 37 00:01:54,930 --> 00:01:58,710 because by default, dd will stream byte by byte. 38 00:01:58,710 --> 00:02:00,510 And that's extremely slow. 39 00:02:00,510 --> 00:02:03,924 If you use BS is 1M, that's block size is one megabyte 40 00:02:03,924 --> 00:02:06,390 then it is using one megabyte blocks, 41 00:02:06,390 --> 00:02:07,980 and that's a lot faster. 42 00:02:07,980 --> 00:02:11,085 You will see that the entire SDA is clung to SDB 43 00:02:11,085 --> 00:02:12,813 within a minute or so. 44 00:02:15,360 --> 00:02:17,220 There we go. We have our perfect clone. 45 00:02:17,220 --> 00:02:19,590 Let's do LSBLK again. 46 00:02:19,590 --> 00:02:21,570 And LSBLK is indeed showing 47 00:02:21,570 --> 00:02:24,783 that SDB is SDB1, SDB2, SDB3. 48 00:02:25,830 --> 00:02:30,830 Now before continuing I want to verify XXD on dev SDA. 49 00:02:31,041 --> 00:02:33,870 XXD is a cool hexadecimal viewer, 50 00:02:33,870 --> 00:02:37,470 and oops, if you just run it like that 51 00:02:37,470 --> 00:02:40,860 it's going to do a hex dump of your complete SDA device. 52 00:02:40,860 --> 00:02:42,210 I don't wanna do that. 53 00:02:42,210 --> 00:02:44,970 I want to dump it through the less utility. 54 00:02:44,970 --> 00:02:46,710 And this is what I wanted to see. 55 00:02:46,710 --> 00:02:49,020 This is the master boot record, 56 00:02:49,020 --> 00:02:52,050 and this is what I should have on my SDA, 57 00:02:52,050 --> 00:02:53,553 but also on my SDB. 58 00:02:56,370 --> 00:02:58,680 And there you can, you go, and okay, 59 00:02:58,680 --> 00:03:02,190 we cannot do a byte comparison, but they're identical. 60 00:03:02,190 --> 00:03:03,333 We just dd them. 61 00:03:04,170 --> 00:03:06,630 And that means that we now can do awesome stuff 62 00:03:06,630 --> 00:03:11,630 like dd IF is slash dev slash zero. 63 00:03:12,230 --> 00:03:17,230 OF is slash dev slash SDA. BS is 1M, and count is 50. 64 00:03:20,970 --> 00:03:23,280 Oh my goodness, what did I just do? 65 00:03:23,280 --> 00:03:26,640 Well, dev zero is the device that generates zeros, 66 00:03:26,640 --> 00:03:28,680 and I use that as input fell, 67 00:03:28,680 --> 00:03:33,060 and I wrote 50 megabytes of that to SDA. 68 00:03:33,060 --> 00:03:36,636 So if at this point we do XXD on dev SDA, 69 00:03:36,636 --> 00:03:39,210 it feels pretty lonely in there. 70 00:03:39,210 --> 00:03:40,410 Nothing but zeros. 71 00:03:40,410 --> 00:03:42,330 That's exactly what I just did. 72 00:03:42,330 --> 00:03:45,510 But fortunately we have this clone on SDB 73 00:03:45,510 --> 00:03:47,220 so it's easy to revert. 74 00:03:47,220 --> 00:03:52,220 Dd, IF is dev SDB. OF is dev SDA. 75 00:03:54,180 --> 00:03:59,180 BS is 1M, and count is 51. 76 00:03:59,400 --> 00:04:01,350 Okay, that's all reasonable. 77 00:04:01,350 --> 00:04:04,380 You can do 50 as well, but I like doing 51. 78 00:04:04,380 --> 00:04:07,470 It's just the overlap that makes me feel more comfortable. 79 00:04:07,470 --> 00:04:10,110 And now you can see that the master boot record 80 00:04:10,110 --> 00:04:12,573 on SDA is restored. 81 00:04:13,740 --> 00:04:15,630 So that means at this point you can reboot, 82 00:04:15,630 --> 00:04:17,730 and everything is still working all right. 83 00:04:17,730 --> 00:04:19,470 There's one more thing that I would like to show you, 84 00:04:19,470 --> 00:04:22,833 and that is dd, IF is dev SR0. 85 00:04:24,638 --> 00:04:29,638 OF is slash my CD dot ISO, and BS is 1M. 86 00:04:31,830 --> 00:04:33,810 You can probably guess what that is doing. 87 00:04:33,810 --> 00:04:34,643 Oh boy. 88 00:04:34,643 --> 00:04:38,283 If at least media is inserted. Let me go fix that. 89 00:04:39,300 --> 00:04:42,420 Now I have connected to the CD-ROM device, and there we go. 90 00:04:42,420 --> 00:04:44,670 Dd is making an ISO out of it. 91 00:04:44,670 --> 00:04:46,620 And that is how you can easily use 92 00:04:46,620 --> 00:04:49,713 this very powerful dd utility on Linux.