MySQL for the Internet of Things

(Steven Felgate) #1

Chapter 6 ■ Building low-Cost MysQl data nodes


The next step is to format the drive with the ext4 file system. This is easy and requires only one
command: mkfs (make file system). You pass it the device name. If you recall, this is /dev/sda1. Even though
you created a new partition, it is still the first partition because there is only one on the drive. If you are
attempting to use a different partition, be sure to use the correct number! The command may take a few
minutes to run, depending on the size of your drive. The following example shows the command in action:


pi@raspberrypi ~ $ sudo mkfs.ext4 /dev/sda1
mke2fs 1.42.12 (29-Aug-2014)
Creating filesystem with 29304945 4k blocks and 7331840 inodes
Filesystem UUID: 0285ba01-3880-4ee5-8a19-7f47404f1500
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872


Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done


Now you have a new partition, and it has been properly formatted. The next step is associating the
drive with a mount point on the boot image and then connecting that drive on boot so you don’t have to do
anything to use the drive each time you start your Raspberry Pi.


Setting Up Automatic Drive Mounting


External drives in Linux are connected (mounted) with mount and disconnected (unmounted) with umount.
Unlike with some operating systems, it is generally a bad idea to unplug your USB drive without unmounting
it first. Likewise, you must mount the drive before you can use it. This section shows the steps needed to
mount the drive and to make the drive mount automatically on each boot.
I begin with a discussion of the preliminary steps to get the drive mounted and ready for automatic
mounting. These include creating a folder under the /media folder to mount the drive (called a mount point),
changing permissions to the folder to allow access, and executing some optional steps to tune the drive.


pi@raspberrypi ~ $ sudo mkdir -p /media/HDD
pi@raspberrypi ~ $ sudo chmod 755 /media/HDD
pi@raspberrypi ~ $ sudo tune2fs -m 0 /dev/sda1
tune2fs 1.42.12 (29-Aug-2014)
Setting reserved blocks percentage to 0% (0 blocks)
pi@raspberrypi ~ $ sudo tune2fs -L MYSQL /dev/sda1
tune2fs 1.42.12 (29-Aug-2014)
pi@raspberrypi ~ $ sudo mount /dev/sda1 /media/HDD


These commands are easy to discern and are basic file and folder commands. However, the tuning
steps using tune2fs (tune file system) are used to first reset the number of blocks used for privileged access
(which saves a bit of space) and then label the drive as MYSQL. Again, these are optional, and you may skip
them if you like.


■Tip you can unmount the drive with sudo umount /dev/sda1.

Free download pdf