Difference between revisions of "Repartitioning a CompactFlash Disk for Linux"

From wiki.emacinc.com
Jump to: navigation, search
(added intro for CF partitioning)
(added info on how to determine local CF disk)
Line 4: Line 4:
  
 
The majority of EMAC's x86-based systems utilize CompactFlash as the primary storage device. By default, EMAC OE is provided with a single ext3 partition on the CompactFlash holding the root filesystem. The most efficient method for repartitioning this type of device is using a CompactFlash card reader on a Linux PC. While command-line tools can be utilized, the application <code>gparted</code> is a graphical application that works very well for resizing existing partitions. Follow the procedure below to resize the existing partition and create a secondary partition on a CompactFlash.
 
The majority of EMAC's x86-based systems utilize CompactFlash as the primary storage device. By default, EMAC OE is provided with a single ext3 partition on the CompactFlash holding the root filesystem. The most efficient method for repartitioning this type of device is using a CompactFlash card reader on a Linux PC. While command-line tools can be utilized, the application <code>gparted</code> is a graphical application that works very well for resizing existing partitions. Follow the procedure below to resize the existing partition and create a secondary partition on a CompactFlash.
#
+
# Power down the target board and carefully remove the CF disk.
 +
# Insert the CF disk into the CF reader connected to a Linux PC.
 +
# The system will most likely bring up a window asking what to do with the device once it is detected. If this occurs, select "Do Nothing" or a similar option to indicate that the device should not be mounted.
 +
# Determine the device node for the CF disk. There are several methods that can be used to accomplish this:
 +
## <code>dmesg</code> can provide information about the disk that was reported by the kernel when it was detected as shown below. <syntaxhighlight lang=bash>
 +
developer@ldc:~$ dmesg | tail
 +
[7414822.178026] sd 6:0:0:1: [sdc] 4001760 512-byte logical blocks: (2.04 GB/1.90 GiB)
 +
[7414822.179094] sd 6:0:0:1: [sdc] Assuming drive cache: write through
 +
[7414822.180711] sd 6:0:0:1: [sdc] Assuming drive cache: write through
 +
[7414822.180716]  sdc: sdc1
 +
</syntaxhighlight> In this example, <code>sdc</code> is the device corresponding to the CF disk. Also note that the size reported matches the expected size for the CF disk (2 GB in this case). The output also shows that a single partition was detected on the device: <code>sdc1</code>.
 +
## The <code>fdisk</code> command can also be used to list the available devices using the <code>-l</code> options. Note that you may or may not have permissions to run the <code>fdisk</code> command as a normal user, it may be necessary to run the command as root using <code>sudo</code> or <code>su</code>. An example <code>fdisk -l</code> output is shown below. <syntaxhighlight lang=bash>developer@ldc:~$ sudo /sbin/fdisk -l
 +
Disk /dev/sda: 500.1 GB, 500107862016 bytes
 +
255 heads, 63 sectors/track, 60801 cylinders
 +
Units = cylinders of 16065 * 512 = 8225280 bytes
 +
Disk identifier: 0x00000000
 +
 
 +
  Device Boot      Start        End      Blocks  Id  System
 +
/dev/sda1  *          1      60302  484375783+  83  Linux
 +
/dev/sda2          60303      60801    4008217+  5  Extended
 +
/dev/sda5          60303      60801    4008186  82  Linux swap / Solaris
 +
 
 +
Disk /dev/sdc: 2048 MB, 2048901120 bytes
 +
224 heads, 56 sectors/track, 319 cylinders
 +
Units = cylinders of 12544 * 512 = 6422528 bytes
 +
Disk identifier: 0x6a5f7029
 +
 
 +
  Device Boot      Start        End      Blocks  Id  System
 +
/dev/sdc1  *          1        1008    6322175+  83  Linux
 +
 
 +
Disk /dev/sdf: 2000.3 GB, 2000398934016 bytes
 +
255 heads, 63 sectors/track, 243201 cylinders
 +
Units = cylinders of 16065 * 512 = 8225280 bytes
 +
Disk identifier: 0x0b45dffc
 +
 
 +
  Device Boot      Start        End      Blocks  Id  System
 +
/dev/sdf1              1      243201  1953512001  83  Linux
 +
</syntaxhighlight> Three devices are listed in this output: <code>/dev/sda</code>, <code>/dev/sdc</code>, and <code>/dev/sdf</code>. Looking at the disk sizes, <code>/dev/sdc</code> matches the 2 GB size of the CF card (2048 MB as listed in the output above).
 +
## After checking the <code>dmesg</code> and <code>fdisk</code> output, inspect the mount locations on the system to verify that the correct disk is being used and that it has not been utilized by the system. In the example below, the <code>grep</code> command is used to search the output of the <code>mount</code> command for the string "/dev/sd". <syntaxhighlight lang=bash>developer@ldc:~$ mount | grep /dev/sd
 +
travis@cheeto:~$ mount | grep /dev/sd
 +
/dev/sda1 on / type ext3 (rw,errors=remount-ro)
 +
