5

I bought Raspberry Pi and got it up and running. I also happened to have an external HDD which I then mounted to the Raspberry Pi. The mount can be accessed in the /mnt folder.

I have SD card in the Raspberry Pi which contains the Raspbian operating system. I would like to move the root folder to the external HDD which has much more space than the SD card because all the programs which are installed via apt-get end up on the SD card and fill it up.

However, I haven't found a way to do this and at the moment I'm stuck with this problem.

3
  • It must be a small SD card (or an unusual number of programs). Add more detail. If you search this Forum you will find how to boot to a different partition. This requires some expertise with Linux.
    – Milliways
    Dec 31, 2015 at 23:02
  • The SD card is 8 gigabytes large, it is not yet full (there is still 58% space left 4,2 gigabytes) but I think that maybe in the future it might get filled up. The external HDD has 120 gigabytes so I thought that if there is a way to move the root / to the HDD in stead of the SD card that would be nice. I'll look into booting to a different partition. Thank you for the tip.
    – Hicks48
    Jan 1, 2016 at 13:43
  • here is your answer: raspberrypi.stackexchange.com/questions/757/…
    – fcm
    Jul 7, 2016 at 1:19

2 Answers 2

2

Since you have the Pi up and running, all the work can be done on the Pi itself.

  1. On a terminal type the command lsblk. The mmcblk0 is the Pi's SD and sda, sdb, ... are the other disk on the Pi. If you have sda and sdb, verify which one is the HDD that you want the root filesystem on. The command dmesg | grep sd or sudo fdisk -l /dev/sd* may be helpful. In my case it is sdb, so I will use sdb in examples.
  2. The root filesystem should be an ext4 partition. Verify with the sudo fdisk -l /dev/sdb* command. If not an ext4 partition, unmount if mounted (sudo umount /dev/sdb?) then use the sudo dfisk /dev/sdb command to make a ext4 partition. The first fdisk command is p for print, use d (and enter for defaults) to delete partitions, use n to create new partitions, select p for primary if there are only going to be less then 5 partitions. You can just press enter if only one partition is needed for the default p, partition number, first sector, and last sector. Press p again to print, if happy, press w to write, if not happy, press q to quit and try later.
  3. We have a partition, /dev/sdb1. To make a filesystem use the command sudo mkfs.ext4 -L root /dev/sdb1.
  4. Mount the filesystem, sudo mount /dev/sdb1 /mnt.
  5. Copy the root filesystem from the SD card to the new filesystem, sudo rsync -axvHAXW / /mnt/. This will copy only the root filesystem, not /boot, proc, run, or sys which are not part of the root filesystem. This will take some time, take a break. Note: Always use a / at the end of directors with the rsync command. On root / is both beginning and end.
  6. To use this as the root filesystem on the next boot, two changes have to be made. Issue the command cat /mnt/etc/fstab and the '/dev/mmcblk0p2 / ' will have to be changed to the new root filesystem. In my case we could try to change it to /dev/sdb1, but on reboot, it may be /dev/sda1 or /dev/sdb1 or /dev/sdc1. for a quick check if there are no other disk on the usb port other that /dev/sda, then you can change /dev/mmcblk0p2 to /dev/sda1. The same is true for the second change in /boot/cmdline.txt (make a backup copy of /boot/cmdline.txt). A better way, would be to use UUID and PARTUUID found with the command sudo blkid /dev/sdb*. In /mnt/etc/fstab, replace '/dev/mmcblk0p2' with '/dev/disk/by-uuid/139ca52c-d45e-44ca-8b8c-12c0af0c9cf5' (or with 'UUID=139ca52c-d45e-44ca-8b8c-12c0af0c9cf5') -- OF COURSE, use your UUID, not nime. In /boot/cmdline.txt, save a copy first and then replace 'root=/dev/mmcblk0p1' with 'root=PARTUUID=432b3940-01'.
  7. Do a reboot, sudo reboot and you should be running the root filesystem on your HHD. If there are any problem, replace your save copy of /boot/cmdline.txt on the Pi's sd card.
  8. EXAMPLES:

    pi@RPi3:~ $ lsblk
    NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
    sdb           8:16   1  29.8G  0 disk
    ├─sdb2        8:18   1  29.8G  0 part /media/pi/rpiroot2
    └─sdb1        8:17   1    63M  0 part /media/pi/boot2
    sda           8:0    0 931.5G  0 disk
    ├─sda2        8:2    0 931.4G  0 part /media/pi/rpiroot
    └─sda1        8:1    0   120M  0 part /media/pi/boot1
    mmcblk0     179:0    0  29.7G  0 disk
    ├─mmcblk0p2 179:2    0  29.7G  0 part /
    └─mmcblk0p1 179:1    0    63M  0 part /boot
    
    
    pi@RPi3:~ $ sudo fdisk /dev/sdb
    
    Welcome to fdisk (util-linux 2.25.2).
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
    
    Command (m for help): p
    Disk /dev/sdb: 29.8 GiB, 32026656768 bytes, 62552064 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: 0x432b3940
    
    Device     Boot  Start      End  Sectors  Size Id Type
    /dev/sdb1         8192   137215   129024   63M  c W95 FAT32 (LBA)
    /dev/sdb2       137216 62552063 62414848 29.8G 83 Linux
    
    
    Command (m for help): d
    Partition number (1,2, default 2):
    
    Partition 2 has been deleted.
    
    Command (m for help): d
    
    Selected partition 1
    Partition 1 has been deleted.
    
    Command (m for help): n
    Partition type
       p   primary (0 primary, 0 extended, 4 free)
       e   extended (container for logical partitions)
    Select (default p): p
    Partition number (1-4, default 1):
    First sector (2048-62552063, default 2048):
    Last sector, +sectors or +size{K,M,G,T,P} (2048-62552063, default 62552063):
    
    Created a new partition 1 of type 'Linux' and of size 29.8 GiB.
    
    Command (m for help): p
    Disk /dev/sdb: 29.8 GiB, 32026656768 bytes, 62552064 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: 0x432b3940
    
    Device     Boot Start      End  Sectors  Size Id Type
    /dev/sdb1        2048 62552063 62550016 29.8G 83 Linux
    
    
    Command (m for help): w
    
    
    pi@RPi3:~ $ sudo blkid /dev/sdb*
    /dev/sdb: PTUUID="432b3940" PTTYPE="dos"
    /dev/sdb1: UUID="139ca52c-d45e-44ca-8b8c-12c0af0c9cf5" TYPE="ext4" PARTUUID="432b3940-01"
    
0

From http://www.redrobe.com/mike/boot-raspberry-pi-from-a-16mb-sd-card/:

Hey Man, I just tested it with a 128 MB microSD & a 16 GB usb drive. It works >just great. My steps are as follows (Win 8 / 7):

– Download the latest image. – Copy the image to USB drive using Win32DiskImager – Remove the pen-drive & re-insert it. – “Boot” partition should be visible in “Computer” – Format your SD Card (MMC do not work). – Copy all the files from boot partition to your memory card. – Edit cmdline.txt in SD Card and replace content with this

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/sda2 rootfstype=ext4 elevator=deadline rootwait

Put both on RPi and you should have it running in matter of seconds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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