skip navigational linksPJRC
Shopping Cart Download Website
Home Products Teensy Blog Forum
You are here: MP3 Player Detailed Info Disk Format, Linux

PJRC Store
Main Board, $150
LCD & Pushbuttons, $42
LCD/Backlight/PB, $77
IDE Cable, $9
Complete Parts List
MP3 Player
Main Page
Detailed Info
User Photo Gallery
Connecting The Board
Firmware Download
Side Projects
Technical Docs
Freq. Asked Questions
FAQ #2
News And Updates

Hard Drive Setup Using Linux (Command Line)

  1. Check Device Name For The Disk Drive
  2. Partition The Drive With "fdisk"
  3. Create FAT32 Filesystem With "mkdosfs"
  4. Mount The New Filesystem
  5. Copy MP3 Files

Check Device Name For The Disk Drive

Most of these steps will require root access, so become root with su if you are logged in with normal access:

paul@cougar ~ > su                                                              
Password: 

The most important step is to correctly identify the device name of the drive you will be using with the mp3 player. You wouldn't want to accidentally erase your PC's normal drive! This table shows the normal device names, but yours may differ if your PC has more than two IDE controllers.

Device NameIDE ControllerDevice Setting
/dev/hdaPrimaryMaster
/dev/hdbPrimarySlave
/dev/hdcSecondaryMaster
/dev/hddSecondarySlave

If you've recently booted your PC (presumably you had to reboot to physically install the drive you're preparing for use with the mp3 player), you can use the dmesg command to view the startup messages that the Linux kernel prints and scroll off the screen before you can read them. Here's an example using grep to show only the relevant lines.

paul@cougar /home/paul # dmesg | grep '^hd[a-z]:'
hda: Maxtor 98196H8, ATA DISK drive
hdc: IC25N010ATDA04-0, ATA DISK drive
hda: 160086528 sectors (81964 MB) w/2048KiB Cache, CHS=9964/255/63
hdc: 19640880 sectors (10056 MB) w/347KiB Cache, CHS=19485/16/63, (U)DMA        

In this example, the PC's normal drive is an 80 gigabyte Maxtor drive, and the drive that will receive the MP3 files is a 10 gigabyte IBM laptop drive. So we'll be careful to type "hdc" to refer to the 10 gigabyte laptop drive. The exact messages you see will depend on the IDE devices installed in your PC, but knowing the capacity of each drive you should be able to double check the device name and avoid reformatting your PC's main drive.

Partition The Drive With "fdisk"

The first step is to run the fdisk program, with the name of the device (in this example "/dev/hdc").

paul@cougar /home/paul # fdisk /dev/hdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklab
el
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 19485.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help):

The fdisk program is interactive and it will prompt you for commands, which are single letters. You can use 'm' to get a list of the commands, and 'p' will show you the current partition table. The fdisk program never actually writes until you use the 'w' command, so can always just quit and nothing on the drive will change.

The warning about more than 1024 cylinders can be safely ignored. The MP3 player never uses cylinder numbers (all access is LBA-based). Only very old LILO bootloaders, old PC bios chips, Microsoft DOS and older versions of Windows have trouble beyond 1024 cylinders.

In this example, the drive was brand new and did not have any partition table from previously installed data. If it did, you would need to use the "d" command to delete each of the existing partitions, and perhaps use the "p" command to print a summary of the partition table to make sure it is blank.

Starting with a blank partition table, you need to create a single partition that uses the entire drive:

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-19485, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-19485, default 19485):            
Using default value 19485

This linux-based fdisk program will create partitions that default to the correct type for the linux filesystems. You will need to change the type to "C", which is the FAT32 type (using LBA access mode):

Command (m for help): t
Partition number (1-4): 1
Changed system type of partition 1 to c (Win95 FAT32 (LBA))                     

As a quick check, the partition table should look approximately like this with the 'p' command:

Command (m for help): p

Disk /dev/hdc: 16 heads, 63 sectors, 19485 cylinders
Units = cylinders of 1008 * 512 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/hdc1             1     19485   9820408+   c  Win95 FAT32 (LBA)             

When you're satisfied, use 'w' to write the partition table. This is the point of no return if the drive previously had other data on it. Once the new partition table is written, the drive is effectively a new blank drive ready to be formatted.

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional                     
information.
Syncing disks.

In most cases, you will not need to reboot (unlike all Microsoft operating systems, which require rebooting to re-read the partition tables). However, if the fdisk program can not verify that the kernel has updated its knowledge of the drive's partition, it will advise you to reboot. No reboot was needed in this example.

Create FAT32 Filesystem With "mkdosfs"

Now that your drive is properly partitioned, you need to create a FAT32 filesystem using the mkdosfs program. Unlike the Microsoft format utility, you can control a great number of parameters, and of these you must choose the "-s" (sectors per cluster) setting. This table shows the four settings that will work properly with the mp3 player firmware:

Sectors Per ClusterMinimum Filesystem Size
-s 8257 Megabytes
-s 16513 Megabytes
-s 321025 Megabytes
-s 642049 Megabytes

As long as your filesystem is not too small, it really doesn't matter much which one you choose.

When you run the mkdosfs program, you must also specify "-F 32" to create a FAT32 filesystem. The device name must specify the partition (/dev/hdc refers to the whole drive, and /dev/hdc1 refers to the first partition on the drive). Here is what you should see:

paul@cougar /home/paul # mkdosfs -F 32 -s 32 /dev/hdc1                          
mkdosfs 2.7 (14 Feb 2001)

The program runs very quickly... so quickly it might appear that nothing happened, but it follows the "no news is good news" style of most unix command line utilities. If there is no error message, it almost certainly worked.

Mount The New Filesystem

Now you must mount the new filesystem so that you can access it. For this example, a new directory was created to mount the drive:

paul@cougar /home/paul # mkdir -p /mnt/mp3disk                                  

Then to actually mount it, the normal linux mount command it used:

paul@cougar /home/paul # mount -t vfat /dev/hdc1 /mnt/mp3disk                   

Once the disk is mounted, it can be accessed just like any other part of the system. The df (disk free) program is a nice quick check that the mount command worked and that the filesystem size is what was expected.

paul@cougar /home/paul # df
Filesystem           1k-blocks      Used Available Use% Mounted on
/dev/hda3             69900668  16413364  49936540  25% /
/dev/hda1                46636      6582     37646  15% /boot
none                    300468         0    300468   0% /dev/shm
/dev/hdc1              9815584        16   9815568   1% /mnt/mp3disk            

Copy MP3 Files

Now the only step remaining is to copy files onto the drive. In this example, I inserted a cdrom (and let RedHat 7.2's automatic cdrom mount take care of mounting it). If you use the command line:

cp /mnt/cdrom/*.mp3 /mnt/mp3disk/                                               

Modern linux-based systems come with Gnome and/or KDE, and perhaps you will prefer their file managers (nautilus and konqueror) to copy and organize your files into the /tmp/mp3disk directory.

Of course, you will need to shut down and remove the drive and then attach it to the mp3 player circuit board. The shutdown process in Redhat and most other distributions will take care of properly unmounting the drive, or you could type "umount /mnt/mp3disk" if you really want to do it yourself.


MP3 Player, Firmware Upgrade Instructions, Paul Stoffregen.
Hyperterminal screen shots contribued by Kasper Bonne.
http://www.pjrc.com/tech/mp3/docs/hd_setup_linux.html
Last updated: February 23, 2005
Questions, Comments?? <paul@pjrc.com>