[G Tablet Q&A, Help & Troubleshooting] rajeevvp:
Guide to swap internal and external SD card assignments on the ViewSonic gTablet for users with partly-functional/non-functional internal SD cards.

The 4 steps need only be done once--as an initial setup procedure. If you flash a new ROM, or you reinstall a ROM, just do only step 4.

1. Flash either the custom version of ClockworkMod Recovery (for CWM-v2.5.x on 1.1 bootloaders) or the CWM recovery.fstab patcher (for CWM-v3.x or -v4.x on either bootloaders)

To copy the custom-CWM-*.zip attachments to the gTablet, remove any external SD card, boot into CWM and then select "mounts and storage", and then select "mount /sdcard".

This will mount your partly working internal SD card so the attachment can be transferred onto it. After mounting the sdcard, on the PC type:

C:\> [B]adb push [I]filename.zip[/I] /sdcard/.[/B]

to push one of the custom CWM zip files to the tablet. Use the back soft-key, then select "install zip from sdcard" and install the zip file you copied.

If your existing version of CWM mounts the external SD card as /sdcard, then you can skip the abovementioned steps. Just copy the zip files onto the microSD card normally using a PC.

People running CWM-v2.5.1.x should flash the custom-CWM-v2.5.1.3.img-signed.zip file which contains a modified version of bekit's ClockworkMod Recovery v2.5.1.3 (from bekit.net). The original bekit CWM-v2.5.1.3, which I've been using without major problems1 since April 2011, in addition to having a few new features, also does the right thing for backups and restores: If it detects an external SD card, it uses the VFAT partition on that for backups and restores. However, the /data partition still defaults to be the EXT3 partition on the internal SD card (/dev/block/mmcblk3). Therefore, the CWM in the attachment has been changed to use /dev/block/mmcblk2p2 (on the external SD card) as its /data partition (instead of the normal /dev/block/mmcblk3p2, which is on the internal SD card). I've also changed the menu colour to a blue (from the usual green) to remind you that you are running a modified CWM.

If you're running CWM versions 3.x or 4.x, then you should flash only the custom-CWM-v3.x-v4.x-signed.zip file.

Note: This step is only needed if you want to continue taking backups and restores transparently (to the external SD instead of the internal SD) using CWM.

2. Repartition external SD card to match the internal SD card

After flashing the modified CWM, power-off the gTablet, insert an SD card into the MicroSD card slot, and boot into again Recovery Mode. Now you should be running the new CWM. The size of the SD card, strictly speaking, doesn't matter that much, and you can get by with a smaller capacity one, but, the instructions that follow assume that you have one that is at least 16 GB in size--to match size of the internal SD card.

Once back in CWM, select "advanced", then choose "Partition SD Card". Select 2048 as the size of the ext partition and 0 as the size of swap. The rest will be formatted as VFAT for use as /mnt/sdcard. This step will take some time to complete, depending on the size of your SD card. After this step, the external SD card will have 2 partitions on it--the 1st a VFAT partition (/mnt/sdcard) and the other an EXT3 partition (/data). This setting matches the arrangement on the internal SD card.

Note: You can skip this step if you already have partitioned the SD card as required elsewhere, and wish to keep the data on the VFAT partition (the EXT3 partition, however, has to be empty). You can use something like a Parted Magic live disc to create or resize partitions while preserving existing data.

3. Copy the contents of the internal SD card onto the external SD card

You'll have to copy the contents of both the old /mnt/sdcard and old /data if you want to preserve all of your data. Attach the USB cable to the gTab and run "adb shell". Then type:

~ # [B]mkdir -p /mnt/src /mnt/dest[/B] [I]Make source and destination mount points[/I]
~ # [B]umount /dev/block/mmcblk3p1 /dev/block/mmcblk2p1[/B] [I]Start with a clean slate[/I]
~ #
~ # [B]mount /dev/block/mmcblk3p1 /mnt/src[/B] [I]Mount old /mnt/sdcard partition[/I]
~ # [B]mount /dev/block/mmcblk2p1 /mnt/dest[/B] [I]Mount new /mnt/sdcard partition[/I]
~ # [B]df[/B] [I]Check how much space is free/used on both[/I]
Filesystem 1K-blocks Used Available Use% Mounted on
tmpfs 224192 0 224192 0% /dev
/dev/block/mtdblock4 222464 1224 221240 1% /cache
/dev/block/mmcblk3p1 13707288 1752680 11954608 13% /mnt/src
/dev/block/mmcblk2p1 1702708 4 1702704 0% /mnt/dest
~ # [B]tar -cf - . -C /mnt/src | tar -xvf - -C /mnt/dest[/B] [I]Copy /mnt/sdcard contents[/I]
[I]See note [B]2[/B] below[/I]

