• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

[REF] manual partition of sdcard w/parted,goto ext3/4 from adb. no liveCD req'd

Search This thread

51dusty

Senior Member
Feb 11, 2009
144
13
bville, md
i needed a way to format my sdcard & install swap capable rom with no card reader...grrr...my gray hair is your gain!

READ THIS FIRST: i wrote a script that automagically partitions the sdcard. get it here.

if you still want to partition manually, read on.

i did this with a BLANK 8gb card and a fresh rom install, so i had no data to lose..be careful. i take no responsibility for what happens to your phone, sdcard, data, sanity, etc if you follow these instructions. remember to backup your sdcard to your pc before you begin. :)

technically, you don't need adb for this, as you can partition your card in the recovery console on the g1(...not the terminal app) using the commands in this post. however, once you wipe your sdcard, you may want some way of getting a new rom onto the phone. ;p

these instructions apply to both, the windows command prompt and the mac terminal.

just about any size and/or class of sdcard will work, but you will want to use a class 6 cause it's wicked fast. 16gb transcend sdcards seem to be giving some people trouble and throwing "ERROR: input/output error during write on /dev/block/mmcblk0" when trying to partition. use them at your own peril.

the example in this thread is for MY sdcard...YOUR sdcard will be different and the partition sizes may vary. apply ur information(sdcard size, partition size) when appropriate. following the instructions in this post will erase ALL DATA on the sdcard before creating new partitions.

read the ENTIRE post VERY carefully BEFORE proceeding or asking questions...


#####

note #1: all typed commands are in bold. adb/console commands in black. windows prompt commands in green.

note #2: if all else fails...remove all partitions and create new. this seems to solve 99.9% of non-hardware related problems.

note #3: if note #2 fails...try 'mklabel msdos'. see below for more info. :)

note to ext3/ext4 fs users: parted does NOT support CREATING ext3/ext4 partitions..you MUST create with ext2 and upgrade. also, parted CAN RESIZE ext3 partitions, but with restrictions. check out the table on the features page, of their website. i will NOT go into resizing partitions in this post as there are many variations...


#####

need to backup your ext partition?

note: these backup commands must be run while phone is booted, not recovery.

to backup your ext partition to your current directory: adb pull /system/sd/ %CD%\sdbackup
to restore back to sdcard: adb push %CD%\sdbackup /system/sd


#####

having issues? please post the following when asking for help:

output from the following commands
parted /dev/block/mmcblk0 print
parted /dev/block/mmcblk0 check 1, if any.
parted /dev/block/mmcblk0 check 2, if any.
parted /dev/block/mmcblk0 check 3, if any.

what rom are you using?
what brand/size/class sdcard?
can you see fat32 partition on the phone? ie. through andExplorer or similar..


#####

