In this document we will set up a repository on a USB flash drive, also called a USB stick.
Normally a USB stick, as it comes out of the box, has been formatted with a FAT filesystem. Such a filesystem is not supported for collaboration. The stick needs to formatted to the ext3 filesystem for collaboration to work. How this is done will be described here.
Insert the stick into the computer, and wait a little till it gets mounted. It is supposed to mount automatically. If it does not mount on its own, then automatic mounting needs to be set up. Setting up automatic mounting goes beyond the scope of this tutorial.
In the terminal, give the command
df
The output of this command can be something like:
Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 93539428 76882380 11905428 87% / tmpfs 1038428 0 1038428 0% /lib/init/rw udev 10240 104 10136 2% /dev tmpfs 1038428 0 1038428 0% /dev/shm /dev/hda 629742 629742 0 100% /media/cdrom0 /dev/sdb5 306619956 189335920 101708620 66% /media/293gig /dev/sdc1 240362656 64350876 163801980 29% /media/250gb /dev/sdd1 1960684 660896 1200188 36% /media/usbdisk
Looking through the list of mounting points, we assume that the USB stick that was inserted mounts at /media/usbdisk. From there we can see that the device is /dev/sdd1. Once we have that information, we are ready for the next step.
Before the stick can be formatted, it must be unmounted first. Issue the following command to unmount the stick:
sudo umount /media/usbdisk
The "sudo" in the command means that root privileges are needed to execute the command.
To format the USB stick to the ext3 filesystem, issue the following command:
sudo mkfs.ext3 /dev/sdd1
The formatting process will be visible and at the end some information about it will be given. At this point it is important to see if no errors occurred.
The formatting command is very powerful. One could even format the main drive of the computer, wiping out all information. Extreme care should be used to ensure that the USB stick is going to be formatted, and nothing else.
A label needs to be written to the USB stick. The reason of this is so as to make sure that this stick will always mount at the same mounting point. In this tutorial we write the label "usbstick" to it.
We take it that the same device is being used as we used for formatting the stick. That is device /dev/sdd1. To write the label to the stick, issue the following two commands:
sudo e2label /dev/sdd1 usbstick
sync
After the label has been written to it, remove the stick from the computer, and insert it again. It should now mount to the name of the label. In this case it should mount under /media/usbstick.
This can be verified with command "df":
df
The output of this command:
Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 93539428 76882380 11905428 87% / tmpfs 1038428 0 1038428 0% /lib/init/rw udev 10240 104 10136 2% /dev tmpfs 1038428 0 1038428 0% /dev/shm /dev/hda 629742 629742 0 100% /media/cdrom0 /dev/sdb5 306619956 189335920 101708620 66% /media/293gig /dev/sdc1 240362656 64350876 163801980 29% /media/250gb /dev/sdd1 1960684 660896 1200188 36% /media/usbstick
This shows that it now mounts under the new name.
The USB stick will hold the data repository.
To make this stick fit for collaboration, there are a few steps to be taken. These steps are:
1. The first step will be to create a directory for the repository, and to make that directory writable. If we assume that the stick mounts at /media/usbstick, then the command to create a directory called "repository" is:
sudo mkdir /media/usbstick/repository
Notice the "sudo" command, which means that this usually needs to be done by user root. If this is done by an ordinary user, permission would be denied.
Once the directory for the repository is there, this directory needs to be made writable for ordinary users. This is the command:
sudo chmod -R 0777 /media/usbstick/repository/
Note the "sudo" again.
Now it is time to check whether the USB stick is writable. We do this by trying to create a file in the repository. If this succeeds, then it is writable. Here's the command:
touch /media/usbstick/repository/testfile
This command should complete without errors. After that the file needs to be removed again:
rm /media/usbstick/repository/testfile
2. The second step is to make the USB stick the current working directory. Type:
cd /media/usbstick/repository
3. The next step is to create a repository on the USB stick, and to copy the data to it.
To create a shared repository on the USB stick, type:
git --bare init --shared
Git will respond saying that an empty shared Git repository has been created.
Before removing the stick, ensure that the data gets written to it, by issuing the command
sync
This finishes setting up the repository on the USB flash drive.
The repository that was created in this tutorial has the following URL:
file:///media/usbstick/repository
The users that are going to use this repository need this URL.