Showing posts with label dd. Show all posts
Showing posts with label dd. Show all posts

mbr in linux

fdisk /mbr
ever used the above in dos? but this doesn't work in linux. there are times when i have a need for this. i usually install bootloaders on specific partitions than on the mbr.

dd can be used for such requirements. the following will wipe your mbr clean

# dd if=/dev/zero of=/dev/xxx bs=446 count=1
where xxx is your disk.

how/where do i use this? i have been playing with many different os for a long time. every os wants to install their own bootloader into the mbr. but, we can't really have that, can we? not if we want them to exist simultaneously on the same disk.

i always install the bootloader on the same partition as the os, and wipe the mbr clean. then use fdisk to make a partition active and reboot to load that os. an os could do whatever with its bootloader and not bother me. this method can also be used to play with multiple bootloaders, each on a separate partition. i arrived at this method, after much grief from trashed bootloaders.

caution: just in case, make a backup of your mbr, before you wipe it.
# dd if=/dev/xxx of=xxx-mbr.raw bs=446 count=1

and restore it, like so
# dd if=xxx-mbr.raw of=/dev/xxx

netcat tar backup

debian netcat-openbsd is leaner, cleaner & more efficient than debian netcat-traditional. if you get a choice, prefer the openbsd version.

i now use busybox wherever i can, including nc and tar. small, simple, clean, standard, available the same everywhere.

$ busybox nc

Usage: nc [-iN] [-wN] [-l] [-p PORT] [-f FILE|IPADDR PORT] [-e PROG]

Open a pipe to IP:PORT or FILE

-e PROG Run PROG after connect
-l      Listen mode, for inbound connects (use -l twice with -e for persistent server)
-p PORT Local port
-w SEC  Timeout for connect
-i SEC  Delay interval for lines sent
-f FILE Use file (ala /dev/ttyS0) instead of network

$ busybox tar

Usage: tar -[cxtZzJjahmvO] [-f TARFILE] [-C DIR] [FILE]...

Create, extract, or list files from a tar file

Operation:
        c       Create
        x       Extract
        t       List
        f       Name of TARFILE ('-' for stdin/out)
        C       Change to DIR before operation
        v       Verbose
        Z       (De)compress using compress
        z       (De)compress using gzip
        J       (De)compress using xz
        j       (De)compress using bzip2
        a       (De)compress using lzma
        O       Extract to stdout
        h       Follow symlinks
        m       Don't restore mtime

at {destination}:
$ nc -l -p {port} | tar xpv[z|j]f -

at {source}:
$ tar cpv[z|j]f - {directory} | nc {destination host/ip} {port}

[z|j] compression: use over slower networks. ignore for faster networks and/or slower computers.

tar streams much faster copying than scp 'ping-pong', especially when you have lots of files.

copy files from {some-server} to your machine:
$ ssh {some-server} ‘cd /some/dir && tar cz dir’ | tar xz

and the other direction:
$ tar cz dir | ssh {some-server} `cd /some/dir && tar xz`

image a disk across the network from {box1} to {box2}:

at {box2}:
$ nc -l {port} [-vv] | dd of={disk.img} bs=1M

at {box1}:
$ dd if=/dev/sda bs=1M | nc {box2 host/ip} {port} [-vv] -q 10

[-vv] use at the box1 (and/or box2, if fast enough)

restore this image in {box2} to {box3}:

at {box3}:
$ nc -l {port} [-vv] | dd of=/dev/sda bs=1M

at {box2}:
$ dd if={disk.img} bs=1M | nc {box1 host/ip} {port} [-vv]

compressed backup

at {box1}:
$ tar cpvJf - {directory} | nc {box2 host/ip} {port}

at {box2}:
$ nc -l -p {port} | dd of={directory}.tar.xz bs=1k


references:
http://nc110.sourceforge.net/
http://sans.org/security-resources/sec560/netcat_cheat_sheet_v1.pdf
http://wikipedia.org/wiki/netcat
http://saurorja.org/2012/04/06/network-file-transfer-using-netcat/
http://compsoc.dur.ac.uk/~djw/tarpipe.html

#! crunchbang 10 statler r20110207

For a while now, I have been hearing and thinking about crunchbang linux, or #! as the community calls it. So finally, I decided to dive in and install crunchbang-10-20110207-openbox-i686 on my spare laptop.

I have been recommending Linux Mint Debian XFCE lately to newbies. I am rethinking that now. It seems LMDX still has a lot of dependencies on Gnome and other bloatwares hanging on from its legacy days. For example, the XFCE Edition uses Gnome-Terminal rather than XFCE-Terminal. IMHO, that defeats the purpose of not wanting to use Gnome.

#! seems to be smoother and slicker at first glance. I like what I see, although the initial install used almost 2G of diskspace. There is a lot of gnome/etc bloatware which shouldn't have made it to this supposedly minimalist openbox distribution. Mint seems not much worse compared to this. (But compare this to my debian-wheezy laptop setup, with everything I need, on about 650M diskspace!!)

dd if=crunchbang-10-20110207-openbox-i686.iso of=/dev/{usb-drive}
was sufficient and simple to make a usb key for testing or install.

For some strange reason, I had trouble booting #! cd/usb. Apparently, it could be due to my screen - max resolution 1024x768. I almost gave up before I understood the issue. Wonder who the #! developers are targetting?

So I edit the grub boot menu, and append vga=773, and only then was I able to boot #! cd/usb to test or install. The install was fairly smooth with no major concerns, except that the drive partitioner seemed to be creating partitions not ending on cylinder boundaries. I reinstalled, after manually partitioning my drive with fdisk.

So, now I have a pristine install of #! waiting to be devoured.

Initial tasks were to update the system:
$ sudo apt-get update
$ sudo apt-get upgrade


#! /etc/apt/sources.list points to German servers, instead of UK ones, which lagged, due to about twice the network distance/time. It was fairly simple to replace de with uk. Since, #! tracks debian-stable (squeeze), and the installer contents are about 8mths old, about ~250M of initial upgrades were waiting. Squeeze is stable and updates shouldn't be frequent, except the security ones.

Then, I installed some of my missing favourites:
- rdate
- localepurge
- ncdu
- tmux
- most

Keep an eye here for my #! adventures... :-)

Bootable USB

I used mkdosfs to create a FAT16 filesystem. I want to use this stick anywhere.

Then I used dd to wipe the MBR.

I wanted to use grub on this stick. But, try as I might, I couldn't get it to boot on the PCs that I have.

Finally, I settled down with the restricted version of syslinux. Now, my usb stick seems to boot most PCs.

Voila! I have my entire desktop on a keyring, and can carry with me everywhere.

As long as the owner of any computer allows me, I stick this into a USB port, and boot to my own desktop. It looks the same, and acts the same, no matter where I am or what hardware I use, if it boots... And I have been able to boot most PCs, laptops, thin clients, etc. Plus, an added bonus is that nothing "on" that PC is disturbed!

most viewed