1

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:

my gparted looks

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:

  1. Is there any other safe way to shrink the Pi SD card image without losing the data?
  2. 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)?
  3. Why am I seeing 2 devices instead of one with fdisk -l?
  4. How do I get gparted to work?
2
  • 1
    One question per question please. In order to help the largest number of people we need to consider that while there may be a large number of people who want to know how to get gparted to work or how to shrink a partition the number of people who have all four of your questions as opposed to one or two of them is vanishingly small. For instance you may find your answer regarding gparted here: askubuntu.com/questions/tagged/…
    – Elder Geek
    Jul 6, 2016 at 22:15
  • @Elder I only have one goal and it is expressed in the title of my question, as long as I can solve that, it's ok. In order to achieve this I have selected a posssible solution path which I have clarified but might not be the best. While walking this path I encountered several problems and for those to which I don't have an answer I made a question. I understant that it might be hard for someone to know all the answers, but I have made other questions that have only been partially answered by individuals and yet the sum of all the partial answers from the community has yield the best results.
    – VMMF
    Jul 7, 2016 at 3:26

1 Answer 1

0

My apologies in advance to the community for the numerous links in this answer.

  1. To avoid losing data it's best practices to backup. While opinions vary widely as to the best approach I recommend imaging the device so you have a complete bit level backup of the entire device (see my answer at the link above).

  2. I can't comment on VMware as I typically use Virtualbox or Bare Metal

  3. See 2 above, that being said you might find this page useful.

  4. Over and above the numerous gparted related answers I pointed you to in my comment you might find this section of the manual useful.

Sources:

30 years Experience and Google to find the links provided.

Not the answer you're looking for? Browse other questions tagged .