CFD Online Logo CFD Online URL
Home > Forums

Maintaining a local git repository on a portable disk image file or partition

Register Blogs Members List Search Today's Posts Mark Forums Read

Rate this Entry

Maintaining a local git repository on a portable disk image file or partition

Posted December 12, 2010 at 12:04 by wyldckat

Here's the scenario: You need the latest OpenFOAM 1.7.x git version, but your Linux machine is stranded on a deserted lab without access to the internet or to any other machine that does have access to the internet. The only machine with internet access that you have access to, is on some other place in the world and on top of that, uses Windows for an operating system. But that certain Windows machine is yours and/or you have administrative powers over it!

What can you do? Install VMplayer or VirtualBox in it, create a Virtual Machine and install Ubuntu or some other Linux distribution on that VM!
How? Search the internet I'm here just to explain how to have a portable git repository of OpenFOAM
Oh and don't forget to install git in that virtual machine! In Ubuntu, run this to install it:
sudo apt-get install git-core

OK, so you've got a working Linux (virtual or real) machine, with internet connection and git is installed. You also have a portable USB pen or harddrive, but it's formatted in NTFS of FAT32, which are Windows friendly, but not POSIX friendly. Now, you have two possible scenarios:
  1. The USB pen/drive is yours and you don't mind reducing the NTFS/FAT32 partition and add a new ext3 or ext4 partition to it. For this, I suggest you use GParted; don't know how? Search the internet! "tutorial gparted" is a good search phrase.
    Advantage with this scenario: you an ext3/4 partition dedicated for transporting an OpenFOAM git and or any other files you may need; mounting the partition should be easy.
  2. The USB pen/drive is (not) yours and you can't change the partitions. In this case, you can create an ext3 or ext4 file system packed inside a single file! Isn't Linux great?
    Advantage: this single-file ext3/4 filesystem can be copied to anywhere and to any filesystem. Even easily up/downloadable! NOTE: FAT32 has a limit of 2GB per file, so if you need a filesystem bigger than this to carry around, it's best to simply create a separate partition.
The first scenario (create a partition) is pretty simple to do with GParted, so I'm going to skip explaining that.
Therefore, I'm going to explain the second scenario.

Preparing and using the single ext3/4 file filesystem
Reference for this section:

This step-by-step list can be done in any folder you want, but only in Linux (and perhaps in Solaris). I'm going to assume you will do these steps directly within the Virtual Machine, so you won't go back and forth with the USB pen/drive.
You can do these steps directly in your USB pen/drive or create the file inside the Virtual Machine's disk and then copy or send it to your real machine.
So here goes:
  1. Let's create the file "ext4file" where the filesystem will be stored, with a size of 512MB (which should be enough, at least for now):
    dd if=/dev/zero of=ext4file bs=1M  count=512
  2. Now we format that file as an ext4 filesystem:
    mkfs.ext4 -F ext4file
  3. Next we can create the folder "$HOME/efmnt" where the file will be mounted and mount the file onto it:
    mkdir $HOME/efmnt
    sudo mount ext4file $HOME/efmnt -o loop,user,owner
    If you are using Ubuntu, then using sudo is valid. If not, you'll have to change to root for mounting the file:
    su -
    mount /path/to/my/ext4file /home/my_user_name/efmnt -o loop,user,owner
    This way of mounting will allow you to save data as a normal user.
  4. Do the things you want to do in the new portable file system, such as git clone and wget and all that. I'll explain later on another step-by-step list.
  5. Now we unmount the folder we mounted before, so we can take the file (or drive) somewhere else. In Ubuntu, run:
    sudo umount /path/to/my/ext4file
    If not in Ubuntu, run:
    su -c 'umount /path/to/my/ext4file'
    This way is more direct
  6. And finally, you can take your file to your other internetless machine, and mount/unmount as in points 3 and 5.
Just in case you need more space in that file in the future, here goes:
  1. To add more 256MB to your filesystem (be sure that the file is unmounted):
    dd if=/dev/zero bs=1M count=256 >> /path/to/ext4file
  2. Expand the filesystem inside the file:
    resize2fs /path/to/ext4file
    And your done
Setting up the portable git repository

Now that you have the portable ext3/4 filesystem (may it be a single file or a partition in the portable drive), mount it on the virtual machine with Linux that has internet access. The folder where it is mounted for this tutorial will be:
So here goes:
  1. Go to the folder, clone the repository from github and get the ThirdParty package while I'm at it:
    cd /home/my_user_name/efmnt
    git clone git://
    If cloning from github doesn't go well, use the mirror repository at
    git clone git://
    And if it still doesn't go well:
    git clone
  2. Next time you need to update the repository on your portable repository (and while in your virtual machine), run:
    cd /home/my_user_name/efmnt
    git pull
  3. Unmount the folder, unmount/safely remove your portable drive and take it to your internetless Linux machine.
  4. Mount the file into a folder just as you did in the Virtual Machine. I'm going to assume it's the same exact folder.
  5. Now, for a new installation in your personal home folder, run:
    cd ~
    mkdir OpenFOAM
    cd OpenFOAM
    git clone /home/my_user_name/efmnt/OpenFOAM-1.7.x
    tar -xzf /home/my_user_name/efmnt/ThirdParty-1.7.1.gtgz
  6. Unmount the file and (safely remove) the portable drive.
  7. Next time you bring your portable drive over with an update, don't forget to mount first and then simply run:
    cd ~/OpenFOAM/OpenFOAM-1.7.x
    git pull
    ./Allwmake > make.log 2>&1
    The last line will start the rebuilding process, and will try to build the utilities and applications that have changed. And I'm assuming that the OpenFOAM environment is already activated (i.e., sourced the file "OpenFOAM-1.7.x/etc/bashrc").
    You can unmount the file/folder when the "git pull" has finished.
Any other questions about git, read the tutorials and learn:
Best regards,
« Prev     Main     Next »
Total Comments 0



All times are GMT -4. The time now is 13:42.