DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 3 Weeks Ago
bsd007's Avatar
bsd007 bsd007 is offline
Always learning
 
Join Date: Sep 2014
Posts: 113
Default How to format SD card as fat32 ?

Hi,

I am using a card reader to connect a SD card.
What is the command to format it as FAT32 ?
__________________
OpenBSD 6.2
Intel(R) Core(TM) i3-6100 CPU
Ram 4GB
Intel HD Graphics

Last edited by bsd007; 3 Weeks Ago at 02:51 PM.
Reply With Quote
  #2   (View Single Post)  
Old 3 Weeks Ago
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 5,944
Default

An MBR partition table is recommended for devices that use FAT filesystems.

Step 1. Create an MBR and MBR partition table with fdisk(8). Once created, there will be a virtual disklabel "i" to address the FAT partition.
Step 2. Format the filesystem with newfs_msdos(8).

An MBR type of x0C is FAT32L, though on modern systems both x0C and x0B (FAT32) use long file names and there should be little operational difference.

The easiest way to create a new MBR is to use fdisk()'s "i" option. This creates an OpenBSD MBR partition (type xA6) of the entire drive with a gap for boot blocks. Then, edit the partition to use a FAT filesystem type, such as x0C. When editing (with the "e" option) the only change to the partition would be the partition type, from "A6" to "C" or "B".

Lastly, the newfs_msdos(8) command will format the filesystem. You will need to use the -F option, as FAT32 is not the default.
  1. # fdisk -iy <drive>
  2. # fdisk -e <drive>
  3. # newfs_msdos -F 32 <drive>i
Edited to add: Please read the fdisk(8) man page. You will need to learn how to print the partition table, and to edit partition number 3.

Last edited by jggimi; 3 Weeks Ago at 03:23 PM.
Reply With Quote
  #3   (View Single Post)  
Old 3 Weeks Ago
bsd007's Avatar
bsd007 bsd007 is offline
Always learning
 
Join Date: Sep 2014
Posts: 113
Default

@jggimi
Okay but how do I find the <drive> name ?
__________________
OpenBSD 6.2
Intel(R) Core(TM) i3-6100 CPU
Ram 4GB
Intel HD Graphics
Reply With Quote
  #4   (View Single Post)  
Old 3 Weeks Ago
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 5,944
Default

When you insert the SD card in the card reader, kernel messages are produced. One of those will show the device name and number, such as sd2 or wd1. You can see these kernel messages on the console, in an xconsole(1) window, in /var/log/messages, and in dmesg(8) output. You can also list all currently connected drives with $ sysctl hw.disknames.
Reply With Quote
  #5   (View Single Post)  
Old 3 Weeks Ago
bsd007's Avatar
bsd007 bsd007 is offline
Always learning
 
Join Date: Sep 2014
Posts: 113
Default

Code:
$ sysctl hw.disknames
hw.disknames=sd0:45aa2bf0be15f70c,cd0:,sd1:
So its sd1 ?

Code:
# fdisk -iy sd1                                                                
Writing MBR at offset 0.
Code:
# fdisk -e sd1  
Enter 'help' for information
fdisk: 1> 
What should I do now ?
__________________
OpenBSD 6.2
Intel(R) Core(TM) i3-6100 CPU
Ram 4GB
Intel HD Graphics
Reply With Quote
  #6   (View Single Post)  
Old 3 Weeks Ago
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 5,944
Default

Quote:
Originally Posted by bsd007 View Post
What should I do now ?
Perhaps you missed my edit, earlier.
Quote:
Originally Posted by jggimi View Post
Edited to add: Please read the fdisk(8) man page. You will need to learn how to print the partition table, and to edit partition number 3.
Reply With Quote
  #7   (View Single Post)  
Old 3 Weeks Ago
sauerquint sauerquint is offline
Real Name: Quintin
New User
 
Join Date: Oct 2015
Location: Anchorage
Posts: 3
Default

This is my saved reference for it

OpenBSD: Formatting Disks
This note shows how to identify and format a disk using OpenBSD.

Tools

fdisk - partition table editor
disklabel - BSD partition editor
newfs - formatter

Steps

1. Identify name of new disk, for example, insert a USB stick, then type 'dmesg'

scsibus0 at umass0: 2 targets, initiator 0
sd0 at scsibus0 targ 1 lun 0: SCSI2 0/direct removable
sd0: 1000MB, 512 bytes/sec, 2048000 sec total

2. Allocate the whole disk to BSD

This is done so that if it is used in another operating system, it will be pre-allocated. This is done using fdisk. You can select 'help' at any time. You may wish to remove existing partitions, such as ones associated with Windows / Fat32 etc - if so, simply change the partition type to 0 using the edit command.

# fdisk -e sd0
fdisk: 1> edit 3
Partition id ('0' to disable) [0 - FF]: [0] (? for help) A6
Do you wish to edit in CHS mode? [n]
offset: [0]
size: [0] *
fdisk:*1> w
Writing MBR at offset 0.
fdisk: 1> q

# fdisk sd0
Disk: sd0 geometry: 127/255/63 [2048000 Sectors]
Offset: 0 Signature: 0xAA55
Starting Ending LBA Info:
#: id C H S - C H S [ start: size ]
-------------------------------------------------------------------------------
0: 00 0 0 0 - 0 0 0 [ 0: 0 ] unused
1: 00 0 0 0 - 0 0 0 [ 0: 0 ] unused
2: 00 0 0 0 - 0 0 0 [ 0: 0 ] unused
3: A6 0 0 1 - 127 122 59 [ 0: 2048000 ] OpenBSD

3. Create a whole partition on the disk with disklabel (the * means whole disk):

# disklabel -E sd0
> a
partition: [a]
offset: [0]
size: [2048000] *
FS type: [4.2BSD]
> w
> x

4. Format the disk:

# newfs sd0a
/dev/rsd0a: 1000.0MB in 2048000 sectors of 512 bytes
5 cylinder groups of 202.47MB, 12958 blocks, 25984 inodes each super-block backups (for fsck -b #) at:
32, 414688, 829344, 1244000, 1658656,

5. Add an entry in the fstab file

/dev/sd0a /mnt/usb ffs rw,nodev,nosuid 1 2
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
codepage and iocharset in fat32 aka msdos filesystem e1-531g OpenBSD General 3 18th January 2016 06:53 PM
New Package Format shep OpenBSD Packages and Ports 1 22nd September 2014 03:42 PM
create a FAT32 partition and format it. wesley OpenBSD General 2 6th November 2010 08:31 AM
Formatting fat32 drive quickly map7 FreeBSD General 10 26th July 2008 05:17 PM
strange with dvd+rw-format cyberboy FreeBSD General 0 26th May 2008 05:43 PM


All times are GMT. The time now is 12:16 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick