Upgrade an Android phone's memory card with Linux
This guide shows you how to change the memory card in your Android smart phone from an existing memory card that it has, to a new and presumably bigger one that you have bought, while keeping all data intact.
To follow this guide you need a Linux computer and you will need a card reader, either built in to your computer or a separate card reader connected to the computer with a USB cable. I used a separate card reader. I used this guide How to change memory card on an Android-phone, as a starting point. Read on for instructions.
Ok, here we go:
Switch off your phone. Open it and take out the old memory card. We are going to make a copy of the memory card and store on the computer.
Put the old memory card into the reader and connect the USB reader to your Linux computer.
Type dmesg to find out what the memory card and reader got registered as. dmesg helps you see what has happened recently on your computer.
Towards the end the dmesg command should output that it detected the card reader and the memory card in the reader. On my computer it looked like this, where I have boldfaced the important info:
[81490.560044] usb 2-3: new high speed USB device using ehci_hcd and address 3
[81490.891778] Initializing USB Mass Storage driver...
[81490.891910] scsi6 : usb-storage 2-3:1.0
[81490.892307] usbcore: registered new interface driver usb-storage
[81490.892309] USB Mass Storage support registered.
[81491.905633] scsi 6:0:0:0: Direct-Access Kingston FCR-HS219/1 9745 PQ: 0 ANSI: 0
[81492.062070] scsi 6:0:0:1: Direct-Access Kingston FCR-HS219/1 9745 PQ: 0 ANSI: 0
[81492.063305] scsi 6:0:0:2: Direct-Access Kingston FCR-HS219/1 9745 PQ: 0 ANSI: 0
[81492.064426] scsi 6:0:0:3: Direct-Access Kingston FCR-HS219/1 9745 PQ: 0 ANSI: 0
[81492.064841] sd 6:0:0:0: Attached scsi generic sg2 type 0
[81492.064980] sd 6:0:0:1: Attached scsi generic sg3 type 0
[81492.065114] sd 6:0:0:2: Attached scsi generic sg4 type 0
[81492.065256] sd 6:0:0:3: Attached scsi generic sg5 type 0
[81492.108160] sd 6:0:0:0: [sdb] Attached SCSI removable disk
[81492.113897] sd 6:0:0:1: [sdc] Attached SCSI removable disk
[81492.116937] sd 6:0:0:2: [sdd] Attached SCSI removable disk
[81492.118378] sd 6:0:0:3: [sde] 3862528 512-byte logical blocks: (1.97 GB/1.84 GiB)
[81492.119505] sd 6:0:0:3: [sde] Write Protect is off
[81492.119509] sd 6:0:0:3: [sde] Mode Sense: 03 00 00 00
[81492.119512] sd 6:0:0:3: [sde] Assuming drive cache: write through
[81492.124881] sd 6:0:0:3: [sde] Assuming drive cache: write through
[81492.124890] sde: sde1
[81492.140247] sd 6:0:0:3: [sde] Assuming drive cache: write through
[81492.140252] sd 6:0:0:3: [sde] Attached SCSI removable disk
So it seems that the memory card is reachable under /dev/sde then in my case. The sdb,sdc, and sdd messages are spurious in this context; no drives get attached at those addresses.
On your computer the name for the memory card may come out different than sde: It could be "sdc", "sdd" or "mmcblk0" for example. Just addd "/dev/" in front to make "/dev/sdc", "/dev/sdd" or "/dev/mmcblk0" in that case, and use that name for the duration of this guide, instead of "/dev/sde".
Time to backup the entire card with whatever partitions are on it, to the computer.
Make a directory on your hard disk where you can store an image of your old memory card. Change "your_user_name" below to your user name on the computer.
mkdir /home/your_user_name/phonecard-backup
You may need to be root ar at least do sudo for all commands below
Image the entire card to a file there
sudo dd bs=200M if=/dev/sde of=/home/your_user_name/phonecard-backup/sde.dd conv=notrunc,noerror
Eject old card from the card reader and put in the new card, switching "if" and "of" in the above command so the image travels back to the card:
sudo dd bs=200M of=/dev/sde if=/home/your_user_name/phonecard-backup/sde.dd conv=notrunc,noerror
You now have a fuctioning new memory card, Unfortunately no bigger than the old one because dd has made an exact copy of the old card.
Time to stretch the new card to its full size: Start parted. The commands you should type are bolded and highlighted in red below.
sudo parted
GNU Parted 2.3
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print devices
/dev/sda (250GB)
/dev/sde (15.9GB)
/dev/mmcblk0 (7948MB)
Here note the full size of /dev/sde, in my case 15.9GB, Continue:
(parted) select /dev/sde
Using /dev/sde
(parted) print
Model: Kingston FCR-HS219/1 (scsi)
Disk /dev/sde: 15.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 69.1kB 1976MB 1976MB primary fat16
Above we can see that dd has made the new card just as small as the old one, which makes sense since dd did a byte by byte copy. The old card only had one partition, that is why "print" only lists one partition on my new card, partition number 1. Time to make that partition bigger:
(parted) resize
WARNING: you are attempting to use parted to operate on (resize) a file
system.
parted's file system manipulation code is not as robust as what you'll
find in
dedicated, file-system-specific packages like e2fsprogs. We recommend
you use parted only to manipulate partition tables, whenever possible.
Support for performing most operations on most types of file systems
will be removed in an upcoming release.
Partition number? 1
Error: Partition /dev/sde1 is being used. You must unmount it before
you modify it with Parted.
Error! Ah, Linux mounted the card when it was inserted. And parted can't resize a mounted volume. Open another terminal window or tab on your computer, and type:
sudo umount /dev/sde1
Switch back to the terminal with parted. As end size use the size you noted before for the new card:
(parted) resize
WARNING: you are attempting to use parted to operate on (resize) a file
system.
parted's file system manipulation code is not as robust as what you'll
find in
dedicated, file-system-specific packages like e2fsprogs. We recommend
you use parted only to manipulate partition tables, whenever possible.
Support for performing most operations on most types of file systems
will be removed in an upcoming release.
Partition number? 1
Start? [69.1kB]?
End? [1976MB]? 15.9GB
Warning: The file system can only be resized to this size by converting
to FAT32. If you convert to FAT32, and MS Windows is installed on this
partition, then you
must re-install the MS Windows boot loader. If you want to do this,
you should consult the Parted manual (or your distribution's manual).
Also, converting to
FAT32 will make the file system unreadable by MS DOS, MS Windows 95a,
and MS Windows NT.
OK/Cancel? OK
(parted) quit
And that should be it. Insert the new memory card into your Android smart phone and boot it up.