The Command Line Is Powerful


Recommended Posts

I had a corrupted partition table on my portable usb dirve. I decided I would try and zero it out using this command

dd if=/dev/zero of=/dev/sda bs=512 count=1

I happen to have it plugged into my linux standalone freevo box, this contained about 150 gbs of media. I was controling the computer remotely from my main workstation. Here is where things went wrong. I used this command

dd if=/dev/zero of=/dev/hda bs=512 count=1

just one letter different, I managed to corrupt my main harddrive instead of the portable drive. All is not lost, I have a second standalne box connected to our bedroom tv that I mirror all of my media to. I recently also made a tarball(compressed backup) of my system. I felt good to be able to recover from my dumb mistake pretty painlessly

Link to post
Share on other sites
I had a corrupted partition table on my portable usb dirve. I decided I would try and zero it out using this command

dd if=/dev/zero of=/dev/sda bs=512 count=1

I happen to have it plugged into my linux standalone freevo box, this contained about 150 gbs of media. I was controling the computer remotely from my main workstation. Here is where things went wrong. I used this command

dd if=/dev/zero of=/dev/hda bs=512 count=1

just one letter different, I managed to corrupt my main harddrive instead of the portable drive. All is not lost, I have a second standalne box connected to our bedroom tv that I mirror all of my media to. I recently also made a tarball(compressed backup) of my system. I felt good to be able to recover from my dumb mistake pretty painlessly

Cool that you were able to recover so easily, shanenin. I'm teaching my self about virtual hosts in Apache. I've currently got my Apache server hosting my website: http://www.hitest.org/

A buddy of mine said that he's able to host over 40 domains on his Apache server. I'm thinking about modifying my vhosts.conf file. I don't have another domain yet, but, it might be fun to investigate the possibility:-)

Link to post
Share on other sites
I'm teaching my self about virtual hosts in Apache. I've currently got my Apache server hosting my website: http://www.hitest.org/

A buddy of mine said that he's able to host over 40 domains on his Apache server. I'm thinking about modifying my vhosts.conf file. I don't have another domain yet, but, it might be fun to investigate the possibility:-)

That is the area I would like to learn some more. I will have my domain, brighteyedcomputer.com listed in the yellow pages, so I will need to have a simple webpage up by Febraury(when it is published). I have not yet decided on making my own webserver, or paying a few dollars a month to have it hosted. I think I would really enjoy setting up my own webserver, a project is the best way to learn. Two negatives of using my cable service to serve the sight. the first would be, I am not sure if port 80 is blocked. The second reason is security. If I am running a web server, I think my home network might be exposed to to much risk.

Link to post
Share on other sites

I'm teaching my self about virtual hosts in Apache. I've currently got my Apache server hosting my website: http://www.hitest.org/

A buddy of mine said that he's able to host over 40 domains on his Apache server. I'm thinking about modifying my vhosts.conf file. I don't have another domain yet, but, it might be fun to investigate the possibility:-)

That is the area I would like to learn some more. I will have my domain, brighteyedcomputer.com listed in the yellow pages, so I will need to have a simple webpage up by Febraury(when it is published). I have not yet decided on making my own webserver, or paying a few dollars a month to have it hosted. I think I would really enjoy setting up my own webserver, a project is the best way to learn. Two negatives of using my cable service to serve the sight. the first would be, I am not sure if port 80 is blocked. The second reason is security. If I am running a web server, I think my home network might be exposed to to much risk.

Yes, three years ago I ran a web server with little or no security and paid the price:-) Today I'm running a Plll 667 MHz IBM computer with 256 MB RAM and it does the job nicely. I have my web server in front of my hardware firewall so my home network isn't exposed. My server is running on one of my static IP addresses. I've got shorewall running (firewall) and have only punched a hole in the firewall to let requests in to my server. I don't have ssh enabled or ftp or sendmail, just a server. I hardly ever run the unit as root. Also, I haven't configured printing services which is a point of attack for hackers. So far so good. I rented the domain hitest.org at Yahoo for $2.99/ year.

Yeah, you would need to find out from your ISP if they will let you run a home server, they might block port 80.

Link to post
Share on other sites
doesn't
dd if=/dev/zero of=/dev/hda bs=512 count=1

just zero out the mbr?

I am pretty sure it does the whole drive, including the mbr. I made a gentoo cd with a tarball and this script to automate installing freevo as standalone divx players

#!/bin/bash

echo "this script will erase and partition your full drive"
echo "enter 'yes' and return to continue"
read answer
if [ ${answer} != "yes" ]; then exit; fi
echo "the script will now partition your drive"
sleep 3
dd if=/dev/zero of=/dev/hda bs=512 count=1 &&
parted -s /dev/hda mklabel msdos &&
parted -s /dev/hda mkpart primary ext2 0.0 200.0 &&
parted -s /dev/hda mkpart primary linux-swap 200.0 400.0 &&
parted -s /dev/hda mkpart primary ext2 400.0 3400.0 &&
parted -s -- /dev/hda mkpart primary ext2 3400.0 -0 &&
echo
echo "the script is finished partitioning, now creating file sysstems"
killall udevd &&
udevstart &&
sleep 3
mke2fs /dev/hda1 &&
mke2fs -j -m 2 /dev/hda3 &&
mke2fs -j -m 1 /dev/hda4 &&
echo
echo "the script is now mounting all filesystems" &&
sleep 3
mkswap /dev/hda2 &&
swapon /dev/hda2 &&
mount -t ext3 /dev/hda3 /mnt/gentoo &&
mkdir /mnt/gentoo/boot &&
mount /dev/hda1 /mnt/gentoo/boot &&
echo
echo "the script is now untarring the system"
sleep 3
tar -xvjpf /mnt/cdrom/extras/freevo-3j.tar.bz2 -C /mnt/gentoo &&
mount -t proc proc /mnt/gentoo/proc &&
cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf &&
echo "`lsmod`" > /mnt/gentoo/tmp/lsmod
chroot /mnt/gentoo /root/install-grub

Link to post
Share on other sites

doesn't

dd if=/dev/zero of=/dev/hda bs=512 count=1

just zero out the mbr?

Yup.

I am pretty sure it will knock out all of the partitions, at least it has in practice. In the script I used above, I use that to wipe the whole drive clean, then parted is able to set up new partitions. If it was only clearing away the mbr parted would not work.

edit added later//

count=1 does that mean it will do one block? what you guys are saying, seems correct, but...

In practice, I always rember this command wiping the whole drive.

Edited by shanenin
Link to post
Share on other sites
I am pretty sure it will knock out all of the partitions, at least it has in practice. In the script I used above, I use that to wipe the whole drive clean, then parted is able to set up new partitions. If it was only clearing away the mbr parted would not work.

The MBR contains the partition table.

count=1 does that mean it will do one block?

Yup.

Link to post
Share on other sites
does that mean by just zeroing the mbr, I am clearing out all of my partitions?

Altering the partition table doesn't affect the partitions. The MBR partition table only contains the information required to identify the partitions: the starting and ending sectors and blocks, the sizes of the partitions, the partition types, and flags that indicate whether the partition is active. Everything else is stored in tables within each partition. As you said, in practice blowing away the partition table will blow away the partitions, but if you restore the table everything will be as you left it.

Edited by jcl
Link to post
Share on other sites

if I wanted to try and fix my mbr(partition table), would that have been a pretty involved process? If I did not have a backup, I may have tried to do that.

edit added later//

I have not been able to find this with a quick google. is the mbr exactly 512 bytes?

bs=512 count=1

is that the exact size of my mbr?

Edited by shanenin
Link to post
Share on other sites
if I wanted to try and fix my mbr(partition table), would that have been a pretty involved process?

Probably.

I have not been able to find this with a quick google. is the mbr exactly 512 bytes?

Yup.

Link to post
Share on other sites

if one block contains 512 bytes, that seems small to contain all of the info:

the partition table. and grub info

edit added later//

I am assumbing 512 bytes means 512 1s or 0s

Edited by shanenin
Link to post
Share on other sites
if one block contains 512 bytes, that seems small to contain all of the info:

You can do a lot with 512 bytes. The partition table is only 64 bytes.

I am assumbing 512 bytes means 512 1s or 0s

512 bytes = 512 octets = 4096 bits.

Edit: To clarify, the partition table consists of four 16 byte entries, one for each primary partition. Each entry has six fields describing the partition. Here's an example, with the fields labelled:

Active  CHS start   Type	CHS end	 First sector	Length
00 010100 82 fe3f79 3f000000 bbe71d00
80 00017a 83 feffff fae71d00 3df7c604
00 000000 00 000000 00000000 00000000
00 feffff 85 feffff 37dfe404 8a581409

  • Active is 0x80 if the partition is active (bootable) and otherwise is ignored
  • CHS start is the beginning of the partition in cylinder-head-sector format. AFAIK this is ignored by Linux.
  • Type is the partition type. 82 = Linux swap, 83 = Linux primary, 85 = Linux extended
  • CHS end is the end of the partition is CHS format. Also ignored.
  • First sector is the first sector of the partition. (This value is little-endian, so the first sector of partition 0 is actually 0x3f = 63.
  • Length is the length of the partition in sectors. (Also little-endian.)

So here we have three partitions (part2 is unused). The first partition is a Linux swap partition of 1,959,867 sectors = ~956 MiB (hooray for dubious rounding by partitioning tools), the second is a bootable regular primary partition of 80,148,285 sectors = ~38 GiB, and the last is an extended partition of 152,328,330 sectors = ~72 GiB (that happens to contain two logical partitions of about equal size).

Edited by jcl
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...