10 Replies Latest reply: Dec 13, 2012 8:54 AM by gdstew RSS

question about the Debian preloaded SD card

ykwong New Members

I recently bought a model B RaspPi and a Debian preloaded SD Card (4G) from Element14. 

Booting up is ok, though I have not really tried to use it long enough to see if it has any voltage drop or heat problem. 

 

My question is :

I do not want to damage (or alter the original state of) my one-and-only-one o/s preloaded SD card.  So I bought a blank 4G SD card and try to make a duplicate and from there I intend to use the duplicate only.  By the way, having a duplicate card is also handy when I decide to buy one more Rasp-Pi.

 

I found that if I use my duplicated SD Card, the bootup is not successful, it will not stop at the Linux prompt that allows me to start the X Window.  It stops midway in the bootup process and I have no choice but to switch the power off.

 

Obviously, I think my method of the card duplication was wrong. Here is how I duplicated the SD card.

I inserted the original in my Mac (which has a built-in SD card slot),

I copied all the files (these are not images file already as the card is bootable) from the original SD into a folder on my Mac harddisk.

Then I inserted the blank 4G SD card in my Mac, and copy those files back from the harddisk to the SD card.

 

I probably did it the wrong way or this method will never duplicate the card successfully.

 

What would be the correct way to do what I want to achieve?

 