materials:
g1 with cm-recovery-1.4
sdcard <--class 6 recommended(adata makes good ones...they max out the g1 hw in terms of speed)
rooted rom with ext3/4 support & swap capability <--recommend CyanogenMod
adb
fingas(or toes if you're this guy)​


part i - prepare the sdcard:

boot your g1 into recovery (using home + power)
drop to console (alt + x)

open windows command prompt and enter:
adb shell

now at the # prompt enter:
parted /dev/block/mmcblk0

you are now in parted...hopefully. if not, check your typing, start over, do more research, or give up.

to find out the size of your sdcard & the partitions that it contains, enter:
print

you may receive a message from the program:
Code:
"No Implementation: Partition 1 isn't aligned to cylinder boundaries. This is
still unsupported."

the error says it all.. ;P
not sure what this means exactly(besides our partitions being out of alignment), but it is not good for our purposes.

also, if your "Partition Table" is reported as being "loop", i suggest repairing with the following procedure as well since it seems to be causing some problems too.

to fix, type:
mklabel msdos

it may give you some guff about:
Code:
Warning: The existing disk label on /dev/block/mmcblk0 will be destroyed and all data on 
this disk will be lost. Do you want to continue?
parted: invalid token: msdos

answer y to the 'yes/no'..

and then:
Code:
New disk label type?

confirm with: msdos

re-enter: print


you should get something like:
Code:
print
print
Model: Unknown (unknown)
Disk /dev/block/mmcblk0: 7969MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      512B    7469MB  7469MB  primary  fat32        lba
 2      7469MB  7969MB  500MB   primary  ext2

or, if your sdcard is new/empty you'll get:

Code:
print
print
Model: Unknown (unknown)
Disk /dev/block/mmcblk0: 7969MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags

if no numbered partitions come up, move onto next step. if not, delete ALL partitions that you see with the rm command. it has the format: rm <partition number>.
in this case:
rm 1
rm 2


the fourth line in the 'print' command output shows you the total size of sdcard in MB(or GB if you card is large)..mine says: Disk /dev/block/mmcblk0: 7969MB

use this number(XXXXMB) and do some simple math to get the size of your partitions.

7969MB - 32MB linux-swap = 7937MB
7937MB - 500MB ext2 = 7437MB fat32

32MB seems to be alright size for swap, though it can be lower depending on your sdcard size.
500 MB is a good round number for the ext2 partition...no need for more.
that leaves us with 7437MB for fat32 storage.​


part ii - create partitions:

for a2sd & swap to work properly, partitions MUST be created in this order: fat32, ext2, linux-swap

the command to create partitions is mkpartfs...command format is:
mkpartfs <partition type> <fs type> <start> <end>

note#1: the <start>/<end> numbers in the following section correspond to the italicized numbers above. your partition information will most likely be different.

note#2: by default parted assumes ur using MB as the units in commands. say you have a card that is LARGE(like 16GB) and want a partition of 12GB...all you do is use the proper units(ie. mkpartfs primary fat32 0 12GB) and parted will oblige. you can use decimals as well...if you want a similar setup to my calculations above, you would have a fat32 partition of 15.4GB(ie. mkpartfs primary fat32 0 15.4GB), 500MB ext2, and 32MB swap

now we create the partitions:
mkpartfs primary fat32 0 7437
mkpartfs primary ext2 7437 7937
mkpartfs primary linux-swap 7937 7969


to check out our handy work, enter:
print

output should be similar to:
Code:
print
print
Model: Unknown (unknown)
Disk /dev/block/mmcblk0: 7969MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      512B    7437MB  7437MB  primary  fat32        lba
 2      7437MB  7937MB  500MB   primary  ext2
 3      7937MB  7969MB  32.2MB  primary  linux-swap(v1)

to exit parted type:
quit

after quitting you may receive a message containing:
Code:
Information: You may need to update /etc/fstab.

no need to worry. fyi, fstab is a file that keeps track of disks & partitions in *nix. more info on fstab can be found here.​


part iii - convert ext2 to ext3/ext4:

parted will not create ext3/ext4 partitions...see beginning of post
to upgrade, enter:
upgrade_fs

you now have journaling(aka ext3)! if ext3 is all you want, skip next two commands.

you want ext4?
enter:
tune2fs -O extents,uninit_bg,dir_index /dev/block/mmcblk0p2
e2fsck -fpDC0 /dev/block/mmcblk0p2


part iv - copy rom to sdcard and install, enable swap:

open another win cmd prompt, enter:
adb shell mount /sdcard
adb push /update-path/update.zip /sdcard
exit


in original cmd prompt, enter:
reboot recovery

after reboot:
wipe data (alt + w) <--this one is optional, but i like fresh installs
install rom (alt + s)

to enable swap, see this page.
note: you do not need to enable swap if your rom does it automagically.​

#####

all told, i end up with:
~7.5GB fat32
~500MB ext4
~32MB swap
cyanogen-v3.6.8.1 running faster than ever!

hope this wasn't too painful.

btw, you could use a live cd, but i think this is easier and maybe a little more fun! ;)
 
Last edited:

jay22are

Senior Member
Jun 11, 2009
137
0
does this damage the sd card in anyway? i was running jac hero with swapper and it killed my sd card...but nice tut..might try it
 

h.nocturna

Senior Member
Oct 8, 2008
1,116
110
wow... I never knew you were allowed to partition straight from terminal or I wouldn't have wasted a CD on g-parted... =/ nice guide, next time I need to partition, I'll use this method.

jay22are, partitioning the card will not damage it, but if you use it for swap you will always run the risk of corrupting your card, however, I read that someone calculated that it would still take 2yrs for your card to start having problems using swapper. So good luck.
 

51dusty

Senior Member
Feb 11, 2009
144
13
bville, md
Is their a noticeable increase in speed when running a non hero rom with swapper?

extremely noticeable. apps run & transition much smoother than without the swap partition. although, i must say that most of the speed & stability in my setup is cyanogen's rom...it's awesome.

now i have a question...

does anyone know if there are speed/reliability differences between using the swapfile(like with the swapper app) and the swap partition? i did the partition b/c that's how i've always configured linux installs and it let's me mount the sdcard w/o issues.
 

engagedtosmile

Senior Member
Mar 28, 2009
522
8
when i'm trying to do the commands I run into this:


(parted) mkpartfs fat32 0 7584
mkpartfs fat32 0 7584
mkpartfs fat32 0 7584
parted: invalid token: fat32
Partition type? primary/extended?


doesn't seem like the guide covers all of the steps.
 

cyanogen

Retired Recognized Developer
Jan 4, 2009
2,515
5,751
Seattle
cyanogenmod.com
Was wondering when someone would write this guide!

wow... I never knew you were allowed to partition straight from terminal or I wouldn't have wasted a CD on g-parted... =/ nice guide, next time I need to partition, I'll use this method.

I just built and included Parted on the new recovery image (1.3.1). I was just waiting for someone to do a writeup about it because I'm lazy :rolleyes:

when i'm trying to do the commands I run into this:


(parted) mkpartfs fat32 0 7584
mkpartfs fat32 0 7584
mkpartfs fat32 0 7584
parted: invalid token: fat32
Partition type? primary/extended?


doesn't seem like the guide covers all of the steps.

Should be "mkpartfs primary fat32 0 7584".

Parted can also resize your existing partitions without erasing data.
 

51dusty

Senior Member
Feb 11, 2009
144
13
bville, md
Was wondering when someone would write this guide!



I just built and included Parted on the new recovery image (1.3.1). I was just waiting for someone to do a writeup about it because I'm lazy :rolleyes:



Should be "mkpartfs primary fat32 0 7584".

Parted can also resize your existing partitions without erasing data.

@engage & others: fixed my mistake in original post

thanks cyanogen!

guess that's what i get for typing too fast... ;p
 

CC CEO

Senior Member
Jan 14, 2008
144
1
what am i doing wrong?

Im using a 2gb card.

following the guide after i use the print command it tells me my card is 2033MB in size

and it lists my start point at 32.3kB

i typed: mkpartfs primary fat32 32.3kB 1458MB

it states it cant make the partition and the closest it can do is 31.7kb to 31.7.

is it something im doing?
 

51dusty

Senior Member
Feb 11, 2009
144
13
bville, md
Im using a 2gb card.

following the guide after i use the print command it tells me my card is 2033MB in size

and it lists my start point at 32.3kB

i typed: mkpartfs primary fat32 32.3kB 1458MB

it states it cant make the partition and the closest it can do is 31.7kb to 31.7.

is it something im doing?

i believe the reason it is not exactly 0 is because it needs room for the partition information. mine was similar...i believe 31.9kb.

you don't need to use the 'kb' / 'mb'...i just use whole numbers and the prg figures out the hard stuff..

hmm...maybe remove all partitions (using the rm command) and start from scratch.

check out this site

can you paste/link to the console output to the forum?
 

jklong03

Senior Member
What about ext4

I got brave and decided to "resize" my ext4 partition down 32MB to create a swap space.

First, I backed up everything using windoze after mounting.
But then it occured to me perhaps I should do a complete backup of my sd card first, including my ext4. But HOW?

Also, cyanogen said parted will resize with no data loss, so I assume you just use the "resize part# start stop" ??

Anyway, when I did my print command, it listed my FAT32 and an ext3. When I try and do anything to ext3, I get a "Error: File system has an incompatible feature enabled" message. I am guessing this is the ext4 stuff?

Will just sit tight for now, before I blow my entire SD card and have to start from scratch till someone can tell me safest way to backup sd card to pc completely and what to do about the ext4 errors.

