Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Partitioning an SD Card on Ubuntu for Linux Boot Setup

Tech 2

Identifying the SD Card Device

To begin partitioning an SD card, first identify its device name using the sudo fdisk -l command. This lists all storage devices connected to the system.

user@ubuntu:~$ sudo fdisk -l
Disk /dev/sda: 2 TiB, 2199022206976 bytes, 4294965248 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: 0x1d291c55

Device     Boot   Start        End    Sectors  Size Id Type
/dev/sda1  *       2048 4286578687 4286576640   2T 83 Linux
/dev/sda2       4286580734 4294963199   8382466   4G  5 Extended
/dev/sda5       4286580736 4294963199   8382464   4G 82 Linux swap / Solaris

Disk /dev/sdb: 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: 0xa73bd1f4

Device     Boot Start     End Sectors  Size Id Type
/dev/sdb1        2048  800767  798720  390M  e W95 FAT16 (LBA)
/dev/sdb2      800768 8000000 7199233  3.4G 83 Linux

In this example, the SD card is identified as /dev/sdb.

Creating Partitions

Use sudo fdisk followed by the device name to start the partitioning tool.

user@ubuntu:~$ sudo fdisk /dev/sdc

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): m

Help:

DOS (MBR)
  a   toggle a bootable flag
  b   edit nested BSD disklabel
  c   toggle the dos compatibility flag

Generic
  d   delete a partition
  F   list free unpartitioned space
  l   list known partition types
  n   add a new partition
  p   print the partition table
  t   change a partition type
  v   verify the partition table
  i   print information about a partition

Misc
  m   print this menu
  u   change display/entry units
  x   extra functionality (experts only)

Script
  I   load disk layout from sfdisk script file
  O   dump disk layout to sfdisk script file

Save & Exit
  w   write table to disk and exit
  q   quit without saving changes

Create a new label
  g   create a new empty GPT partition table
  G   create a new empty SGI (IRIX) partition table
  o   create a new empty DOS partition table
  s   create a new empty Sun partition table

Command (m for help):

Adding New Partitions

For a bootable Linux setup, create two partitions. Use the n command to add a new partition.

Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p):

Using default response p.
Partition number (3,4, default 3):
First sector (8388608-62333951, default 8388608):
Last sector, +sectors or +size{K,M,G,T,P} (8388608-62333951, default 62333951):

Created a new partition 3 of type 'Linux' and of size 25.7 GiB.

Writing Partition Changes

After creating partitions, write the changes to disk with the w command.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

If the kernel fails to re-read the partition table, run sudo partprobe to update it without rebooting.

Formatting Partitions

For a bootable Linux SD card, format the partitions with appropriate filesystems. Typically, use msdos (FAT) for the boot partition and ext3 or ext4 for the root filesystem.

Format the first partition as msdos:

user@ubuntu:~$ sudo mkfs.msdos /dev/sdb1
mkfs.fat 3.0.28 (2015-05-16)
mkfs.msdos: /dev/sdc1 contains a mounted filesystem.

Note: If the partition is mounted, unmount it first or use Windows Disk Management to format it, but ensure sudo mkfs.msdos /dev/sdb1 is executed.

Format the second partition as ext4:

user@ubuntu:~$ sudo mkfs.ext4 /dev/sdc1

Copying Files

After formatting, copy the necessary files:

  • Place the kernel image (e.g., uImage) and device tree files into the msdos (FAT) partition.
  • Copy the root filesystem into the ext3 or ext4 partition.

This setup prepares the SD card for booting a Linux system. For Endroid, an additional partition may be required.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.