I have a 16 GB micro SD card with an expanded file system (so the whole space is occupied). Inside this micro SD Card is the Raspbian OS of my Raspberry Pi and there's a lot of unused free space. I normally use Windows so I made a copy of my SDCard for back-up purposes using Win32diskimager. Then I tried to write this back-up into another 16 GB micro SD card but couldn't because the second one was a little bit smaller. So I decided I needed to slightly shrink my micro SD card partition (where there is a lot of free space) so that after saving it with Win32diskimager it could fit into the smaller 16 GB micro SD card.
For doing this I checked several solutions and found this excellent tutorial Easy Resize and Back-Up Raspberry Pi SD card with Ubuntu that I decided to follow. The only problem with the tutorial was that I have to use Ubuntu which I don't know anything about.
Nevertheless I installed WMware 12.0.0 and decided to run an Ubuntu virtual machine. The Ubuntu Image I could find was ubuntu-14.04.3-desktop-amd64 and I could also get a copy of the repository into an external hard drive (as my internet connection is extremely slow because I'm still using a dial up modem). After successfully configuring the repo to run locally and following this tutorial how to use SD card reader in VM... to allow my Ubuntu VM to see the micro SD card as a hard disk drive, when I type fdisk -l
I'm seeing that the micro SD card is recognized yet it appears as two different devices:
Disk /dev/sda: 15.7 GB, 15716057088 bytes
4 heads, 16 sectors/track, 479616 cylinders, total 30695424 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cbe05
Device Boot Start End Blocks Id System
/dev/sda1 8192 2291015 1141412 e W95 FAT16 (LBA)
/dev/sda2 2291016 30695423 14202204 5 Extended
/dev/sda5 2293760 2359293 32767 83 Linux
/dev/sda6 2359296 2488319 64512 c W95 FAT32 (LBA)
/dev/sda7 2490368 30695423 14102528 83 Linux
Disk /dev/sda1: 3898 MB, 3898605568 bytes
4 heads, 16 sectors/track, 118976 cylinders, total 7614464 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cbe05
Device Boot Start End Blocks Id System
/dev/sda1p1 8192 2291015 1141412 e W95 FAT16 (LBA)
/dev/sda1p2 2291016 30695423 14202204 5 Extended
/dev/sda1p5 2293760 2359293 32767 83 Linux
/dev/sda1p6 2359296 2488319 64512 c W95 FAT32 (LBA)
/dev/sda1p7 2490368 30695423 14102528 83 Linux
Here you can see all the partitions into which the micro SD card is divided. I haven't been able to mount any of these partitions even though I typed
sudo mount /dev/sda /media/usb -t auto
But then I analysed I didn't really needed any of these to be mounted, I only needed them to be resized, so I installed Gparted tool to do this and this is what i could see:
The fat32, fat16 and ext4 partitions appear with a red icon logo indicating some kind of problem. When I right click on information for ext4 partition it says:
e2label: No such file or directory while trying to open /dev/sda7
Couldn't find valid filesystem superblock.
tune2fs 1.42.9 (4-Feb-2014)
tune2fs: No such file or directory while trying to open /dev/sda7
Couldn't find valid filesystem superblock.
Couldn't find valid filesystem superblock.
dumpe2fs 1.42.9 (4-Feb-2014)
dumpe2fs: No such file or directory while trying to open /dev/sda7
Unable to read the contents of this file system!
Because of this some operations may be unavailable.
The cause might be a missing software package.
The following list of software packages is required for ext4 file system support: e2fsprogs v1.41+.
I checked my sdcard in Windows with chkdsk tool (as suggested in Warning image in Gparted) and no problem was found. I also checked and there are no software packages missing
I don't know what is wrong but the fact that I can't mount the device and that gparted is giving me so many errors tells me that something is wrong.
My questions are:
- Is there any other safe way to shrink the Pi SD card image without losing the data?
- Is there another proper way to load the micro SD card into the Ubuntu VM (connecting it as an USB device is not working either)?
- Why am I seeing 2 devices instead of one with
fdisk -l
? - How do I get gparted to work?