OESF Portables Forum

Everything Else => General Support and Discussion => Zaurus General Forums => Archived Forums => Software => Topic started by: daniel3000 on October 30, 2007, 09:13:50 am

Title: Sfdisk Partitioning Question
Post by: daniel3000 on October 30, 2007, 09:13:50 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: [Select]
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
Title: Sfdisk Partitioning Question
Post by: InSearchOf on October 30, 2007, 10:48:35 am
Quote from: 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: [Select]
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
Title: Sfdisk Partitioning Question
Post by: daniel3000 on October 31, 2007, 05:33:05 am
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
Title: Sfdisk Partitioning Question
Post by: daniel3000 on November 02, 2007, 05:37:48 am
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: [Select]
#!/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