SD Card Formatting
There's quite a bit of discussion on how to format the SD card. The easy way to do it is to just gparted program. It's point and click easy. However, what if you want to do it automatically? Use *sfdisk* program.
Once you prepped the SD card using gparted, use the sfdisk program to dump the info out to a file. This is what I did in order to get 4 GB file data.
- sudo sfdisk -d /dev/sda > SD4GFAT32.sdmap
- cat SD4GFAT32.sdmap
- # partition table of /dev/sda
- unit: sectors
- /dev/sda1 : start= 16384, size= 7684096, Id= b
- /dev/sda2 : start= 0, size= 0, Id= 0
- /dev/sda3 : start= 0, size= 0, Id= 0
- /dev/sda4 : start= 0, size= 0, Id= 0
So that's the file, and its content. Now, if you redid the whole partition using gparted to something like this:
- sudo sfdisk -d /dev/sda
- Warning: extended partition does not start at a cylinder boundary.
- DOS and Linux will interpret the contents differently.
- # partition table of /dev/sda
- unit: sectors
- /dev/sda1 : start= 2048, size= 4319232, Id= b
- /dev/sda2 : start= 4352000, size= 3356672, Id= 5
- /dev/sda3 : start= 0, size= 0, Id= 0
- /dev/sda4 : start= 0, size= 0, Id= 0
You can use sfdisk to restore it to its former partition, thus reformatting the SD card.
- sudo sfdisk /dev/sda < SD4GFAT32.sdmap
- Checking that no-one is using this disk right now ...
- OK
- Disk /dev/sda: 1020 cylinders, 122 heads, 62 sectors/track
- Warning: extended partition does not start at a cylinder boundary.
- DOS and Linux will interpret the contents differently.
- Old situation:
- Units = cylinders of 3872768 bytes, blocks of 1024 bytes, counting from 0
- Device Boot Start End #cyls #blocks Id System
- /dev/sda1 0+ 571- 572- 2159616 b W95 FAT32
- /dev/sda2 575+ 1019- 444- 1678336 5 Extended
- /dev/sda3 0 - 0 0 0 Empty
- /dev/sda4 0 - 0 0 0 Empty
- New situation:
- Warning: The partition table looks like it was made
- for C/H/S=*/6/18 (instead of 1020/122/62).
- For this listing I'll assume that geometry.
- Units = sectors of 512 bytes, counting from 0
- Device Boot Start End #sectors Id System
- /dev/sda1 16384 7700479 7684096 b W95 FAT32
- start: (c,h,s) expected (151,4,5) found (2,20,17)
- end: (c,h,s) expected (1023,5,18) found (1018,5,18)
- /dev/sda2 0 - 0 0 Empty
- /dev/sda3 0 - 0 0 Empty
- /dev/sda4 0 - 0 0 Empty
- Warning: partition 1 does not start at a cylinder boundary
- Warning: partition 1 does not end at a cylinder boundary
- Warning: no primary partition is marked bootable (active)
- This does not matter for LILO, but the DOS MBR will not boot this disk.
- Successfully wrote the new partition table
- Re-reading the partition table ...
- If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
- to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1
- (See fdisk(8).)
Just to make sure, here's the command again.
- sudo sfdisk -d /dev/sda
- # partition table of /dev/sda
- unit: sectors
- /dev/sda1 : start= 16384, size= 7684096, Id= b
- /dev/sda2 : start= 0, size= 0, Id= 0
- /dev/sda3 : start= 0, size= 0, Id= 0
- /dev/sda4 : start= 0, size= 0, Id= 0
One more thing. If you want to reformat the partition to FAT32 filesystem, you can do this:
- sudo mkfs -t vfat /dev/sda1
Yes, you need to format each partition separately, and that means you can have different file system per partition. Also, vfat stands for FAT32, although you can specify it explicitly, or use something else entirely.
No comments:
Post a Comment