How can I add a script to the image to run at boot before popping the card into the Raspberry Pi? I can access the SD card in Ubuntu but not sure how to find /etc/init.d. The picture shows diskutil -l but I'm not sure which partition to mount. enter image description here

  • You are either contradicting yourself or you are looking in the wrong partition. You also do not mention the source of the OS on the card, but presuming it is Raspbian (or most other Pi distros, but not NOOBS), the root filesystem is in the second partition.
    – goldilocks
    Dec 5, 2016 at 15:20
  • Apologies, it's Raspbian. I want to add a script to run at first boot.
    – alkopop79
    Dec 5, 2016 at 15:50
  • Okay, so the second partition contains the root filesystem. If you can't find it, then you need to indicate how you've checked to see if it exists; "Fuse" implies to me the laptop is running linux (which is probably the most foolproof way to access an ext4 filesystem), but that's not clear either. If you can find it, then you should be able to mount it and find /etc/init.d (note this is a bit of an obsolete method but it will still work). Somewhere in there something isn't working out. We need more details.
    – goldilocks
    Dec 5, 2016 at 16:01
  • I'm using Mac OS X and have Ubuntu VM. I wasn't quite sure which partition to mount on Ubuntu. In Mac OS X once partition appears as 'BOOT'.
    – alkopop79
    Dec 5, 2016 at 16:43
  • I'm still confused and don't know what exactly am I looking for. What might be the name of the right partition?
    – alkopop79
    Dec 5, 2016 at 17:04

2 Answers 2


sda isn't the SD card, it's the storage allocated for the VM. Even it you do find /etc/init.d there, don't bother, it's the wrong one. This storage appears to be arranged so that it can have more than four partitions, which is why you have 1, 2, and 5. DOS style partition tables have a maximum of four primary partitions. To increase that, you can use a special "extended" partition, that can contain more "logical" partitions.

The extended partition doesn't itself contain a filesystem. The reason it's required is a DOS style MBR is only 512 bytes, which only has room for information about 4 partitions. An extended partition is just an extra table for information about more, but it has to be somewhere other than the MBR itself (which is the first sector of the device), and its allocated space incorporates the logical partitions within it. There is more information about this stuff in that wikipedia article. Anyway, so sda5 is a logical partition that occupies all of sda2. This might seem a bit silly, and perhaps it is in this case, but it is sort of like the difference between 6 and 3+3 ;) It's marked as swap, meaning it is for use if RAM allocated to the VM is all used up. Probably you don't need it and it was set this way when the VM was, but no big deal for now.

More to the point...

You may not have access to the SD card from the VM. To check, look at ls -1 /dev/sd* before you insert it, and afterward. If they are the same, then you need to arrange for the VM to have access to external storage devices.

If they are different, you should now know which device the SD card is. fdisk -l on that device (e.g., sdb) should look like this:

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1        8192   172031   163840   80M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      172032 30318591 30146560 14.4G 83 Linux

The size of the second partition may be different, but note:

  • The offset of the first partition is 8192. This is an SD card related thing.
  • The first partition is very small (only 80M; the default on Raspbian currently is I think actually 60M) and FAT32. This is the boot partition. Everything can read FAT32, so it may be the only one that actually shows up under OSX
  • The second partition is Linux. This is the root filesystem where you will find the /etc/init.d you want.

The first partition is a requirement for a Pi based card, so if you see anything where it isn't a little FAT32 (or VFAT) partition, it is not a Pi SD card.


This can easily be done with my Nard SDK distro. If the script


exist it will be run on boot and then become deleted.

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.