/dev/sdf1 on /media/backup type ext3 (rw)
 +
</syntaxhighlight> This output illustrates that <code>/dev/sda1</code> is the root filesystem, <code>/dev/sdf1</code> is an auxiliary disk mounted on <code>/media/backup</code>, and <code>/dev/sdc1</code> is not mounted. Given the results from these three commands, <code>/dev/sdc</code> is the CF disk.
 +
# After determining the CF disk on the system,

Revision as of 07:52, 4 April 2013

Many embedded systems require writing to persistent storage during routine operation. While the journaling filesystems used on EMAC OE systems are tolerant of power failures during a write to the filesystem, it is still advantages to leave the root filesystem mounted read-only as often as possible to prevent any possibility of data loss or corruption on the root filesystem. One method to accomplish this is using a separate disk (such as an SD card) or secondary partitions on the primary storage device for any application-specific data that needs to be written to disk. This article describes the process of creating and utilizing an additional partition for data storage.

CompactFlash Partitioning

The majority of EMAC's x86-based systems utilize CompactFlash as the primary storage device. By default, EMAC OE is provided with a single ext3 partition on the CompactFlash holding the root filesystem. The most efficient method for repartitioning this type of device is using a CompactFlash card reader on a Linux PC. While command-line tools can be utilized, the application gparted is a graphical application that works very well for resizing existing partitions. Follow the procedure below to resize the existing partition and create a secondary partition on a CompactFlash.

  1. Power down the target board and carefully remove the CF disk.
  2. Insert the CF disk into the CF reader connected to a Linux PC.
  3. The system will most likely bring up a window asking what to do with the device once it is detected. If this occurs, select "Do Nothing" or a similar option to indicate that the device should not be mounted.
  4. Determine the device node for the CF disk. There are several methods that can be used to accomplish this:
    1. dmesg can provide information about the disk that was reported by the kernel when it was detected as shown below.
      developer@ldc:~$ dmesg | tail
      [7414822.178026] sd 6:0:0:1: [sdc] 4001760 512-byte logical blocks: (2.04 GB/1.90 GiB)
      [7414822.179094] sd 6:0:0:1: [sdc] Assuming drive cache: write through
      [7414822.180711] sd 6:0:0:1: [sdc] Assuming drive cache: write through
      [7414822.180716]  sdc: sdc1
      
      In this example, sdc is the device corresponding to the CF disk. Also note that the size reported matches the expected size for the CF disk (2 GB in this case). The output also shows that a single partition was detected on the device: sdc1.
    2. The fdisk command can also be used to list the available devices using the -l options. Note that you may or may not have permissions to run the fdisk command as a normal user, it may be necessary to run the command as root using sudo or su. An example fdisk -l output is shown below.
      developer@ldc:~$ sudo /sbin/fdisk -l
      Disk /dev/sda: 500.1 GB, 500107862016 bytes
      255 heads, 63 sectors/track, 60801 cylinders
      Units = cylinders of 16065 * 512 = 8225280 bytes
      Disk identifier: 0x00000000
      
         Device Boot      Start         End      Blocks   Id  System
      /dev/sda1   *           1       60302   484375783+  83  Linux
      /dev/sda2           60303       60801     4008217+   5  Extended
      /dev/sda5           60303       60801     4008186   82  Linux swap / Solaris
      
      Disk /dev/sdc: 2048 MB, 2048901120 bytes
      224 heads, 56 sectors/track, 319 cylinders
      Units = cylinders of 12544 * 512 = 6422528 bytes
      Disk identifier: 0x6a5f7029
      
         Device Boot      Start         End      Blocks   Id  System
      /dev/sdc1   *           1        1008     6322175+  83  Linux
      
      Disk /dev/sdf: 2000.3 GB, 2000398934016 bytes
      255 heads, 63 sectors/track, 243201 cylinders
      Units = cylinders of 16065 * 512 = 8225280 bytes
      Disk identifier: 0x0b45dffc
      
         Device Boot      Start         End      Blocks   Id  System
      /dev/sdf1               1      243201  1953512001   83  Linux
      
      Three devices are listed in this output: /dev/sda, /dev/sdc, and /dev/sdf. Looking at the disk sizes, /dev/sdc matches the 2 GB size of the CF card (2048 MB as listed in the output above).
    3. After checking the dmesg and fdisk output, inspect the mount locations on the system to verify that the correct disk is being used and that it has not been utilized by the system. In the example below, the grep command is used to search the output of the mount command for the string "/dev/sd".
      developer@ldc:~$ mount | grep /dev/sd
      travis@cheeto:~$ mount | grep /dev/sd
      /dev/sda1 on / type ext3 (rw,errors=remount-ro)
      /dev/sdf1 on /media/backup type ext3 (rw)
      
      This output illustrates that /dev/sda1 is the root filesystem, /dev/sdf1 is an auxiliary disk mounted on /media/backup, and /dev/sdc1 is not mounted. Given the results from these three commands, /dev/sdc is the CF disk.
  5. After determining the CF disk on the system,