Resizing SD card via command line

This forum is for topics specific to the Raspberry Pi and Arch Linux ARM

Re: Resizing SD card via command line

Postby lumpynose » Fri Mar 22, 2013 4:51 am

Re-imaged my sd card (I'm doing this on a Raspberry Pi) and tried the above; the second part, the resizing with resize2fs fails because the filesystem is mounted read only and it complains about that. The man page for resize2fs says
$this->bbcode_second_pass_quote('', '
')If the filesystem is mounted, it can be used to expand the size of the mounted filesystem, assuming the kernel supports on-line resizing. (As of this writing, the Linux 2.6 kernel supports on-line resize for filesystems mounted using ext3 and ext4).

Question: (I'm a bit of an old fart and used to administer SunOS and Solaris systems; I don't have a lot of Linux experience so my terminology may not be correct.) Would it be possible to specify the character device for the disk instead of the block device? My experience is that programs that complain about systems being mounted (or not) may work with the character device if the block device had been specified.
lumpynose
 
Posts: 22
Joined: Fri Mar 22, 2013 3:01 am

Re: Resizing SD card via command line

Postby pepedog » Fri Mar 22, 2013 9:53 am

I was dubious this could be done on a mounted system, but it works.
There may be complaints that e2fsck has to be run before or after resize, that works too
pepedog
Developer
 
Posts: 2431
Joined: Mon Jun 07, 2010 3:30 pm
Location: London UK

Re: Resizing SD card via command line

Postby lumpynose » Sat Mar 23, 2013 7:05 pm

Here are my latest notes to myself. I've added some reboots and going to single user mode because I'm paranoid:

Before running fdisk I brought the system down to single user and remounted the root partition read-only. In the following the # is root’s prompt.

# systemctl rescue
# mount -o ro,remount /
# fdisk /dev/mmcblk0

Delete the second partition /dev/mmcblk0p2.

d
2

Create a new primary partition and use default sizes prompted. This will then create a partiton that fills the disk.

n
p
2
enter
enter

Save and exit fdisk:

w

Reboot and run resize2fs:

# shutdown -r now
# systemctl rescue
# resize2fs /dev/mmcblk0p2

Your main / partition should be the full size of the disk now. Don’t remount the root partition read-only before you run resize2fs; resize2fs fails if it’s mounted read-only.

After running resize2fs reboot, go to single user, remount root read-only, and run e2fsck:

# shutdown -r now
# systemctl rescue
# mount -o ro,remount /
# e2fsck /dev/mmcblk0p2
# shutdown -r now
lumpynose
 
Posts: 22
Joined: Fri Mar 22, 2013 3:01 am

Re: Resizing SD card via command line

Postby pepedog » Sat Mar 23, 2013 7:42 pm

One step I would encourage is before # shutdown -r now, or reboot or poweroff, use sync command
pepedog
Developer
 
Posts: 2431
Joined: Mon Jun 07, 2010 3:30 pm
Location: London UK

Re: Resizing SD card via command line

Postby lumpynose » Sat Mar 23, 2013 7:50 pm

$this->bbcode_second_pass_quote('pepedog', 'O')ne step I would encourage is before # shutdown -r now, or reboot or poweroff, use sync command


Very true. That's why I used shutdown; it does the sync for you.

Edit: or at least shutdown called sync on the systems I'm familiar with, which was bsd, sunos, and solaris.
lumpynose
 
Posts: 22
Joined: Fri Mar 22, 2013 3:01 am

Re: Resizing SD card via command line

Postby lumpynose » Sun Mar 24, 2013 4:56 am

$this->bbcode_second_pass_quote('lumpynose', '')$this->bbcode_second_pass_quote('pepedog', 'O')ne step I would encourage is before # shutdown -r now, or reboot or poweroff, use sync command


Very true. That's why I used shutdown; it does the sync for you.

Edit: or at least shutdown called sync on the systems I'm familiar with, which was bsd, sunos, and solaris.
/sbin/shutdown is a sym link to /usr/bin/systemctl. I'm guessing that systemctl looks at how it was invoked and when it's invoked as reboot it runs its reboot command. My interpretation is that it effectively does a sync before it reboots. The man page for systemctl doesn't say what happens when it's invoked as reboot. For the reboot command to systemctl the man page for systemctl says
$this->bbcode_second_pass_quote('', '
')Shut down and reboot the system. This is mostly equivalent to start reboot.target but also prints a wall message to all users. If combined with --force shutdown of all running services is skipped, however all processes are killed and all file systems are unmounted or mounted read-only, immediately followed by the reboot. If --force is specified twice the operation is immediately executed without terminating any processes or unmounting any file systems. This may result in data loss.
I suppose it's possible that systemctl uses --force twice in order to not do the read-only remounting but I would think that very unlikely.
lumpynose
 
Posts: 22
Joined: Fri Mar 22, 2013 3:01 am
Top

Re: Resizing SD card via command line

Postby pepedog » Sun Mar 24, 2013 12:37 pm

Which of all those options, including poweroff, turns off most LEDs?
I think sync is flaky with all shutdown methods (all distro), especially where fat is concerned.
Might seem paranoid but I have seen instructions for untarring rootfs and it ends with
$this->bbcode_second_pass_code('', 'sync
sync
sync
sleep 3
halt')
So you make up your mind on that
I have had a pi for 16 months, never had corruption, and always synced. Search posts in Raspberry Pi forum and see how many point to sync as "Solved" soloution
pepedog
Developer
 
Posts: 2431
Joined: Mon Jun 07, 2010 3:30 pm
Location: London UK

Re: Resizing SD card via command line

Postby lumpynose » Mon Mar 25, 2013 2:16 am

It actually depends on the phase of the moon, and sometimes the date. When the moon is waxing you only need 2 syncs. When it's waning you need the 3 syncs. On February 29th you need another sync after the sleep.
lumpynose
 
Posts: 22
Joined: Fri Mar 22, 2013 3:01 am

Re: Resizing SD card via command line

Postby jawbonegroove » Mon Jul 01, 2013 6:06 pm

excellent post. can we get this sticky'd...?
jawbonegroove
 
Posts: 6
Joined: Sat Jun 29, 2013 2:50 am

Re: Resizing SD card via command line

Postby paranoidandroid » Thu Aug 01, 2013 1:56 pm

I have tried this on the latest release (archlinux-hf-2013-07-22.img) and the geometry has changed, the disk now has an extended partition with a logical one inside that…

fdisk reports (after imaging onto 8GB card)
$this->bbcode_second_pass_code('', ' Device Boot Start End Blocks Id System
/dev/mmcblk0p1 2048 186367 92160 c W95 FAT32 (LBA)
/dev/mmcblk0p2 186368 3667967 1740800 5 Extended
/dev/mmcblk0p5 188416 3667967 1739776 83 Linux
')

It looks like both the extended & logical partitions need to be deleted (p2 and p5)

Something like…
$this->bbcode_second_pass_code('', '
fdisk "/dev/mmcblk0"
p
d
2
n
e
(return) # accept default partition no
(return) # accept default start
(return) # accept default end
n
l
(return) # accept default start
(return) # accept default end
p
w

sync; reboot
...
resize2fs /dev/mmcblk0p5
fsck etc
')

I get the following geometry from fdisk…
$this->bbcode_second_pass_code('', '
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 2048 186367 92160 c W95 FAT32 (LBA)
/dev/mmcblk0p2 186368 15652863 7733248 5 Extended
/dev/mmcblk0p5 188416 15652863 7732224 83 Linux
')


I tried only deleting the last partition but it is limited by the size of the enclosing extended partition, so you can't expand the partition until the extended one is also expanded.

Thanks for all the tips so far, this is handy - hope this helps too :)
paranoidandroid
 
Posts: 1
Joined: Thu Aug 01, 2013 1:26 pm

PreviousNext

Return to Raspberry Pi

Who is online

Users browsing this forum: No registered users and 13 guests