raspberry pi SD card format

Notes on formatting an SD card for raspberry pi

Insert the SD card and figure out the device name
# dmesg
[86441.438194] mmc0: new high speed SDHC card at address f377
[86441.438511] mmcblk0: mmc0:f377 SD04G 3.75 GiB 

or if you are familiar with the system drives
# cat /proc/diskstats


If the system auto-mounts the SD card unmount it
# df -h |grep -i mmcb
# umount /dev/mmcblk0
# df -h |grep -i mmcb


1) Check the drive with parted
# parted /dev/mmcblk0
GNU Parted 2.3
Using /dev/mmcblk0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)print                                                            
Model: SD SD04G (sd/mmc)
Disk /dev/mmcblk0: 4027MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      4194kB  4027MB  4022MB  primary  fat32

(parted) unit chs                                                         
(parted) print                                                            
Model: SD SD04G (sd/mmc)
Disk /dev/mmcblk0: 975,30,29
Sector size (logical/physical): 512B/512B
BIOS cylinder,head,sector geometry: 975,128,63.  Each cylinder is 4129kB.
Partition Table: msdos

Number  Start  End        Type     File system  Flags
 1      1,2,2  975,30,29  primary  fat32
                                                                  

(parted)quit
it seems OK

2)
Suppose we wanted to format from the beginning an SD card.
Then, to destroy old partitions, create one large partition, and format ...
# parted /dev/mmcblk0
GNU Parted 2.3
Using /dev/mmcblk0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: SD SA08G (sd/mmc)
Disk /dev/mmcblk0: 7969MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  132MB   131MB   primary  fat16        boot, lba
 2      132MB   7969MB  7837MB  primary  ext4

(parted) unit chs                                                         
(parted) print                                                            
Model: SD SA08G (sd/mmc)
Disk /dev/mmcblk0: 968,220,19
Sector size (logical/physical): 512B/512B
BIOS cylinder,head,sector geometry: 968,255,63.  Each cylinder is 8225kB.
Partition Table: msdos

Number  Start    End         Type     File system  Flags
 1      0,32,32  16,15,62    primary  fat16        boot, lba
 2      16,16,0  968,220,19  primary  ext4
(parted) rm 1                                                             
(parted) rm 2   
(parted) mkpart primary 0GB 8GB
(parted) print                                                            
Model: SD SA08G (sd/mmc)
Disk /dev/mmcblk0: 968,220,19
Sector size (logical/physical): 512B/512B
BIOS cylinder,head,sector geometry: 968,255,63.  Each cylinder is 8225kB.
Partition Table: msdos

Number  Start    End         Type     File system  Flags
 1      0,32,32  968,220,19  primary  fat16
(parted)quit
# partprobe
# mkdosfs /dev/mmcblk0
# mount /dev/mmcblk0 /mnt/blah/
# df -h |grep mnt
/dev/mmcblk0          7.5G  4.0K  7.5G   1% /mnt/blah


Mount the SD drive ( From 1 )
# mkdir /mnt/blah
# mount -t vfat /dev/mmcblk0p1 /mnt/blah/
# df -h |grep mmcb
/dev/mmcblk0p1          3.8G   32K  3.8G   1% /mnt/blah


Download and Copy NOOBS to the SD
# aria2c http://downloads.raspberrypi.org/NOOBS_latest
# mkdir NOOBS
# mv NOOBS_v1_3_2.zip NOOBS
# cd NOOBS; uzip NOOBS_v1_3_2.zip; mv NOOBS_v1_3_2.zip .. ; cd ..
# cp -r NOOBS/* /mnt/blah/
# ls /mnt/blah/
bootcode.bin  defaults         os   recovery.elf       recovery.img  riscos-boot.bin
BUILD-DATA    INSTRUCTIONS-README.txt  recovery.cmdline  RECOVERY_FILES_DO_NOT_EDIT  recovery.rfs
# sync
# umount /dev/mmcblk0p1


Use the SD card to boot pi and install the raspberry pi distribution you like ...



Raspberry Pi SD card format