1

I´m trying to expand an SD that´s running on a Raspberry Pi. The original SD was 8Gb. I saved it to PC with Win32DiskImager, then wrote a new 32Gb SD from that image, and run the file expand option in raspi-config. The total size is still in the 8Gb area.

This is the SSH output after running raspi-config:

Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): Disk /dev/mmcblk0: 28.9 GiB, 31016878080 bytes, 60579840 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
Disklabel type: dos
Disk identifier: 0x9a7af20d

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1        8192   532479   524288  256M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      532480 60579839 60047360 28.6G 83 Linux

Command (m for help): Partition number (1,2, default 2):
Partition 2 has been deleted.

Command (m for help): Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): Partition number (2-4, default 2): First sector (2048-60579839, default 2048): Last sector, +/-sectors or +/-size{K,M,G,T,P} (532480-60579839, default 60579839):
Created a new partition 2 of type 'Linux' and of size 28.6 GiB.
Partition #2 contains a ext4 signature.

Command (m for help):
Disk /dev/mmcblk0: 28.9 GiB, 31016878080 bytes, 60579840 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
Disklabel type: dos
Disk identifier: 0x9a7af20d

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1        8192   532479   524288  256M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      532480 60579839 60047360 28.6G 83 Linux

Command (m for help): The partition table has been altered.
Syncing disks.

My df -h looks like this (I have a 1.5Gb RAM disk):

Filesystem      Size  Used Avail Use% Mounted on
/dev/root       6.8G  4.5G  2.0G  69% /
devtmpfs        779M     0  779M   0% /dev
tmpfs           908M     0  908M   0% /dev/shm
tmpfs           908M  8.6M  900M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           908M     0  908M   0% /sys/fs/cgroup
tmpfs           1.5G  8.0K  1.5G   1% /home/x1/dh2sg/fsram
/dev/mmcblk0p1  253M   54M  199M  22% /boot
tmpfs           182M     0  182M   0% /run/user/1001

I have tried:

# cd /boot # sudo resize2fs /dev/mmcblk0p2

which gives me:

resize2fs 1.44.5 (15-Dec-2018)
Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
resize2fs: Permission denied to resize filesystem

so I-ve tried:

# sudo umount -l /dev/mmcblk0p2

# resize2fs /dev/mmcblk0p2

which returns:

resize2fs 1.44.5 (15-Dec-2018)
ext2fs_check_mount_point: Can't check if filesystem is mounted due to missing mtab file while determining whether /dev/mmcblk0p2 is mounted.

As far as I can see, mtab is there:

$ ls -lrt /etc/mtab
lrwxrwxrwx 1 root root 19 Aug 20  2020 /etc/mtab -> ../proc/self/mounts

$ ls -lrt /proc/mounts
lrwxrwxrwx 1 root root 11 Oct 16 19:21 /proc/mounts -> self/mounts

and this the full contents of /etc/mtab:

