Please note that User Registration has been temporarily disabled due to a recent increase in automated registrations. If anyone needs an account, please request one here: RequestAccount. Thanks for your patience!--Wmat (talk)
Please email User:Wmat if you experience any issues with the Request Account form.

Difference between revisions of "RPi Resize Flash Partitions"

From eLinux.org
Jump to: navigation, search
(Created page with "Category:raspberryPi")
 
Line 1: Line 1:
[[Category:raspberryPi]]
+
[[Category:RaspberryPi]]
 +
 
 +
==Manually resizing the SD card on Linux==
 +
 
 +
Tutorial video here: http://www.youtube.com/watch?v=R4VovMDnsIE
 +
 
 +
Following on from the instructions above, keep the newly-written SD card in the card reader, but unmounted. We'll use the <code>parted</code> (partition editor) tool to resize the partitions.
 +
* Use parted to examine the card
 +
$ sudo parted /dev/sdd
 +
(parted) unit chs
 +
(parted) print
 +
Disk /dev/sdd: 121535,3,31
 +
Sector size (logical/physical): 512B/512B
 +
BIOS cylinder,head,sector geometry: 121536,4,32.  Each cylinder is 65.5kB.
 +
Partition Table: msdos
 +
 +
Number  Start      End        Type    File system    Flags
 +
  1      16,0,0    1215,3,31  primary  fat32          lba
 +
  2      1232,0,0  26671,3,31  primary  ext4
 +
  3      26688,0,0  29743,3,31  primary  linux-swap(v1)
 +
: This shows how my SD card was formatted after writing the image. Notice that nothing uses the card from end of 'cylinder' 29743 to the card's maximum at 121535.
 +
: Partition 1 is the boot partition: we'll leave that alone. Partition 2 is the root partition, which we'll grow to fill most of the card. Partition 3 is the swap space, which needs to be moved to the end of the card. Note that on some other versions of linux (and some other versions of hardware) use /sde not /sdd.
 +
