Take the 2-minute tour ×
Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. It's 100% free, no registration required.

As this warns, you should not enable swap on the wrong partition or you can destroy your phone:

OK before we go any further! previous phones had a partition layout where mmcblck0 was the SDcard (external) our phone uses mmcblck1 for the external sd. This is important because if you use an app it may be preset to use mmcblck0 as swap partition.using this setting will cause you to use your sbl2 or sbl3 as swap partition.this will brick your phone and unbrick guide will be useles.

So the swap partition might be /dev/block/mmcblk0p3 if I have 3 partitions (fat32, sdext, swap) on my SD card, or /dev/block/mmcblk0p2 if I have 2 partitions (fat43 and swap) or /dev/block/mmcblk1p? if you have a different phone, etc. and the wrong choice can brick your phone.

How do you find out which partition is which? It should be the only partition on any drive of the phone with the swap filesystem.

  • fdisk -l does this on Ubuntu, but outputs nothing in Android
  • blkid does not show the swap partition
  • cat /proc/partitions lists a lot of partitions, but doesn't indicate which is the swap
  • cat /proc/swaps only lists swaps that are already being used
  • cat /proc/mtd only says dev: size erasesize name and nothing else
  • ls /dev/block/vold lists some partitions as 179:64 179:65 179:66, but doesn't indicate what they are?
  • 4ext recovery will show it in the table of partitions (swap swap 129 MiB), but doesn't say the dev name
  • ...

Even if there's no command line tool to print it directly, surely there's a way to deduce it from some other information??

share|improve this question
    
Is there something in your /proc/swaps? –  ott-- Sep 14 '13 at 14:51
    
@ott--: cat /proc/swaps just shows the swapfile created by swapper 2, not the partition on the SD card –  endolith Sep 14 '13 at 15:30
    
As you already know the device (SDCard), have you tried to use mount (without parameters) to find the corresponding block device (/dev/block/*), and check that against the list of /proc/partitions (or /proc/mtd)? If you have no further partition on your card, your swap partition should be "the other one ending with a digit", unless mount pointed to vold only. In that case, comparing sizes (or temporarily removing the card for a "diff") might help. –  Izzy Oct 6 '13 at 0:33

2 Answers 2

up vote 7 down vote accepted

I installed the Disk Info app and in the options, I enabled Expert mode and Unmounted partitions. It doesn't say "swap", but it shows clearly that it's the only other partition on the SD card and it's the right size, so /dev/block/mmcblk1p2 must be the one:

screenshot of Disk Info

Swapper 2 is configured to use /dev/block/mmcblk0p3 by default, so I'm glad I didn't go with the default.

share|improve this answer

fdisk -l works if you pass the whole disk device name explicitly (e.g., fdisk -l /dev/block/mmcblk1); what does not work is automatic discovery of block devices (apparently because Android places block device files under the /dev/block directory, but fdisk expects to see those files directly in /dev). Therefore one option is to collect the list of whole disk devices (/dev/block/mmcblk0, /dev/block/mmcblk1, …) and look at their partition tables using fdisk -l <device>. These whole disk devices are listed in /proc/partitions before the corresponding partitions.

The blkid utility does not look at the partition table at all — it opens all block devices known by the system and detects the filesystem type from the actual data on those devices; therefore blkid will not show correct information for the swap partition until that partition is initialized by mkswap. This means that blkid is useless for your current task (finding which partition should be passed to mkswap).

mount usually shows devices under /dev/block/vold, which are named according to their major and minor numbers. To get the usual device name, you can look in /proc/partitions to find a row containing the same numbers in the first two columns. Then you can remove the p<number> part from the end of the device name, add /dev/block/ at the start and pass the resulting name to fdisk -l to see the partition table of the corresponding device.

Beware that if you look at the fdisk -l output for the internal eMMC flash, you may find lots of partitions with strange types, especially on Qualcomm-based devices. E.g., see the partition table for Samsung Galaxy W (GT-I8150):

# fdisk -lu /dev/block/mmcblk0                                  

Disk /dev/block/mmcblk0: 3959 MB, 3959422976 bytes
1 heads, 16 sectors/track, 483328 cylinders, total 7733248 sectors
Units = sectors of 1 * 512 = 512 bytes

              Device Boot      Start         End      Blocks  Id System
/dev/block/mmcblk0p1               1      212991      106495+  c Win95 FAT32 (LBA)
Partition 1 does not end on cylinder boundary
/dev/block/mmcblk0p2   *      212992      213991         500  4d Unknown
Partition 2 does not end on cylinder boundary
/dev/block/mmcblk0p3          213992      221183        3596  46 Unknown
Partition 3 does not end on cylinder boundary
/dev/block/mmcblk0p4          221184     7733247     3756032   5 Extended
Partition 4 does not end on cylinder boundary
/dev/block/mmcblk0p5          229376      239615        5120  47 Unknown
/dev/block/mmcblk0p6          245760      285759       20000  49 Unknown
/dev/block/mmcblk0p7          286720      292863        3072  58 Unknown
/dev/block/mmcblk0p8          294912      306175        5632  48 Unknown
/dev/block/mmcblk0p9          311296      324271        6488  50 Unknown
/dev/block/mmcblk0p10         327680      333823        3072  4a Unknown
/dev/block/mmcblk0p11         335872      342015        3072  4b Unknown
/dev/block/mmcblk0p12         344064      360447        8192  90 Unknown
/dev/block/mmcblk0p13         360448      375807        7680  91 Unknown
/dev/block/mmcblk0p14         376832      387071        5120  92 Unknown
/dev/block/mmcblk0p15         393216     1488895      547840  93 Unknown
/dev/block/mmcblk0p16        1490944     1613823       61440  94 Unknown
/dev/block/mmcblk0p17        1613824     3887103     1136640  95 Unknown
/dev/block/mmcblk0p18        3891200     3993599       51200  96 Unknown
/dev/block/mmcblk0p19        3997696     3998695         500  97 Unknown
/dev/block/mmcblk0p20        4005888     4013079        3596  98 Unknown
/dev/block/mmcblk0p21        4014080     4024319        5120  99 Unknown
/dev/block/mmcblk0p22        4030464     4070463       20000  9a Unknown
/dev/block/mmcblk0p23        4071424     4081663        5120  9b Unknown
/dev/block/mmcblk0p24        4087808     4101807        7000  9c Unknown
/dev/block/mmcblk0p25        4104192     4114431        5120  9d Unknown
/dev/block/mmcblk0p26        4120576     4130815        5120  9e Unknown
/dev/block/mmcblk0p27        4136960     4147199        5120  9f BSD/OS
/dev/block/mmcblk0p28        4153344     7733247     1789952  a0 Thinkpad hibernation

Partition type codes there are even dangerously wrong, because /dev/block/mmcblk0p1, which is declared Win95 FAT32 (LBA), actually contains some system data (including locations and MD5 hashes of various ROM parts); however, /dev/block/mmcblk0p28, which is the FAT16-formatted “internal data storage”, has a type which looks completely bogus. In this case the manufacturer did not reuse the 0x82 (Linux swap) type code for their own purposes, but I'm not sure that such collisions never occur, so you should not blindly try to use any partition which looks like swap — first check that the device size and partition layout are what you expect to see on your SD card.

/proc/mtd is never useful for finding a swap partition on SD card (MTD drivers are used to access directly attached raw flash chips, they cannot work with external SD cards).

share|improve this answer
    
Aha! fdisk -l /dev/block/mmcblk1 says /dev/block/mmcblk1p2 30637 31152 132096 82 Linux swap –  endolith Oct 10 '13 at 13:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.