/dev/root / ext4 rw,noatime 0 0
devtmpfs /dev devtmpfs rw,relatime,size=797592k,nr_inodes=103885,mode=755 0 0
sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
proc /proc proc rw,relatime 0 0
securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime 0 0
tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
tmpfs /run tmpfs rw,nosuid,nodev,mode=755 0 0
tmpfs /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k 0 0
tmpfs /sys/fs/cgroup tmpfs ro,nosuid,nodev,noexec,mode=755 0 0
cgroup2 /sys/fs/cgroup/unified cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate 0 0
cgroup /sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noexec,relatime,xattr,name=systemd 0 0
none /sys/fs/bpf bpf rw,nosuid,nodev,noexec,relatime,mode=700 0 0
cgroup /sys/fs/cgroup/cpu,cpuacct cgroup rw,nosuid,nodev,noexec,relatime,cpu,cpuacct 0 0
cgroup /sys/fs/cgroup/pids cgroup rw,nosuid,nodev,noexec,relatime,pids 0 0
cgroup /sys/fs/cgroup/net_cls cgroup rw,nosuid,nodev,noexec,relatime,net_cls 0 0
cgroup /sys/fs/cgroup/freezer cgroup rw,nosuid,nodev,noexec,relatime,freezer 0 0
cgroup /sys/fs/cgroup/blkio cgroup rw,nosuid,nodev,noexec,relatime,blkio 0 0
cgroup /sys/fs/cgroup/devices cgroup rw,nosuid,nodev,noexec,relatime,devices 0 0
cgroup /sys/fs/cgroup/cpuset cgroup rw,nosuid,nodev,noexec,relatime,cpuset 0 0
systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=31,pgrp=1,timeout=0,minproto=5,maxproto=5,direct 0 0
sunrpc /run/rpc_pipefs rpc_pipefs rw,relatime 0 0
mqueue /dev/mqueue mqueue rw,relatime 0 0
debugfs /sys/kernel/debug debugfs rw,relatime 0 0
configfs /sys/kernel/config configfs rw,relatime 0 0
tmpfs /home/x1/dh2sg/fsram tmpfs rw,nosuid,nodev,relatime,size=1536000k 0 0
/dev/mmcblk0p1 /boot vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro 0 0
tmpfs /run/user/1001 tmpfs rw,nosuid,nodev,relatime,size=185936k,mode=700,uid=1001,gid=1001 0 0
gvfsd-fuse /run/user/1001/gvfs fuse.gvfsd-fuse rw,nosuid,nodev,relatime,user_id=1001,group_id=1001 0 0
fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0

Any ideas on what could be wrong?

5
  • Did you reboot? Although no one can say if you use Win32DiskImager; try using a supported method.
    – Milliways
    Oct 17 '21 at 6:26
  • @Milliways -- yes, rebooted many times. What would be a supported method? My case is that I started working with an 8Gb SD card, and then moved to a 32Gb card. As the 8Gb card has a lot of fine tuning, my approach was to do an image file of the 8Gb card and then write that image to the 32Gb card (and of course use 100% of the 32Gb space). How would you do that? Thanks!
    – PiBer2
    Oct 17 '21 at 12:02
  • 1
    Have you tried running raspi-config then select Advanced Options - first choice should be Expand Filesystem
    – Bravo
    Oct 17 '21 at 22:16
  • @Bravo: yes, as said in the question, that´s the first thing I´ve done. Thanks!
    – PiBer2
    Oct 18 '21 at 13:13
  • oh, sorry, I missed that @PiBer2
    – Bravo
    Oct 18 '21 at 21:45
1

I see the partition is already resized, all you have to do is to run resize2fs /dev/mmcblk0p2 as root. This should be done on a mounted partition, unmounting / on a running system is a sure way to crash it.

If resize2fs fails to grow the partition even as root, it's typically because you have errors on it which need to be fixed with fsck. If this is the case, running dmesg after a failed resize2fs attempt will output something like:

kernel: EXT4-fs warning: There are errors in the filesystem, so online resizing is not allowed

It's possible that umount -l / caused the inconsistencies in the first place.

Note that it's actually possible to unmount the / on a running system if you really have to (e.g. you need to shrink it instead of growing), but it's somewhat more complicated than just umount -l /: you need to stop most system services, create a new minimal root file system on tmpfs and switch to it using pivot_root.

1
  • Thanks Dmitry... Yes, I have that output from dmesg. I guess I will have to begin from scratch with a new SD!
    – PiBer2
    Oct 18 '21 at 20:36
0

There are literally dozens of approaches; the most conventional is using dd although probably not for Windows.

SD Card Copier copies on the Pi itself and automatically adjusts size.

Various options are discussed.

The procedure I use (which is fast and efficient) Backup image of SD Card makes a small installable image, but takes more setup. (I use this to make regular backups.)

can-a-raspberry-pi-be-used-to-create-a-backup-of-itself looks at other options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.