Help - Search - Members - Calendar
Full Version: Sfdisk Partitioning Question
OESF Forums > General Forums > General Support and Discussion > Software
daniel3000
Hello,

I need to partition SD cards from a shell script using sfdisk, but don't know how to to that in a safe way.

No matter what the size of the SD card is, I would like to create a 128MB SWAP partition at the END of the card (i.e. as the second partition /dev/mmcda2) and the remaining space at the beginning (/dev/mmcda1) needs to be linux ext2.

I have used something like

CODE
sfdisk /dev/mmcda -uM << EOF
,128,S,
,,L,*
;
EOF


in order to achieve the opposite, i.e. 128MB swap as partition 1 and Linux ext2 as parition 2.

Any idea how to use sfdisk to achieve what I really need?
Thanks a lot!
Daniel

InSearchOf
QUOTE(daniel3000 @ Oct 30 2007, 09:13 AM) *
Hello,

I need to partition SD cards from a shell script using sfdisk, but don't know how to to that in a safe way.

No matter what the size of the SD card is, I would like to create a 128MB SWAP partition at the END of the card (i.e. as the second partition /dev/mmcda2) and the remaining space at the beginning (/dev/mmcda1) needs to be linux ext2.

I have used something like

CODE
sfdisk /dev/mmcda -uM << EOF
,128,S,
,,L,*
;
EOF


in order to achieve the opposite, i.e. 128MB swap as partition 1 and Linux ext2 as parition 2.

Any idea how to use sfdisk to achieve what I really need?
Thanks a lot!
Daniel


Just wondering why you want it at the END of the card?

Late
daniel3000
Because most systems only mount the first partition of the SD card, so the data partition should be the first one in favor of maximum compatibility.

daniel
daniel3000
Okay guys, I have solved the problem myself.
I use fdisk -l output first to read the total size of the card,
then I calculate the data partition size by substracting the wanted swap partitoin size (here 200MB),
then I create the data partition and swap partition using sfdisk and the calculated data partition size.

CODE
#!/bin/bash

SDSIZE=`fdisk -l /dev/mmcda | grep "Disk /dev/mmcda" | cut -f 3 -d " "`
SWAPSIZE=200
DATASIZE=$[$SDSIZE-$SWAPSIZE]


echo SD card size:            $SSIZE MB
echo Size for data partition: $DATASIZE MB
echo Size for swap partition: $SWAPSIZE MB

sfdisk /dev/mmcda -uM << EOF
,$DATASIZE,L,*
,,S,
;
EOF


Seems to work very well.

daniel
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2014 Invision Power Services, Inc.