Whoopsie with the dd command.

Holy mother of Slayer, do I feel like a moron right now.

I have a camera that complains that every memory card I put in it need a format, even after I format it with the camera, so I got the bright idea to use a Linux tutorial, and see if I fared any better using a Linux format.

For future reference, don’t do this when half asleep.

The tutorial I looked at when I typed “format SD card in linux” into google used the dd command, fdisk, and mkfs.vfat. I had no idea what the /dev/ location for my card was, so I assumed it was sda, because the tutorial used sdd, and since you know, it starts with sd, and it was the only one that I thought I had. Turns out it was /dev/mmcblk0.

Yeah, I’m a moron.

Anyway, once I figured out the issue, the command made it about 15 gigabytes onto the drive. It is my only drive in the laptop - don’t ask me why, but I assumed my laptop used hda for it’s hard drive.

I’m hoping, and I’m sure it is in vain, that since the first partition (/dev/sda1) is Windows, and is 50 gigs, that the dd command starts at the beggining of the disk. If so that means my 25 gig root and 25 /home partitions are still okay - I could care less if the vista partition is gone.

I’m probably screwed, but on the bright side, the only folder in Konqueror that wont load in the root directory is /windows/ everyother folder shows me things fine - I really doubt my laptop could hold that much in memory.

My only issue is YaST wont let me touch any partition on /dev/sda. My biggest question, assuming that the dd command does in fact work sequentially, is if there is anyway I can format the windows partition as a an ext2 filesystem, and mount it at /home/user/music, or something else useful.

On the other hand, I can live with 50 gigs, hence why I never bothered to trash the windows partiton, I would just prefer not to.

Your Linux partitions are probably ok but you need to restore the MBR, which contains the boot sector and partition table. There is a utility called gpart (not gparted) that guesses where partitions might start on the disk. Unless you had printed it out somewhere, that would be better. Then after restoring the partition table the way it was, you need to put GRUB back, using a repair CD. After that you can boot into Linux and do what you like with the trashed Windows partition.

To be honest, I haven’t rebooted since the boo boo. I’m too afraid too.

Everything is working though.

I don’t have gparted installed, and can’t at the moment, as I’m running a yast update.

However, I used the Boot Loader entry in YaST to restore the MBR, would that have had the same effect?

I’m not going to reboot until the experts here think it is safe to do so. I may have used linux for five years, but I’m still learning.

What would be the easiest way of reinstalling grub?

If you reboot now, you will not be able to boot off the disk, as the MBR has been overwritten. Installing the bootloader from YaST isn’t good enough because that doesn’t restore the partition table, only the boot code. What you have to do is retrieve the partition info from the currently running kernel. Fortunately you can find this out by:

cat /proc/partitions

The values are in blocks. Write the info down, and then use fdisk to recreate the partition table, combining with info from the mount command. Then reinstall the bootloader with YaST.

Good luck.

Thanks for the response, again.

Here is the output from cat.


travis@Hellen-Keller:/> cat /proc/partitions
major minor  #blocks  name

   8     0  117220824 sda
   8     1   52736000 sda1
   8     2          1 sda2
   8     5    2104483 sda5
   8     6   20972826 sda6
   8     7   41399473 sda7
travis@Hellen-Keller:/>

Pardon my stupidity, but I have no clue how to recreate the partition table with fdisk.

sda1 is a primary partition with 52736000 blocks
sda2 is an extended partition containing sda5-7
sda5 is a logical partition with 2104483 blocks
sda6 is a logical partition with 20972826 blocks
sda7 is a logical partition with 41399473 blocks

The types you have to get from /etc/fstab or the mount command.

Here is my fstab file.


/dev/disk/by-id/scsi-SATA_TOSHIBA_MK1237G_778UT23GT-part5 swap                 swap       defaults              0 0
/dev/disk/by-id/scsi-SATA_TOSHIBA_MK1237G_778UT23GT-part6 /                    ext3       acl,user_xattr        1 1
/dev/disk/by-id/scsi-SATA_TOSHIBA_MK1237G_778UT23GT-part7 /home                ext3       acl,user_xattr        1 2
/dev/disk/by-id/scsi-SATA_TOSHIBA_MK1237G_778UT23GT-part1 /windows/C           ntfs-3g users,gid=users,fmask=133,dmask=022,locale=en_GB.UTF-8 0 0
proc                 /proc                proc       defaults              0 0
sysfs                /sys                 sysfs      noauto                0 0
debugfs              /sys/kernel/debug    debugfs    noauto                0 0
usbfs                /proc/bus/usb        usbfs      noauto                0 0
devpts               /dev/pts             devpts     mode=0620,gid=5       0 0

Those aren’t in the same order as the disks, but I do know which is which.

I’m assuming I will have to use the fdisk command to recreate each one? I just don’t know how.

Also, do I need to worry about the proc, sysfs, debugfs, etc partitions?

No, the others are not disk mounts. You only have to worry about the disk mounts.

Just run fdisk /dev/sda and use the n command to create new partitions and follow the prompts. You can switch the display and data entry unit to blocks instead of the normal cylinders.

You might have a slight issue later when it tries to mount the disk partitions by disk ID rather than partition number and your disk ID (label) was probably also wiped out. That can be fixed by editing /etc/fstab to use partition numbers.

My update finished, so I installed gparted.

I can try this with fdsik, which I must admit, I’m terrified of borking my install. I could just back up the home directory, but since the 11.0 release I have stayed up to date with so many repositories - resulting in gigs of downloads on a 30kbs download speed connection - that I don’t want to loose if I don’t have to.

If Gparted would be easier, and more imporatantly, safer, let me know

I don’t know, I’ve never used gparted in this situation. I prefer a simple tool that doesn’t try to do anything behind your back.

Remember, even if you enter the numbers wrong in fdisk, your data isn’t lost. It’s still there on the disk. All you are changing is the partition table, some 100 bytes or so of the boot sector. You just need to keep trying until the partition boundaries are correct and the Linux partitions mount correctly.

You can also use the YaST partitioner instead of fdisk if you prefer. Just don’t format the partitions.

At tle very least write down those block numbers. Even if you have to reboot and run a rescue CD on the disk, you will need those numbers.