Author Topic: Sfdisk Partitioning Question  (Read 7250 times)

daniel3000

  • Hero Member
  • *****
  • Posts: 1003
    • View Profile
    • http://
Sfdisk Partitioning Question
« 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
SL-C3200 with weeXpc, based on pdaXrom 1.1.0beta3
HP 200LX with MS-DOS 5.0

InSearchOf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1144
    • View Profile
    • http://
Sfdisk Partitioning Question
« Reply #1 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
Sharp Zaurus SL-C3100 and SL-6000L
pdaXrom Developer
Please visit pdaXrom.org for updates
My Blog
IRC #pdaxrom @ FreeNode

daniel3000

  • Hero Member
  • *****
  • Posts: 1003
    • View Profile
    • http://
Sfdisk Partitioning Question
« Reply #2 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
SL-C3200 with weeXpc, based on pdaXrom 1.1.0beta3
HP 200LX with MS-DOS 5.0

daniel3000

  • Hero Member
  • *****
  • Posts: 1003
    • View Profile
    • http://
Sfdisk Partitioning Question
« Reply #3 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
« Last Edit: November 02, 2007, 05:38:06 am by daniel3000 »
SL-C3200 with weeXpc, based on pdaXrom 1.1.0beta3
HP 200LX with MS-DOS 5.0