Thanks in advance for the help!
 

schwiz

Senior Member
Jul 3, 2009
204
29
very cool, I feel like such a dork doing it this way and it feels good! When i put in my command for the partition I got this error:
Warning: You requested a partition from 0.00B to 7216MB.
The closest location we can manage is 512B to 31.7kB. Is this still acceptable
to you?
not sure why I think its because the disk already had partitions. I couldn't remove them because parted said the disc was mounted. So I still couldn't avoid booting to the live cd and reformating though :*(

edit: actually rebooting the phone allowed me to use the rm command and remove my partitions and follow your instructions. Worked great thank you! this is going to save me loads of hassle in the future

edit2: spoke too soon when I run upgrade_fs I get this message
e2fsck 1.41.6 (30-May-2009)
/sbin/e2fsck: Superblock invalid, trying backup blocks...
/sbin/e2fsck: Bad magic number in super-block while trying to open /dev/block/mm
cblk0p2

The superblock could not be read or does not describe a correct ext2
filesystem. If the device is valid and it really contains an ext2
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
e2fsck -b 8193 <device>
so i use the repair ext filesystems on the recovery image and it says
Checking filesystems. Error checking filesystem! Run e2fsck manually from console.
any help?

edit3: deleted the partitions and did it again, worked this time
 
Last edited:

temporizer

Senior Member
Aug 17, 2006
617
0
38
Vancouver
extremely noticeable. apps run & transition much smoother than without the swap partition. although, i must say that most of the speed & stability in my setup is cyanogen's rom...it's awesome.

now i have a question...

does anyone know if there are speed/reliability differences between using the swapfile(like with the swapper app) and the swap partition? i did the partition b/c that's how i've always configured linux installs and it let's me mount the sdcard w/o issues.

first, IMHO and research, the swap partition does nothing to cyanogen's roms because of his magic touch, however, it does work wonders with the browser, and with all other builds besides cyan's

second, The swap file is placed on your fat32 partition, when you mount your sd card to your pc, the swap file disappears and your rom crashes...

stick with a linux-swap partition. you shouldn't go over 32mb tho, it gets glitchy after that.
 
Last edited:

51dusty

Senior Member
Feb 11, 2009
144
13
bville, md
I got brave and decided to "resize" my ext4 partition down 32MB to create a swap space.

First, I backed up everything using windoze after mounting.
But then it occured to me perhaps I should do a complete backup of my sd card first, including my ext4. But HOW?

Also, cyanogen said parted will resize with no data loss, so I assume you just use the "resize part# start stop" ??

Anyway, when I did my print command, it listed my FAT32 and an ext3. When I try and do anything to ext3, I get a "Error: File system has an incompatible feature enabled" message. I am guessing this is the ext4 stuff?

Will just sit tight for now, before I blow my entire SD card and have to start from scratch till someone can tell me safest way to backup sd card to pc completely and what to do about the ext4 errors.

Thanks in advance for the help!

to backup ext partition just cp /system/sd it has the apps dirs and dalvik-cache

this ver of parted does not handle ext3/4...that's why you have to upgrade after partitioning. as far as resizing goes...i would imagine it can't do that to ext3/4 either.

maybe cyanogen can provide complete explanation of ext3/4 support...?

my advice would be to delete all and start fresh..i'm not a huge fan of resizing partitions...it seems to let gremlins into the fs. ;p
 

Top Liked Posts

  • There are no posts matching your filters.
  • 8
    i needed a way to format my sdcard & install swap capable rom with no card reader...grrr...my gray hair is your gain!

    READ THIS FIRST: i wrote a script that automagically partitions the sdcard. get it here.

    if you still want to partition manually, read on.

    i did this with a BLANK 8gb card and a fresh rom install, so i had no data to lose..be careful. i take no responsibility for what happens to your phone, sdcard, data, sanity, etc if you follow these instructions. remember to backup your sdcard to your pc before you begin. :)

    technically, you don't need adb for this, as you can partition your card in the recovery console on the g1(...not the terminal app) using the commands in this post. however, once you wipe your sdcard, you may want some way of getting a new rom onto the phone. ;p

    these instructions apply to both, the windows command prompt and the mac terminal.

    just about any size and/or class of sdcard will work, but you will want to use a class 6 cause it's wicked fast. 16gb transcend sdcards seem to be giving some people trouble and throwing "ERROR: input/output error during write on /dev/block/mmcblk0" when trying to partition. use them at your own peril.

    the example in this thread is for MY sdcard...YOUR sdcard will be different and the partition sizes may vary. apply ur information(sdcard size, partition size) when appropriate. following the instructions in this post will erase ALL DATA on the sdcard before creating new partitions.

    read the ENTIRE post VERY carefully BEFORE proceeding or asking questions...


    #####

    note #1: all typed commands are in bold. adb/console commands in black. windows prompt commands in green.

    note #2: if all else fails...remove all partitions and create new. this seems to solve 99.9% of non-hardware related problems.

    note #3: if note #2 fails...try 'mklabel msdos'. see below for more info. :)

    note to ext3/ext4 fs users: parted does NOT support CREATING ext3/ext4 partitions..you MUST create with ext2 and upgrade. also, parted CAN RESIZE ext3 partitions, but with restrictions. check out the table on the features page, of their website. i will NOT go into resizing partitions in this post as there are many variations...


    #####

    need to backup your ext partition?

    note: these backup commands must be run while phone is booted, not recovery.

    to backup your ext partition to your current directory: adb pull /system/sd/ %CD%\sdbackup
    to restore back to sdcard: adb push %CD%\sdbackup /system/sd


    #####

    having issues? please post the following when asking for help:

    output from the following commands
    parted /dev/block/mmcblk0 print
    parted /dev/block/mmcblk0 check 1, if any.
    parted /dev/block/mmcblk0 check 2, if any.
    parted /dev/block/mmcblk0 check 3, if any.

    what rom are you using?
    what brand/size/class sdcard?
    can you see fat32 partition on the phone? ie. through andExplorer or similar..


    #####

    materials:
    g1 with cm-recovery-1.4
    sdcard <--class 6 recommended(adata makes good ones...they max out the g1 hw in terms of speed)
    rooted rom with ext3/4 support & swap capability <--recommend CyanogenMod
    adb
    fingas(or toes if you're this guy)​


    part i - prepare the sdcard:

    boot your g1 into recovery (using home + power)
    drop to console (alt + x)

    open windows command prompt and enter:
    adb shell

    now at the # prompt enter:
    parted /dev/block/mmcblk0

    you are now in parted...hopefully. if not, check your typing, start over, do more research, or give up.

    to find out the size of your sdcard & the partitions that it contains, enter:
    print

    you may receive a message from the program:
    Code:
    "No Implementation: Partition 1 isn't aligned to cylinder boundaries. This is
    still unsupported."

    the error says it all.. ;P
    not sure what this means exactly(besides our partitions being out of alignment), but it is not good for our purposes.

    also, if your "Partition Table" is reported as being "loop", i suggest repairing with the following procedure as well since it seems to be causing some problems too.

    to fix, type:
    mklabel msdos

    it may give you some guff about:
    Code:
    Warning: The existing disk label on /dev/block/mmcblk0 will be destroyed and all data on 
    this disk will be lost. Do you want to continue?
    parted: invalid token: msdos

    answer y to the 'yes/no'..

    and then:
    Code:
    New disk label type?

    confirm with: msdos

    re-enter: print


    you should get something like:
    Code:
    print
    print
    Model: Unknown (unknown)
    Disk /dev/block/mmcblk0: 7969MB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    
    Number  Start   End     Size    Type     File system  Flags
     1      512B    7469MB  7469MB  primary  fat32        lba
     2      7469MB  7969MB  500MB   primary  ext2

    or, if your sdcard is new/empty you'll get:

    Code:
    print
    print
    Model: Unknown (unknown)
    Disk /dev/block/mmcblk0: 7969MB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    
    Number  Start   End     Size    Type     File system  Flags

    if no numbered partitions come up, move onto next step. if not, delete ALL partitions that you see with the rm command. it has the format: rm <partition number>.
    in this case:
    rm 1
    rm 2


    the fourth line in the 'print' command output shows you the total size of sdcard in MB(or GB if you card is large)..mine says: Disk /dev/block/mmcblk0: 7969MB

    use this number(XXXXMB) and do some simple math to get the size of your partitions.

    7969MB - 32MB linux-swap = 7937MB
    7937MB - 500MB ext2 = 7437MB fat32

    32MB seems to be alright size for swap, though it can be lower depending on your sdcard size.
    500 MB is a good round number for the ext2 partition...no need for more.
    that leaves us with 7437MB for fat32 storage.​


    part ii - create partitions:

    for a2sd & swap to work properly, partitions MUST be created in this order: fat32, ext2, linux-swap

    the command to create partitions is mkpartfs...command format is:
    mkpartfs <partition type> <fs type> <start> <end>

    note#1: the <start>/<end> numbers in the following section correspond to the italicized numbers above. your partition information will most likely be different.

    note#2: by default parted assumes ur using MB as the units in commands. say you have a card that is LARGE(like 16GB) and want a partition of 12GB...all you do is use the proper units(ie. mkpartfs primary fat32 0 12GB) and parted will oblige. you can use decimals as well...if you want a similar setup to my calculations above, you would have a fat32 partition of 15.4GB(ie. mkpartfs primary fat32 0 15.4GB), 500MB ext2, and 32MB swap

    now we create the partitions:
    mkpartfs primary fat32 0 7437
    mkpartfs primary ext2 7437 7937
    mkpartfs primary linux-swap 7937 7969


    to check out our handy work, enter:
    print

    output should be similar to:
    Code:
    print
    print
    Model: Unknown (unknown)
    Disk /dev/block/mmcblk0: 7969MB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    
    Number  Start   End     Size    Type     File system  Flags
     1      512B    7437MB  7437MB  primary  fat32        lba
     2      7437MB  7937MB  500MB   primary  ext2
     3      7937MB  7969MB  32.2MB  primary  linux-swap(v1)

    to exit parted type:
    quit

    after quitting you may receive a message containing:
    Code:
    Information: You may need to update /etc/fstab.

    no need to worry. fyi, fstab is a file that keeps track of disks & partitions in *nix. more info on fstab can be found here.​


    part iii - convert ext2 to ext3/ext4:

    parted will not create ext3/ext4 partitions...see beginning of post
    to upgrade, enter:
    upgrade_fs

    you now have journaling(aka ext3)! if ext3 is all you want, skip next two commands.

    you want ext4?
    enter:
    tune2fs -O extents,uninit_bg,dir_index /dev/block/mmcblk0p2
    e2fsck -fpDC0 /dev/block/mmcblk0p2


    part iv - copy rom to sdcard and install, enable swap:

    open another win cmd prompt, enter:
    adb shell mount /sdcard
    adb push /update-path/update.zip /sdcard
    exit


    in original cmd prompt, enter:
    reboot recovery

    after reboot:
    wipe data (alt + w) <--this one is optional, but i like fresh installs
    install rom (alt + s)

    to enable swap, see this page.
    note: you do not need to enable swap if your rom does it automagically.​

    #####

    all told, i end up with:
    ~7.5GB fat32
    ~500MB ext4
    ~32MB swap
    cyanogen-v3.6.8.1 running faster than ever!

    hope this wasn't too painful.

    btw, you could use a live cd, but i think this is easier and maybe a little more fun! ;)
    1
    1
    It's not an issue in regards to hard drive grinding, I know that much thanks :rolleyes:
    I was talking about efficiency of the the different file systems which effect performance.
    You probably know more about ext partitions than I do (well, alot more apparently ;)) but I don't see a backward compatibility issue when all the partition is doing is storing apps on a phone's sd card.
    So no sense having the system look in 12800 different places just to read an app when the performance would be better if the app was stored in a single chunk.

    Now, if backwards compatibility is that big an issue, then for sure it wouldn't be a great idea.
    But I'm not really seeing a backwards compatibility issue.
    It's just apps on a phone and if they're important apps or paid apps, then I'm sure a Titanium backup would solve that issue.

    if it's performance you are interested in then turn off journaling

    tune2fs -O ^has_journal /dev/block/mmcblk0p2