Android - How to find the pathname of the swap partition on SD card?
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:
Swapper 2 is configured to use /dev/block/mmcblk0p3
by default, so I'm glad I didn't go with the default.
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).