Tuesday, July 23, 2013

Running From an External Hard Drive

The SD card of the Raspberry Pi is required for booting.  While you may not be able to boot from an external hard drive, moving the root partition there will significantly speed up the Raspberry Pi.  There are many uses where this configuration particularly useful.  File servers and media servers are good examples.  I use a system like this for a MySQL database server.


There are a number of variations to the process, but basically, the steps are:
o  Install OS on SD Card and boot 
o  Plug in external hard drive
o  Partition and Format hard drive
o  Copy system to hard drive
o  Mount the new system and modify configuration to use the hard drive

I decided not to re-invent the wheel.  The following instructions are just my variations on the instructions provided by Rattus here: 

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=26&t=10914&p=129474&hilit=resizefs#p122476  
Note about the sudo command:  All of the following must be done as root.  You must put sudo before each of the commands.  Or, you can follow the (not recommended, bad practice) habit I have and just enter sudo bash to run a shell as root and skip saying sudo all the time.

Load SD Card with Raspbian in the usual way. Update the system software and firmware with the following three commands. This can take quite a while to complete.
apt-get update
apt-get upgrade
rpi-update
reboot


List the partitions This should show only the /boot and / partitions on the SD card.
fdisk –l

Plug external hard drive into USB and list the partitions again. This should show another HD probably at /dev/sda

Modify the partition table for the external drive.
fdisk /dev/sda
Delete partitions by entering “d” and then the number of the partition to delete. Delete all the partitions. Entering “p” will list the partitions.

At this point, you have a few options.
    a) Create a single partition and move the root there. This will leave the swap file on the SD card.
    b) Create a root partition that fills most of the drive and a small swap partition.
    c) Create a partition for the OS, a small swap partition, and a large partition for application data.

I am using the third option.  The following instructions are fairly easy to change to use one of the other options.  While still in the fdisk program, do these steps.

- Create the root partition:  I made mine 16GB.  Enter “n” to create a partition, “p” to select primary partition and then “1” to select partition number one.  Select the default start sector.  Enter +16G to specify the size.  
- Create the swap partition:  Enter “n” to create a partition, “p” to select primary partition and then “2” to select partition number two.  Select the default start sector.  Enter +2G to specify the size.  Enter “t” to set the type of a partition.  Enter “2” and then “82” to make this one a swap partition.
- Create the data partition:  Enter “n” to create a partition, “p” to select primary partition and then “3” to select partition number three.  Select the default start sector and default end sector to fill up the rest of the disk.  
- Enter “p” to list the partitions and verify things are like you expect.
- Enter “w” to write the new partition table and exit.

Create (format) the data partition with an EXTv4 file system. This command takes a few minutes to finish. There is no need to format the first partition since we are going to do a raw copy of an existing file system over it anyway.
mkfs.ext4 /dev/sda3

Initialize the swap partition
mkswap /dev/sda2

Mount the new root partition.
mount /dev/sda1 /mnt

Use rsync to clone the root partition from the sdcard to the new partition on your hard disk, Note the exclude of /mnt. This takes a while.
rsync -avz --exclude '/mnt' / /mnt

Change the mount configuration file on the new root.
vi /mnt/etc/fstab

Change the root device /dev/mmcblk0p2 to be /dev/sda1

Add /dev/sda2 as a swap partition by adding this line.
/dev/sda2 none swap sw 0 0

