The DistRogue

Sunday, November 11, 2007

dd: The Great Destroyer and Creator

Buried deep in the Linux man pages is a command called dd. You know how short commands like cat, ps, grep, rm or mv are really powerful? dd owns all of them. It copies data between block files- image files or device files. It's simple enough- to use it, just run
dd if=[input] of=[output]

But there are a lot of things you can put in [input] and [output], and some of the could be dangerous. Here are some of the things you can do with it:
-Write a disk image onto a CD, DVD, or USB key:
dd if=[file] of=/dev/sdb1 (as an example)

-Make a compressed backup of a USB key:
dd if=/dev/sdb1 | bzip2 > backup.img.bz2

-Erase your entire hard drive:
dd if=/dev/zero of=/dev/sda

-Securely erase your hard drive:
dd if=/dev/urandom of=/dev/sda
dd if=/dev/zero of=/dev/sda

-Make an ext3 filesystem and mount it at /media/fs:
mkdir /media/fs
dd if=/dev/zero of=fs.ext3 bs=512k count=
mke3fs fs.ext3
mount fs.ext3 /media/fs

-Add a gigabyte-size swap file without rebooting or making any new partitions:
dd if=/dev/zero of=swap bs=1M count=1024
mkdwap swap
swapon swap

Don't try any of these at home unless you're sure what you're doing. dd is a very powerful and useful command, but don't use it unless you need to.
As for reviews: I'm trying to get Sabayon3.4 Mini to run off of my USB key, but if I can't, on to Fedora 8.
From gOS 1.0,
The DistRogue.
UPDATE: I used angle brackets <> for the examples, but I had to change them to square brackets because [input] (with <> instead of []) is a valid HTML tag. 0.o... Learn from me.

Labels: ,

Monday, August 13, 2007

How to turn your USB key into a bootable PCLinuxOS system

If you're a hardcore Linux geek, you'll want to take Tux with you wherever you go. Even if you're a normal user, you probably wouldn't mind having a penguin in your pocket. These are 100%-tested instructions on installing PCLinuxOS 2007 or later (2007, at the time of writing, is the latest version) to a gigabyte-or-larger USB key.
1. Download the PCLinuxOS CD image and open it in an archive manager.
2. Mount your USB key. It has to have one partition on it with more than 700MB of free space left, but any type of filesystem works. I used FAT32 for my key. Also, make absolutely sure that the partition is bootable (you can use a partition manager like fdisk or GParted for this). That means that its boot flag should be on.
3. Extract the contents of the CD image to your USB key. Don't make a folder on your USB key and extract them into the folder; otherwise, it won't boot.
4. Run these commands from the terminal:

cd
sudo grub-install --no-floppy --root-directory=. /dev/sdX

!CAUTION! Be careful with that command; if you do it wrong (for instance, use /dev/sda on a newer system), you might screw up your MBR, in which case, you'd better have a live CD ready. If you did it wrong, just run "grub-install /dev/sda" from a live CD. You do have one, right?
5. Make a file under the boot/grub folder in your USB key called menu.lst, with this in it:

title PCLinuxOS 2007
root (hd0,0)
kernel /isolinux/vmlinuz bootfrom=/dev/sda1 root=/dev/rd/3 acpi=on vga=788 keyb=us splash=silent fstab=rw,noauto
initrd /isolinux/initrd.gz
boot

6. Reboot and enable USB-HDD or USB-ZIP booting in your computer's BIOS if it isn't already enabled.
7. Enjoy.
I used PCLinuxOS for this, but it probably works with other distros, with some minor tweaking in menu.lst. The original tutorial can be found here, written for Damn Small Linux.
From PCLinuxOS 2007,
The DistRogue.

Labels: , , ,