[I]List of files copied is printed[/I]

~ # [B]umount /mnt/src /mnt/dest[/B]
~ #
~ # [B]mount /dev/block/mmcblk3p2 /mnt/src[/B] [I]Mount old /data partition[/I]
~ # [B]mount /dev/block/mmcblk2p2 /mnt/dest[/B] [I]Mount new /data partition[/I]
~ # [B]df[/B] [I]Check how much space is free/used on both[/I]
Filesystem 1K-blocks Used Available Use% Mounted on
tmpfs 224192 0 224192 0% /dev
/dev/block/mtdblock4 222464 1240 221224 1% /cache
/dev/block/mmcblk3p2 1873950 93202 1680761 5% /mnt/src
/dev/block/mmcblk2p2 234082 4 234078 0% /mnt/dest
~ # [B]tar -cf - . -C /mnt/src | tar -xvf - -C /mnt/dest[/B] [I]Copy /data contents[/I]

[I]List of files copied flies by[/I]

~ # [B]umount /mnt/src /mnt/dest[/B]
~ #

[I]Now we check both filesystems for errors.[/I]

~ # [B]mount -r /system[/B]
~ # [B]/system/bin/fsck_msdos -f -y /dev/block/mmcblk2p1[/B] [I]Check the /mnt/sdcard partition[/I]
** /dev/block/mmcblk2p1
** Phase 1 - Read and Compare FATs
Attempting to allocate 933 KB for FAT
Attempting to allocate 933 KB for FAT
** Phase 2 - Check Cluster Chains
** Phase 3 - Checking Directories
** Phase 4 - Checking for Lost Files
98 files, 835632 free (208908 clusters)
~ # [B]/system/bin/e2fsck -f -y /dev/block/mmcblk2p2[/B] [I] Check the /data partition[/I]
e2fsck 1.41.10 (10-Feb-2009)
/dev/block/mmcblk2p2: recovering journal
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

/dev/block/mmcblk2p2: ***** FILE SYSTEM WAS MODIFIED *****
/dev/block/mmcblk2p2: 680/499872 files (12.4% non-contiguous), 673082/999972 blocks
~ # [B]umount /system[/B]
~ #

Note: You can skip this data copying step if you wish your existing ROM to start with a clean slate--like a fresh install, or, if you cannot read data from the internal SD card.

4. Patch the /init*.rc and /system/etc/vold.fstab files to swap SD card assignments on the currently installed ROM

Just flash the attached swap-sdcard-assignments-signed.zip file once. You'll have to repeat this step in case you switch ROMs. The current swap-sdcard-assignments-signed.zip file works on Beasty/Clemsyn, VEGAn-TAB 5.1.1, CM 7.x and GtabComb[Over] b-3.x. If you want to install a different ROM, send me a PM and I'll see if the scripts can be used with it: some ROMs have ancillary scripts which need to be fixed and/or have non-standard SD card assignments.

1. All the CWM 2.5.1.x versions that I've looked at don't properly format (erase) partitions on the NAND flash. Instead of erasing the flash partition, they instead, mount the chosen partition and then run a rm -rf command to get rid of everything. This rm command can fail on corrupted YAFFS2 filesystems. As an example, I've seen the /cache partition contain no-name directories which loop back to themselves--causing CWM to hang when an erase or a backup is attempted. CWM versions 3.x and 4.x, from looking at the source code, seem to do the right thing. On CWM x2.5.1.x, use the erase_image <partition-name> command to wipe NAND partitions after using cat /proc/mtd to get partition names.

2. If you want to omit certain files/dirs from the tar copy process, either delete those from the source or create an exclude file with the names of the files/directories you wish to exclude. This exclude file is a plain text file containing the full paths (minus the leading /), one on each line, of all files/dirs to be excluded by the first tar command in the pipeline. For instance to skip the "clockworkmod" and "home/rvp" directories on the old /mnt/sdcard partition, I would create an "exclude.txt" file using either cat, below, or, on the PC using an editor which can save text files in Unix format, then "adb push" the file onto the gTablet, and pass the "-X filename" parameter to tar:

~ # [B]cat > exclude.txt
clockworkmod
home/rvp[/B]
[I]CTRL-D[/I]
~ # [B]tar -cf - . -X exclude.txt -C /mnt/src | tar -xvf - -C /mnt/dest[/B] [I]Copy /mnt/sdcard contents[/I]
~ #