Finally, stop the system from using the swap file that it normally uses.
rm /mnt/etc/rc?.d/*dphys-swapfile

And delete the old swap file.
rm /mnt/var/swap

Use your editor of choice (I use vi) to modify the boot configuration to use the new root partition. First make a backup copy.
cp /boot/cmdline.txt /boot/cmdline.orig
vi /boot/cmdline.txt
Change /dev/mmcblk0p2 to be /dev/sda1

Now the system is ready to reboot. It should come up normally with the external hard drive mounted as root.
reboot

If the system fails, use another machine to copy /boot/cmdline.orig to /boot/cmdline.txt and then reboot again.
One problem that some people have run into is controllers that take too long to complete the USB discovery. This can be compensated for by adding delays in the /boot/cmdline.txt file with the bootdelay and rootdelay options.

79 comments:

  1. Thank you so much for this tutorial.
    A few comments for other noobs like me who had a little trouble:

    1. When copying the image to the hard drive, I had to choose /dev/mmcblk0p6 instead of /dev/mmcblk0p2. (I dont understand though why this is the partition listed as Linux (and not Linux "Extended")
    dd if=/dev/mmcblk0p6 of=/dev/sda1 bs=32M conv=noerror,sync

    2. Change /dev/mmcblk0p2 / to be /dev/sda1
    Not sure if this was required, but I have deleted the middle slash as well. Did not try without just to make sure I dont screw up everything:)

    3. rm /etc/rc2.d/ S02dphys-swapfile
    I had to remove the space between the last forward slash and the "S"

    Thanks a lot, this was a very nice and easy to follow tutorial:)

    ReplyDelete
    Replies
    1. Were you using a NOOBS? This might explain why you needed the mmcblk0p6

      Delete
  2. Nicely done. I would recommend one addition, and one emphasis.

    Emphasis: When you first do 'fdisk -l' and locate the usb hdd, it may be listed as /dev/sdaX, where X is a number. That refers to an existing partition on /dev/sda. When you then do 'fdisk /dev/sda' DO NOT include the number. I went down that rabbit hole and it took some time to find my way back. :-)

    Addition: While you are modifying the /dev/sda1/etc/fstab file, include a line for the data partition you created so that it too will be mounted at boot. Mine looks like:

    /dev/sda3 /mnt/data ext4 defaults 0 0

    Your mount point might differ.

    Again, thanks.

    ReplyDelete
  3. As a Linux/Raspberry newbie, I am trying to follow your tutorial. However, After copying the second partition, I get hundreds of error messages like "Inode not valid, recreate?" "Wrong size 4164617681 should be 0, resize?" "Superblock has an invalid journal, clear?"
    What does that mean, I what are the consequences of doing all of it?

    ReplyDelete
    Replies
    1. That is why the e2fsck command must be run. This should correct all those errors. Did you run this command?

      Delete
    2. I previously had this problem it is caused by copying the wrong data to the hard drive
      if you do this right you should have little or no errors.
      Try copying mmcblk0p6 or the other partition that is linux NOT linux extened you can check this by saying sudo fdisk -l

      Delete
    3. With this problem it is not only 2 or 3 like regularly it is literally HUNDREDS of errors I spent half an hour and never got through it in the end I corrupted the files and restarted after I realized what I had done.

      Delete
  4. Thanks for step by step but it's freeze when I do the partition. Please suggest me for the solution.

    ReplyDelete
    Replies
    1. Be sure you are doing the partition on the correct device. It is normally /dev/sda (not /dev/sda1 and certainly not /dev/mmcblk0. Also be sure you have enough power. You should be running the external drive from a powered USB hub.

      Delete
  5. Hi,

    I have successfully done all the steps above until resize2fs. By now, after running resize2fs to expand the partition to use 20GB I left available in a separate partition (btw I had to umount /dev/sda1 first because on first try resize2fs told it was not possibile to resize online) it has been over 48 hours (!!!) that the command is running, with no other output than:

    pi@raspberrypi /mnt $ sudo resize2fs /dev/sda1
    resize2fs 1.42.5 (29-Jul-2012)


    Is this normal? How long could it take for resize2fs to resize to a 20GB partition (6GB were copied using dd previously)? It's an ext4 filesystem.

    ReplyDelete
    Replies
    1. I wouldn't expect it to take more than an hour. Probably a lot less.
      Did you run the e2fsck command immediately after doing the dd copy? You must do that before you try to mount the device.
      All I can suggest is trying again.

      Delete
    2. Yes, e2fsck reported clean filesystem. Then I tried resize2fs with the partirion *mounted* and got

      pi@raspberrypi:~$ sudo resize2fs /dev/sda1
      resize2fs 1.42.5 (29-Jul-2012)
      Filesystem at /dev/sda1 is mounted on /mnt/test; on-line resizing required
      old desc_blocks = 2, new_desc_blocks = 1
      resize2fs: Permission denied to resize filesystem


      So I have *umounted* it and then

      pi@raspberrypi /mnt $ sudo resize2fs /dev/sda1
      resize2fs 1.42.5 (29-Jul-2012)



      Thank you anyway... I had to kill it, after 80 hours running still no feedback. I'll try again later.

      Delete
    3. killed it.
      rebooted.
      run e2fsck, fixed some errors.
      run resize2fs and after a few minutes it was done!

      Delete
  6. Best to remove all rc scripts for the dphys-swapfile, e.g. in the rc.2, 3, 4 and 5 directories, not just 2

    rm /etc/rc?.d/S02dphys-swapfile

    ReplyDelete
  7. This all worked perfectly for me - thanks for writing it up

    ReplyDelete
  8. Excellent clear description of how to do this.
    Thanks

    ReplyDelete
  9. This comment has been removed by a blog administrator.

    ReplyDelete
  10. Hello. First, thanks for this post.

    Got it working with only minor modifications for my unique situation.

    However, my external HDD apparently "times out", sleeps, or hibernates after a certain period of inactivity, which makes it impossible for me to log in via SSH (using PuTTY) once it does. (I'm running headless.)

    The ext HDD is a Toshiba Canvio 3.0 Plus, 1.5TB.

    Furthermore, while I can physically power down the Pi and restart, "sudo reboot" does not seem to work: the Pi lights up, however, I cannot SSH in.

    I do run:

    sudo apt-get -y update
    sudo apt-get -y dist-upgrade
    sudo rpi-update

    regularly.

    Any ideas? (Other than "use another drive", please; that is not really an
    option right now.)

    Thanks in advance!

    (Cross-posted to:
    Raspberry Pi • View topic - USB HDD
    http://www.raspberrypi.org/phpBB3/viewtopic.php?f=26&t=10914&p=129474&hilit=resizefs#p122476)

    ReplyDelete
    Replies
    1. try this:
      apt-get install sdparm
      then
      sdparm --clear=STANDBY /dev/sdX
      (where X is the appropriate letter for your drive)

      if that works, then you can run it at each boot by adding it to /etc/rc.local

      As a last resort, you could do a cron job to access the drive regularly to keep it awake.

      crontab-e
      (this will open the cron config file using nano as the edittor)
      Add this line (again with the correct letter for your drive)
      */5 * * * * /bin/touch /dev/sdX &>/dev/null

      This will access the device every 5 minutes.
      Hope this helps.

      Delete
    2. Thanks for the prompt replies.

      Actually, I think I have resolved my problem. Before I could implement your
      advice, I barely bumped the USB hub and the power failed. That led to a
      corrupt SD card, and time spent rebuilding to the point where I could try
      setting up to run my Pi from an ext HD. Once I replaced what was obviously a
      flaky USB Hub, the problems I described in my first post went away.

      So, again, thank you all so much for your attempts to help me. I do think,
      however, that it was all down to a faulty USB Hub. For anyone who has similar
      issues, if you can, swap out your hub, just to be sure that's not the problem.

      Thanks again!


      (Cross-posted to:
      Raspberry Pi • View topic - USB HDD
      http://www.raspberrypi.org/phpBB3/viewtopic.php?f=26&t=10914&p=129474&hilit=resizefs#p122476)

      Delete
  11. A few other typos than those mentioned, above, but this noob finally figured out the problems and I seem to be running Raspbian off of the HD. It worked first shot. Does some work in the SD then the HD wakes up and starts flashing for the rest of the time and no more flashing of the SD access LED.

    Now we will see if there are timeout problems or anything else. Thanks for the instructions. Would be nice to do just a couple of minutes of cleanup on them and fix the remaining problems.

    I also had to change mmcblk0p2 to mmcblk0p6. One can tell which is should be by looking in /boot/cmdline.txt. It will have the correct name on one of the first lines.

    Mike Morrow
    ILikeTheInternet.com

    ReplyDelete
  12. That is very kind of you to write this share for us, thanks a lot I could get lot more knowledge from your article.. thanks for sharing.

    ReplyDelete
  13. Thanks a lot!
    I just have one question: is the SD card necessary after this process?
    I suppose so. So... Is everything on the SD necessary or i can use a smaller one to keep just the needed files? How can i use a really small SD to just make the Rpi boot from an USB HDD?
    Thank you

    ReplyDelete
    Replies
    1. I'm not sure if the SD card is needed once booting completes but taking it out while the Pi is running would probably be a bad idea. All that you really need to boot a system configured like this are the files on the small FAT partition at the beginning of the SD card and probably something from the boot sector of the drive. You can use a disk imaging tool (or just the dd command) to copy just that little bit and then write that to a very small SD card. I never see anything smaller than 4Gbytes these days but there are lots of older ones still around that are smaller. Beware though, some of those older SD cards may not be compatible with the Pi.

      Delete
  14. Thank you, I got this all going for my rPi and external HDD. The only special thing I did was shrink my HDD volume by 8GB, then use GParted in Ubuntu to make your suggested partitions in the 8GB volume. No need to have the entire external HDD taken over by the rPi, only 8GB! Yay,

    ReplyDelete
  15. Me having a problem,
    I tried to send AT command from my Lxterminal to minicom
    by "echo -n "AT" > /dev/ttyAMA0
    for typing next xommad i need to pass enter to minicom.
    how can i do that?

    ReplyDelete
    Replies
    1. the -n option is suppressing the output of the trailing newline.
      Since you are using AT commands, I will assume that you have a modem connected to the serial port.
      Try using printf instead of echo. It will interpret escaped special characters. "\n" is the enter character.
      For example:
      printf "AT+BAUD2\nATDT123456789\n"
      The exact commands and the delays needed in between will depend on your modem and the service you are connecting to.
      Hope that helps you.

      PS
      I thought the days of modems were long behind me. However, a few years ago I had to configure a Linux system to use an Iridium satellite modem. In the middle of a desert, In an "unspecified location"

      Delete
  16. Hi Ted! Can you tell me, what kind of power supply do you use for this construction? Especially, what output current is in it?
    Thank for sharing your experience.

    ReplyDelete
    Replies
    1. The system pictured suffered a hard drive failure and the USB hub has now also failed.
      Typically, this type application needs about 2A of 5V current.
      I am building a new system using this hub, chosen for the small size:
      Belkin F4U040v USB 2.0 4-Port Ultra-Slim Series Hub
      http://www.newegg.com/Product/Product.aspx?Item=N82E16817394179

      It includes a 2.6A power supply and the system has been working great so far.
      I will be adding multi-segment LED displays for showing CPU and IO utilization, which will be covered in an upcoming blog post.

      Delete
  17. I've always been very aware of the (lack of) performance of the Pi. Is there any sort of comparison between your setup and a vanilla one? Might I suggest a video with boot times side by side, or something like it. This is way out of my league (at least for now), but can this also be done with RaspBMC?

    Thanks for the GREAT tutorial!
    Miguel

    ReplyDelete
  18. Thanks for the how-to (kept me from guessing). I did have to reboot before "rpi-update" would work (and then rebooted again after).

    ReplyDelete
  19. This comment has been removed by the author.

    ReplyDelete
  20. Does This Install all the operating systems that are on the SD card or just Debian?

    ReplyDelete
    Replies
    1. If it is not could you tell us how to move multiple operating systems onto a hard drive?

      Delete
    2. These instructions were made assuming a standard image of Raspbian is used. I should have mentioned that, but it seemed obvious at the time. The popular image now is NOOBS, which let's you load one of several OSes. I plan in experimenting with NOOBS and moving all or part of it to the external drive.

      The same basic process described above would be used. The main difference is that NOOBS has several partitions for the different OSes so you have to know which partition to copy and how to set up the boot sequence to use the external drive. Hopefully I can get to this soon. This post gets a lot of traffic and is a bit out of date now.

      Delete
  21. Excellent guide. New to the RPi platform, and this guide was exactly what I needed. Thank you for taking the time to post this.

    ReplyDelete
  22. Hi i have some questions.

    My cmdline.txt had mmcblk0p6 as the root. So i copied that instead of blk0p2. Was that alright to do?

    When i mounted sda1 and went to edit /mnt/etc/fstab it has mmcblk0p5 as the root, and mmcblk0p6 was listed on the next line (blk0p6 was not listed as root). I chose to change out blk0p5.
    I do not think it worked for me. Can anyone help me out?
    Thanks!

    ReplyDelete
    Replies
    1. I have a NOOBS sd card. Sorry I ready your post about how this guide is for standard raspbian not NOOBS after I submitted my post

      Delete
  23. Just a recommendation this post would work quite well with this setup all you would have to do is create a 4th partition http://www.stuffaboutcode.com/2012/08/raspberry-pi-auto-backups.html

    ReplyDelete
  24. THANKS Ted.
    I follow your explanation Word by Word, and end up with a working system first time.
    Thats is a really GOOD toturial.
    Regards Ole Andersen in Denmark.

    ReplyDelete
  25. Brilliant write up. To ensure booting from the correct hard drive (or flash drive) every time I would also suggest mounting using the UUID of the drive. This means that the boot drive will ALWAYS be mounted at the correct point even if you swap USB ports, add additional drives, etc. See this for further details:
    http://elinux.org/RPi_Adding_USB_Drives#USB_Flash_and_Hard_Drives

    ReplyDelete
    Replies
    1. Under the section "Robust mounting of multiple USB flash drives"

      Delete
  26. Great walk through. Worked like a dream first time.

    Only had one hitch where my SD data didn't copy over correctly the first time. After copying it over again it worked.

    ReplyDelete
  27. Great guide.

    Related to the Q regarding minimum SD size:

    I managed installing a "pisces" (R3 - http://www.raspbian.org/PiscesImages) "minimal" Rasbian version on a 1GB SD card.

    Being a lazydog with no urge to fiffle about bootstrap on SD card, I did the following to get it running:

    1. Following the guide above, I installed Pisces version on a 4GB Flash, had to copy all /boot (found in the fat32 partition visible in Windows) from a "full" running Raspbian card that worked previously. No idea why the bootstrap was different - NOTE: Pisces uses /dev/mmcblk0p3 as root - experiment 2-6 on NOOB and other if needed!

    2. Altered root=/dev/mmcblk0p2 to root=/dev/mmcblk0p3 in the cmdline.txt file

    3. Booted the Pisces flash with USB disk available - the fact that the USB hub powersupply supplies the Pi was a pleasant surprize.

    4. Followed the guide above and created a partition on /dev/sda1 containing Pisces Rasbian on a 250GB resized disk

    5. Enabled journalling on the ext4 disk: tune2fs -O has_journal /dev/sda1

    6. Rechecked the disk: e2fsck -f /dev/sda1 (maybe not needed but now it has journals so...)

    7. Install "Absolute minimal Rasbian image - http://www.linuxsystems.it/raspbian-wheezy-armhf-raspberry-pi-minimal-image/ on a 1GB SD-card

    8. Copyed everything from the 4GB Pisces SD card (used for dd'ing to USB disk - therefore 100% certainly working) /boot (visible in Windows) to the 1GB SD-card after deleting all files there.

    9. Boot Rasberry Pi using bootstrap from minimal distro on 1GB SD-card with entire system on USB disk.

    Sweeeeeeettt - Happppyyyy ;-)

    Merry X-mas

    /Niels

    ReplyDelete
  28. Another alternative to having to constantly type sudo is just: sudo -i or su - (if you have a root password)

    ReplyDelete
  29. how long does the dd stage take. I am using an old msata HDD that I have, sadly dd gives no info. 120gb

    ReplyDelete
    Replies
    1. It shouldn't take more than an hour. Probably more like ten minutes.

      One way to get info on the progress of dd is to open another terminal window and run the command:
      sudo kill -USR1 $(pgrep ^dd$)

      This will send a signal to the dd process and it will output it's status (back in the window it is running in.)

      Delete
  30. I have had a hard disk working with my RSPI for quite a while. When I upgraded to the
    RSPI 2, I tried following the same procedure to install a Toshiba 1 terabyte drive. When I
    got to "rm /etc/rc2.d/..... " I get an error message that the directory does not exist. I determined
    that there is an unintended space in that instruction so I tried it again without the space
    but I still get an error message that the file does not exist. Since it does not exist anyway,
    I assumed no harm in ignoring it and continued on. However, after rebooting, everything
    seems to be going well until halfway through, the boot dies with a message of a "kernel
    panic" and everything quits. I am new to this and possibly the new procedures for the
    RASPI 2 are different from the old one and the suggested procedure will have to be modified?

    Fred K8VDU

    ReplyDelete
    Replies
    1. I wouldn't expect a difference on the model 2. I just received my model 2 and will likely use it to upgrade my MySQL server, which has the hard drive. So, I will find out.

      The rm command is to stop the system from using the flash card for swap space. Even with no swap space the system shouldn't panic on boot. It is more likely something to do with locating the root drive.

      -Ted KJ4CEX

      Delete
  31. When i try to edit /mnt/etc/fstab and save the settings, i get an error saying that it cannot write to fstab because its read only system. I searched the internet for a solution, but can't find anything that seems to work. Do you have any suggestions what to do about this?
    Thank you

    ReplyDelete
    Replies
    1. Like most of the commands for this, it needs to be performed as root. Put a "sudo" in front of the edit command.

      Delete
    2. I did, i used sudo su. I checked the syslog this evening and found out that the fs was going into read only mode because of a "critical target error, dev sda, sector 0".
      I don't know exactly what that meens but it's keeping me from write to the HDD.

      Delete
    3. It looks like there is something wrong with my HDD. This HDD was used on a windows pc before and had never any kind of malfunction. But on the raspberry pi it says all the time that it's a read only system.

      Delete
    4. Can i avoid that sector 0 and make partions on other places of the HDD? Or is there a way to repair that sector?
      Sorry for the multiple replies, but i'm trying to get this work for the past two weeks and my knowledge about linux is minimal so I'm depending on what others have to say about this problem.

      Delete
    5. You can not avoid using sector zero - that is where the partition table is stored. I suggest that you make a backup of your SD card soon. You can make an image using the same diskimager program that you use when you first load the card. Another way that I have started using is the "rpi-clone.sh" script. see this link for more info.
      https://learn.adafruit.com/adafruit-raspberry-pi-lesson-1-preparing-and-sd-card-for-your-raspberry-pi/make-a-backup-image

      Delete
  32. Have you ever tried this with an already running system, rather then a fresh install. Iv had mine running off the SD card for nearly 2 years now, and I think the SD card is starting to pack in. I have done everything as described, and it boots fine, except nothing will pick up my SSL certs, and some things cant find their databases, which I cant understand because everything should be mirrored.
    I would rather not have to start over again, Iv put alot of work into what I have.

    ReplyDelete
    Replies
    1. It will work the same whether it is a new install or a well used one. The process described will clone the current sdcard contents to the hard drive. Note that you still need the sdcard with the boot partition in order to boot. You could also just clone the sdcard to a new one using the "rpi-clone.sh" script. see this link for more info.
      https://learn.adafruit.com/adafruit-raspberry-pi-lesson-1-preparing-and-sd-card-for-your-raspberry-pi/make-a-backup-image

      Delete
  33. Ted: Thank you for the clear instructions. I am not well versed in Linux, but was able to get a HDD hooked up and running. My problem is the drive was salvaged from an old laptop and is starting to fail. I would like to know if you can point me to a procedure where I can image (clone) the existing drive onto a new one.

    Thanks, Steve

    ReplyDelete
    Replies
    1. The easiest way is to create a backup using the rpi-clone script. Instructions are here:
      https://learn.adafruit.com/adafruit-raspberry-pi-lesson-1-preparing-and-sd-card-for-your-raspberry-pi/make-a-backup-image
      You may need to make some modifications to the instructions since you will already have a /dev/sda device and will be cloning to /dev/sdb so be careful about that.

      Delete
  34. Hello, well written and easy to follow. Thank you.

    While trying to mount /sda1 I got "wrong fs type, bad option, bad superblock..."

    So formatted /sda1 and tried again. Was fine this time.

    Thanks.

    ReplyDelete
  35. Hello,
    I am a newbie at raspberry pi. I am using raspbian jessie, I entered in sudo /dev/sda at the start and it said this file does not exist, I also tried /dev/sda1 and /dev/hda and dev/hda1 and I got the same answer. what should I do?
    Thanks

    ReplyDelete
    Replies
    1. Check the output from the lsusb command and see if the device shows up. It probably doesn't. Most likely problem is insufficient power on the USB to power the device. You often need to run this from a powered USB hub.

      Delete
    2. The hard drive shows up at lsusb as
      Bus 001 Device 004: 1058:107b Western Digital Technologies, Inc.
      but I just don't know how to open /dev/sda.
      Thanks for getting back to me so soon.

      Delete
    3. "sudo /dev/sda" doesn't make sense. /dev/sda is a device file not a command. try entering "sudo fdisk /dev/sda" and this will run the partitioning program on the external drive (see the instructions in the post"

      Just to verify that the device file exists, try "ls -al /dev/sda"
      Does that show the file info or "No such file or directory"?

      To "open" the external device you must mount it. Assuming that it has already be partitioned and formatted, then "sudo mount /dev/sda1 /mnt" will mount the drive on the /mnt directory. Then the contents of the drive will appear there.

      Delete
  36. I got to the mounting of /dev/sda1, but it said
    mount: you must specify the filesystem type
    what do I do?
    Thanks again.

    ReplyDelete
    Replies
    1. Normally the system can tell what filesystem type the partition is using. Have you formatted yet? Run the command "mkfs.ext4 /dev/sda1" before doing the rsync command.

      Delete
  37. Hello,
    when the tutorial said
    Change the root device /dev/mmcblk0p2 to be /dev/sda1
    how exactly do you do that? Also is
    sudo vi /mnt/etc/fstab
    all you need to do to change the mount configuration file on the new root?
    Thanks

    ReplyDelete
    Replies
    1. While editing the fstab file, change the line for the root device (the one with only / in the second column)
      The fstab file is all that needs to be changed for the mount configuration, but the boot command file also needs to be changed to tell it to use sda1 as root. That is the change made to /boot/cmdline.txt

      Delete
    2. Hello,
      The rsync command failed once with a bunch of errors about stuff not copied, so I deleted to partition it was in and tried again.
      This time it got a lot farther but it failed with a few io() errors I think, then I tried to retry it but when I entered the command nothing happened. I thought it must have been fine, so I went on to the next step.

      I tried to open /mnt/etc/fstab but I got:
      E297: Write error in swap file
      E303: Unable to open swap file for "/mnt/etc/fstab" , recovery impossible
      "/mnt/etc/fstab" 4 lines , 322 characters
      Press ENTER or type command to continue

      when I pressed enter I got:
      proc /proc proc defaults 0 0
      /dev/mmcblk0p5 /boot vfat defaults 0 2
      /dev/mmcblk0p6 / ext4 defaults,noatime 0 1
      # a swap file is not a swap partition, so no using swapon|off from here on, use dphys-swapfile swap[on|off] for that
      ~
      ~
      ~
      ~
      ~
      ~
      ~

      and so on.
      When I tried typing, the arrow keys were all that worked.
      I then tried to reboot it in hope that the problems would be fixed. It started off fine and then the screen went black like normal but the screen never booted up again. I once saw the little square in the corner but it went away after a few seconds. I had to pull the plug after a minute. I tried to turn it on again but once it started the scrolling checks (with the four raspberries at the top), I got two red warns instead of okays. The first one said insuffiecient space on the root partition, mounting t . . .
      I didn't have time to read the second one before the screen went black again. it hasn't lit up since.
      What should I do?
      Thanks again for your help.

      Delete
  38. Hello, my name is Jose
    Thanks for this post.
    I have used this for the last year and it works very well for me.
    Now I have one problem and I hope you can help me.
    I want to connect another usb disk to the PI, if the PI is running every thing works good but if I reboot, the pi do not start. I think this hapend because the second disk has an external power suplied and the PI identifies this as dev/sda1,
    and do not boot.
    How can I make this work?
    Thanks very much for your help

    ReplyDelete
    Replies
    1. This should solve the problem:
      http://wiki.linuxquestions.org/wiki/Booting_from_USB#Use_a_unique_device_name

      Delete
  39. Very clear instructions but I have tried several times and have gotten this error: rsync: write failed on "/mnt/var/swap": No space left on device (28).

    In the listing above there are hundreds of lines similar to this:

    ERROR: sys/module/uio_pdrv_genirq/sections/__mcount_loc failed verification -- update discarded.

    I thought I was running out of space so I used 32G for the OS partition to no avail. I even switched over to Raspbian Lite, again no joy.

    Any advice would be appreciated.

    ReplyDelete
    Replies
    1. /mnt/var/swap is the old swap file. It should have been deleted and the init script to use it should also have been deleted.
      (from the post)
      Finally, stop the system from using the swap file that it normally uses.
      rm /mnt/etc/rc?.d/*dphys-swapfile

      And delete the old swap file.
      rm /mnt/var/swap

      (You also should have created a swap partition /dev/sda2)
      Add /dev/sda2 as a swap partition by adding this line.
      /dev/sda2 none swap sw 0 0


      My guess is that the init script is still being run. Make sure that the file "dphys-swapfile" is gone from /etc/init.d

      Delete
  40. I just read your article and found it very informative. I remember how hard it was for me to find the right type of external hard drive for my needs. Well, if someone is looking to buy an external hard drive then I'd love to recommend this list of external hard drives where you will find the best one for your specific needs.

    ReplyDelete
  41. This comment has been removed by the author.

    ReplyDelete