I am grateful to any advice, information, comments....

  • 1. Re: question about the Debian preloaded SD card
    obcd Level 1

    The Pi sd card has 2 partitions. One smaller fat32 partition (50 - 70MB) is used for the boot files and the kernel.

    The other ext4 partition is used for the linux root filesystem.

    I have no Mac experience, but obviously, only copiing the files won't do the trick.

    In linux, you need to dd the sd card contents to a file. After that, you can dd them back to the other card. 

     

    Be very carefull with the dd command, as it can also overwrite your harddisk or parts of it when it's not properly used.

    (It's nickname is disc destroyer)

     

    dd will also transfer the sd card sector 0, so the backup sd card will have the same partition layout as the original one.

  • 2. Re: question about the Debian preloaded SD card
    ykwong New Members

    Hi LC,

     

    Thanks for your advice.  After reading your post, I guess I should try the following (at least in principle)

     

    (by the way, switching to command mode from GUI in a Mac is almost identical to be running any Linux computer)

     

    (1) make an empty folder in my Mac and mount it as a drive

    (2) insert the original SD into the SD slot and use the dd command to copy the files from the original to the newly mounted drive (which is actually a folder on the Mac HD).

    (3) Place the blank SD inside the SD slot and use the dd command again, but this time files are copied from the mounted drive back to the SD card. 

     

    Now the only problem is I need to learn all the syntax of the dd command. 

     

    Are these procedures correct?  Or did I miss any crucial step?

  • 3. Re: question about the Debian preloaded SD card
    obcd Level 1

    dd works sector based. To my knowledge, you can even dd directly to a file.

    It might be worth to have a look at the elinux rPi section. They describe how to transfer an image file to the sd card. (Probably for Mac as well.)

    Just make sure you transfer it to SDx (your sd card) and not to SDx1 (the first partition of your sd card) This is a commonly made mistake.

     

    And always make sure it's your SD card and not your MAC harddisk !!!!!!!

     

    A 4Gig sd card will create a 4Gig image file. You might compress it after use.

  • 4. Re: question about the Debian preloaded SD card
    Doubleagent New Members

    Try this link. You will find detailed info on flashing an SD card.

     

    http://elinux.org/RPi_Easy_SD_Card_Setup

  • 5. Re: question about the Debian preloaded SD card
    gdstew Level 5

    Here is a version of the instructions for using dd  to write the image file using Linux that I modified to include reading the image. Note that BSD uses a

    different naming convention for block devices than Linux does but after substituting the BSD versions it should work. Also note that these image files

    can be => 2 GB in size.

     

    1.  Run df -h to see what devices are currently mounted

    2.  If your computer has a slot for SD cards, insert the card. If not, insert the card

         into an SD card reader, then connect the reader to your computer.

    3.  Run df -h again. The device that wasn't there last time is your SD card. The left

         column gives the device name of your SD card. It will be listed as something like

         "/dev/mmcblk0p1" or "/dev/sdd1". The last part ("p1" or "1" respectively) is the

         partition number, but you want to read and write to the whole SD card, not just one

         partition, so you need to remove that part from the name (getting for example

         "/dev/mmcblk0" or "/dev/sdd") as the device for the whole SD card. Note that the

         SD card can show up more than once in the output of df: in fact it will if you

         have previously written a Raspberry Pi image to this SD card, because the RPi SD

         images have more than one partition.

    4.  Now that you've noted what the device name is, you need to unmount it so that files

         can't be read or written to the SD card while you are copying over the SD image.

         So run the command below, replacing "/dev/sdd1" with whatever your SD card's

         device name is (including the partition number)

          * umount /dev/sdd1

          * If your SD card shows up more than once in the output of df due to having

             multiple partitions on the SD card, you should unmount all of these partitions.

    5.  In the terminal read the image to the card with this command, making sure you

         replace the input file if= argument "/dev/sdd" with the right device name and the

         output file of= argument with the path and name of your .img file. Make sure the

         device name is the name of the whole SD card as described above, not just a

         partition of it (for example, sdd, not sdds1 or sddp1, or mmcblk0 not mmcblk0p1)

          * dd bs=1M if=/dev/sdd of=RP_debian.img

          * Note that if you are not logged in as root you will need to prefix this with sudo

          * The dd command does not give any information of its progress and so may appear

             to have frozen. If your card reader has an LED it may blink during the read

             process, or you can run pkill -USR1 -n -x dd in another terminal (prefixed

             with sudo if you are not logged in as root).

    6.  To write the image to the card use this command, making sure you replace the input

         file if= argument with the path and name of your .img file, and the "/dev/sdd" in the

         output file of= argument with the right device name (this is very important: you will lose

         all data on the hard drive on your computer if you get the wrong device name). Make

         sure the device name is the name of the whole SD card as described above, not just

         a partition of it (for example, sdd, not sdds1 or sddp1, or mmcblk0 not mmcblk0p1)

          * dd bs=1M if=RP_debian.img of=/dev/sdd

          * Note that if you are not logged in as root you will need to prefix this with sudo

          * The dd command does not give any information of its progress and so may appear

             to have frozen. It could take more than five minutes to finish writing to the

             card. If your card reader has an LED it may blink during the write process, or

             you can run pkill -USR1 -n -x dd in another terminal (prefixed with sudo if you

             are not logged in as root).

    7.  As root run the command sync or if a normal user run sudo sync (this will ensure the

         write cache is flushed and that it is safe to unmount your SD card)

    8.  Remove SD card from card reader, insert it in the Raspberry Pi, and have fun

  • 6. Re: question about the Debian preloaded SD card
    ykwong New Members

    Ok, I will pay extra attention when doing it

  • 7. Re: question about the Debian preloaded SD card
    ykwong New Members

    Hi Tony,

    I did read that link.  It is not exactly identical to my situation.  It is mainly for getting everything from the net to start.  My case is a bit dufferent, I got the bootable files preloaded in the SD.  I just want to duplicate that SD card.  Nevertheless, thanks for your post.  It may help as well.  

  • 8. Re: question about the Debian preloaded SD card
    ykwong New Members

    Thanks Gary.
    I am going to copy and paste your instruction to an rtf file first and make a hardcopy so that I can cross-reference when I am trying out the dd approach.

  • 9. Re: question about the Debian preloaded SD card
    ykwong New Members

    Why do I use pkill? 

    Should I use ps to monitor the progress?

  • 10. Re: question about the Debian preloaded SD card
    gdstew Level 5

    Hi,

     

    The use of dd is not as complicated as the instructions seem to indicate. It really boils down to this:

     

    1) Make sure you know which device (in /dev directory) the SD card is before you read or write to it with

        dd. This is critical because dd will overwrite everything on the device you use.

    2) Make sure the device is not mounted before you use dd.

    3) Make sure you read/write the device itself, not a partition on the device.

    4) dd will take several minutes to write a 2GB image to an SD card. I've never timed it but I'm fairly certain

         that it is somewhere between 5 and 10 minutes on a class 10 SD card. Other SD devices are slower

         than this so it will vary. Reading the image is much faster.

     

    I have used this procedure to do exactly what you are trying to do several time with no problems. dd will

    write a message to the console showing how many blocks were read or written when it finishes so you will

    know when it is done. I have never needed to use pkill which is intended to be used if dd hangs up which

    hasn't happened to me so far. You can monitor dd with ps but to do so you will either have to run dd in the

    background (add an & at the end of the dd command), or open a different terminal for the ps command. If

    you run dd in the background it will not write any messages to the console when finished.