step 1 : SD card format and partition
In this program, you are going to learn
How to find the SD card device name ?
How to delete existing partitions ?
How to add two partitions ?
How to format the partitons ?
How to mount the partitons ?
Clear the dmesg
$ sudo dmesg -c
After inserting the SD card reader to the Linux desktop machine, find its device name by dmesg.
$ dmesg | tail
[20194.951893] usb 1-3: Manufacturer: Prolific Technology Inc.
[20194.953283] pl2303 1-3:1.0: pl2303 converter detected
[20194.953986] usb 1-3: pl2303 converter now attached to ttyUSB0
[20195.422420] pl2303 ttyUSB0: pl2303_get_line_request - failed: -32
[20195.422975] pl2303 ttyUSB0: pl2303_get_line_request - failed: -32
[20213.618087] mmc0: cannot verify signal voltage switch
[20213.743845] mmc0: new ultra high speed SDR104 SDHC card at address aaaa
[20213.744562] mmcblk0: mmc0:aaaa SC16G 14.8 GiB
$ ls /dev/mmcblk0
/dev/mmcblk0
Remove and Add SD card and check the dmesg, do ls /dev/, check output and confirm your device ID
Startup fdisk in the administrative mode with the command
sudo fdisk /dev/mmcblk0
$ sudo fdisk /dev/mmcblk0
Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help):
Enter
d
to delete any given partition name from the system.
Command (m for help): d
Partition number (1,2, default 2):
The next prompt will ask for the Partition number. Just press Enter to accept the default value.
Partition number (1,2, default 2):
Partition 2 has been deleted.
Command (m for help):
Enter
d
to delete any given partition name from the system.
Command (m for help): d
Selected partition 1
Partition 1 has been deleted.
Command (m for help):
Now, use the
p
command to print the partitions to verify.
Command (m for help): p
Disk /dev/mmcblk0: 14.9 GiB, 15931539456 bytes, 31116288 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5452574f
Command (m for help):
Finally, enter the
w
command to write the partitions out.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
Startup fdisk in the administrative mode with the command
sudo fdisk /dev/mmcblk0
$ sudo fdisk /dev/mmcblk0
Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using t1he write command.
Command (m for help):
Within fdisk, use the
n
command to create a new partition.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p):
Then we enter
p
to specify that the new partition will be a primary partition.
Select (default p):
Using default response p.
Partition number (1-4, default 1):
Next we select
1
to specify the partition number.
Partition number (1-4, default 1):
First sector (2048-31116287, default 2048):
The next prompt will ask for the first sector. Just press Enter to accept the default value.
First sector (2048-31116287, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-31116287, default 31116287):
After that it will ask for the last sector. Give the value as 512M
Last sector, +sectors or +size{K,M,G,T,P} (2048-31116287, default 31116287): +512M
Created a new partition 1 of type Linux and of size 512 MiB.
Partition #1 contains a vfat signature.
Do you want to remove the signature? [Y]es/[N]o: Y
The signature will be removed by a write command.
Command (m for help):
Now you have to type
n
to create new partition.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p):
Then type
p
for making a primary partition
Select (default p):
Using default response p.
Partition number (2-4, default 2):
Next we select
2
to specify the partition number.
Partition number (2-4, default 2):
First sector (1050624-31116287, default 1050624):
The next prompt will ask for the first sector. Just press Enter to accept the default value.
First sector (1050624-31116287, default 1050624):
Last sector, +sectors or +size{K,M,G,T,P} (1050624-31116287, default 31116287):
After that it will ask for the last sector. Give the value as
512M
.
Last sector, +sectors or +size{K,M,G,T,P} (1050624-31116287, default 31116287): +512M
Created a new partition 2 of type 'Linux' and of size 512 MiB.
Partition #2 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: Y
The signature will be removed by a write command.
Command (m for help):
Enter
t
to recognize specified partition table type.
Command (m for help): t
Partition number (1,2, default 2):
Next we select
1
to specify the partition number.
Partition number (1,2, default 2): 1
Hex code (type L to list all codes):
Enter
b
to change type of partition from Linux to FAT32.
Hex code (type L to list all codes): b
Changed type of partition 'Linux' to 'W95 FAT32'.
Command (m for help):
Now, use the
p
command to print the partitions to verify.
Command (m for help): p
Disk /dev/mmcblk0: 14.9 GiB, 15931539456 bytes, 31116288 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5452574f
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 2048 1050623 1048576 512M b W95 FAT32
/dev/mmcblk0p2 1050624 2099199 1048576 512M 83 Linux
Filesystem/RAID signature on partition 1 will be wiped.
Filesystem/RAID signature on partition 2 will be wiped.
Command (m for help):
Finally, enter the
w
command to write the partitions out.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
FAT32 for boot partition
$ sudo mkfs.vfat -F 32 -n boot /dev/mmcblk0p1
mkfs.fat 4.1 (2017-01-24)
mkfs.fat: warning - lowercase labels might not work properly with DOS or Windows
ext4 for root partition
$ sudo mkfs.ext4 -L root /dev/mmcblk0p2
mke2fs 1.44.1 (24-Mar-2018)
Discarding device blocks: done
Creating filesystem with 131072 4k blocks and 32768 inodes
Filesystem UUID: a88d6d66-108a-40de-b740-7c55b4850db1
Superblock backups stored on blocks:
32768, 98304
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
Mount both partitions so that we can write to them.
$ sudo mount /dev/mmcblk0p1 /mnt/boot
$ sudo mount /dev/mmcblk0p2 /mnt/root
Is fdisk the only command for managing partitions in Linux?
See Answer
??
How do I start fdisk in Linux?
See Answer
??
How to see the size of your Partition?
See Answer
??
What are all file systems that is supported by u-boot?
See Answer
??
Why we are using the FAT32 file system here?
See Answer
??
Can we use any other file system instead of FAT32?
See Answer
??
What is the purpose of mounting ?
See Answer
??