* Move the swap partition (you'll have to adjust the numbers so that the end of partition 3 is at the end cylinder/head/sector of the card)
 +
* to calculate the number to use in the following command do:- <code>(Maximum - (Partation 3 End - Partation 3 Start) ) - 1 = Partition 3 New Start</code>  so in this example  <code>(121535 - ( 29743 - 26688)) -1 = 118479 </code>
 +
(parted) move 3 118479,0,0
 +
* Now grow the root partition. This involves removing the partition, re-creating it, then using <code>resize2fs</code> to grow the filesystem to fill the partition. It won't destroy any data.
 +
(parted) rm 2
 +
(parted) mkpart primary 1232,0,0 118478,3,31
 +
(parted) quit
 +
: Note that the starting address of the new partition is identical to its original value, and the ending address is immediately before the start of the swap partition.
 +
* Now clean and resize the root partition. As before, some users may need to use /sde2 instead.
 +
$ sudo e2fsck -f /dev/sdd2
 +
: (allow it to add lost-and-found)
 +
$ sudo resize2fs /dev/sdd2
 +
* Then put the card in the RPi and boot. You end up with a 7Gb partition to use.
 +
pi@raspberrypi:~$ df -h
 +
Filesystem            Size  Used Avail Use% Mounted on
 +
tmpfs                  94M  4.0K  94M  1% /lib/init/rw
 +
udev                  10M  168K  9.9M  2% /dev
 +
tmpfs                  94M    0  94M  0% /dev/shm
 +
rootfs                7.1G  1.3G  5.4G  20% /
 +
/dev/mmcblk0p1        75M  28M  48M  37% /boot
 +
 
 +
==Manually resizing the SD card on Raspberry Pi==
 +
 
 +
You can also resize the partitions of the SD card that your Pi is running on.
 +
 
 +
First you need to change the partition table with fdisk. You need to remove the existing partition entries and then create a single new partition than takes the whole free space of the disk. This will only change the partition table, not the partitions data on disk. '''The start of the new partition needs to be aligned with the old partition!'''
 +
 
 +
Start fdisk:
 +
 
 +
sudo fdisk -cu /dev/mmcblk0
 +
 
 +
Then delete partitions with ''d'' and create a new with ''n''. You can view the existing table with ''p''.
 +
 
 +
* ''p'' to see the current start of the main partition
 +
* ''d'', ''3'' to delete the swap partition
 +
* ''d'', ''2'' to delete the main partition
 +
* ''n'' ''p'' ''2'' to create a new primary partition, next you need to enter the start of the old main partition and then the size (''enter'' for complete SD card). The main partition on the Debian image from 2012-04-19 starts at 157696, but the start of your partition might be different. Check the ''p'' output!
 +
* ''w'' write the new partition table
 +
 
 +
Now you need to reboot:
 +
 
 +
  sudo shutdown -r now
 +
 
 +
After the reboot you need to resize the actual partition. The <code>resize2fs</code> will resize your main partition to the new size from the changed partition table.
 +
 
 +
sudo resize2fs /dev/mmcblk0p2
 +
 
 +
This will take a few minutes, depending on the size and  speed of your SD card.
 +
 
 +
When it is done, you can check the new size with:
 +
 
 +
df -h

Revision as of 18:26, 18 June 2012


Manually resizing the SD card on Linux

Tutorial video here: http://www.youtube.com/watch?v=R4VovMDnsIE

Following on from the instructions above, keep the newly-written SD card in the card reader, but unmounted. We'll use the parted (partition editor) tool to resize the partitions.

  • Use parted to examine the card
$ sudo parted /dev/sdd
(parted) unit chs
(parted) print
Disk /dev/sdd: 121535,3,31
Sector size (logical/physical): 512B/512B
BIOS cylinder,head,sector geometry: 121536,4,32.  Each cylinder is 65.5kB.
Partition Table: msdos

Number  Start      End         Type     File system     Flags
 1      16,0,0     1215,3,31   primary  fat32           lba
 2      1232,0,0   26671,3,31  primary  ext4
 3      26688,0,0  29743,3,31  primary  linux-swap(v1)
This shows how my SD card was formatted after writing the image. Notice that nothing uses the card from end of 'cylinder' 29743 to the card's maximum at 121535.
Partition 1 is the boot partition: we'll leave that alone. Partition 2 is the root partition, which we'll grow to fill most of the card. Partition 3 is the swap space, which needs to be moved to the end of the card. Note that on some other versions of linux (and some other versions of hardware) use /sde not /sdd.
  • Move the swap partition (you'll have to adjust the numbers so that the end of partition 3 is at the end cylinder/head/sector of the card)
  • to calculate the number to use in the following command do:- (Maximum - (Partation 3 End - Partation 3 Start) ) - 1 = Partition 3 New Start so in this example (121535 - ( 29743 - 26688)) -1 = 118479
(parted) move 3 118479,0,0
  • Now grow the root partition. This involves removing the partition, re-creating it, then using resize2fs to grow the filesystem to fill the partition. It won't destroy any data.
(parted) rm 2
(parted) mkpart primary 1232,0,0 118478,3,31
(parted) quit
Note that the starting address of the new partition is identical to its original value, and the ending address is immediately before the start of the swap partition.
  • Now clean and resize the root partition. As before, some users may need to use /sde2 instead.
$ sudo e2fsck -f /dev/sdd2
(allow it to add lost-and-found)
$ sudo resize2fs /dev/sdd2
  • Then put the card in the RPi and boot. You end up with a 7Gb partition to use.
pi@raspberrypi:~$ df -h
Filesystem            Size  Used Avail Use% Mounted on
tmpfs                  94M  4.0K   94M   1% /lib/init/rw
udev                   10M  168K  9.9M   2% /dev
tmpfs                  94M     0   94M   0% /dev/shm
rootfs                7.1G  1.3G  5.4G  20% /
/dev/mmcblk0p1         75M   28M   48M  37% /boot

Manually resizing the SD card on Raspberry Pi

You can also resize the partitions of the SD card that your Pi is running on.

First you need to change the partition table with fdisk. You need to remove the existing partition entries and then create a single new partition than takes the whole free space of the disk. This will only change the partition table, not the partitions data on disk. The start of the new partition needs to be aligned with the old partition!

Start fdisk:

sudo fdisk -cu /dev/mmcblk0

Then delete partitions with d and create a new with n. You can view the existing table with p.

  • p to see the current start of the main partition
  • d, 3 to delete the swap partition
  • d, 2 to delete the main partition
  • n p 2 to create a new primary partition, next you need to enter the start of the old main partition and then the size (enter for complete SD card). The main partition on the Debian image from 2012-04-19 starts at 157696, but the start of your partition might be different. Check the p output!
  • w write the new partition table

Now you need to reboot:

 sudo shutdown -r now

After the reboot you need to resize the actual partition. The resize2fs will resize your main partition to the new size from the changed partition table.

sudo resize2fs /dev/mmcblk0p2

This will take a few minutes, depending on the size and speed of your SD card.

When it is done, you can check the new size with:

df -h