How do You Move Cygwin?

Last week, I had to move Cygwin from my old to my new working PC.

I can tell you, starting new with Cygwin is a completely different thing than copying or moving a working installation to another PC after four years of not updating it. I spent one and a half days on the task and it still does not work exactly like it did before … but I can use it productively. And it was worth the trouble. 😉

What follows is my personal moving cygwin leaflet.

How do I copy or move Cygwin from PC 1 to PC 2?

As said, it was not easy and I had to follw many blind alleys and got lost in the mazes of the Cygwin forums a lot ….. I’m leaving away some of the blind alleys and all of the system reboots in the following description.

  1. Zip the cygwin directory on PC 1. On my PC 1, it is located under C:\cygwin. It contains cygwin’s setup.exe and the packages directory and the bin, usr, etc, lib … directories.  I zipped it to c-cygwin.7z.
  2. Zip the user’s home directory on PC 1. My cygwin username on PC 1 was ‘wic’, and the home was located under D:\wic. I zipped it to d-wic.7z.
  3. Unzip the c-cygwin.7z on PC 2 to C:\cygwin.
  4. Unzip the d-wic.7z, ideally to D:\wic. But my PC 2 has no D:\ drive and I don’t want to repartition it now. So I extract it to C:\wic.
  5. Run c:\cygwin\setup.exe. Select “Install from local directory”. Select “c:\cygwin” as root directory. Select C:\cygwin\packages as local package directory. Click Next, Next, … until setup.exe ends.
  6. Set the Windows environment variable HOME for your user to /cygdrive/c/wic. Literally, as cygwin like path.
  7. Now I can doubleclick my C:\cygwin\cygwin.bat file and it tries to run my olde .profile and so on…..But, I get some strange errors like

    bash: $’\r’: command not found

  8. I’m assuming my .profile has Windows- line-endings but the drive is mounted in binmode. I call ./mount and get

    c: on /cygdrive/c type system(binmode,noumount)
    d: on /cygdrive/d type system (binmode,noumount)

    I call ./od -c ~/.profile  and see a lot of \r\n. So my assumption seems plausible.

  9. I’m trying to remount in textmode: mount -t c:\cygwin /cygdrive/c but I’m getting this error: mount: /cygdrive/c: Device or resource busy.
  10. Somewhere in the net they say if this error occurs, you should unmount first. I’m trying umount -A, and there is no error message. But still, the binmode-mounts stay. I cannot not remount c: as textmode.
    During all the reading in the forums, I find out that the cygwin maintainers changed the treatment of line-endings totally around 2011. I think there’s no way to resist these changes….. After four years, finally I have to update my cygwin.
  11. I download and install the newest version of cygwin. At least the PATH variable is now set correctly, I can call cygwin commands now from every folder as long as I’m inside the bash.
  12. I’m mounting mkdir /c; mount C: /c   Seems to work. Still the mounting of my home directory is wrong.
  13. I’m moving c:\wic to c:\cygwin\home\wic and setting the HOME environment variable to /home/wic. Still, it cannot interpret the windows line endings correctly.
  14. I’m calling d2u (dos2unix) for the most important files:
    cd /c/cygwin/home/wic
    d2u .*   # this works, d2u ignores binary files and directories
    d2u *
    cd bin
    d2u .*
    d2u *
  15. cp /bin/bash.exe /usr/local/bin/bash.exe  # because some of my bash scripts use #!/usr/local/bin/bash
  16. Copy scripts from c-cygwin.7z/usr/local/bin to /usr/local/bin, running d2u * in /usr/local/bin.
  17. When I close the cygwin window and start it again, the mount of c: -> /c is away. Maybe because of lacking rights? I try to start cygwin with admin rights and do the mount again. No, it’s not a rights problem, but mount does only create temporary mounts. If you want to have persistent mounts, you have to change the /etc/fstab file.
  18. Also, I want to replace the /cygwin prefix by /, so that cd c:/ can be written as cd /c.  In the /etc/fstab, replace this line
    none /cygdrive cygdrive binary,posix=0,user 0 0
    this:
    # getting rid of /cygdrive and make all new mounts text mounts.
    none / cygdrive text 0 0
  19. Hooray hooray. Now, I can use all of my scripts, my aliases and all of the un*x commands that come with cygwin. Only some fine tuning is lacking.
  20. Create a shortcut on the screen to Cygwin.bat.
  21. Select the little tree as icon for the shortcut. The tree is my bash symbol for ages. (pic)
  22. Double click it. Right-click on the window header. Select Properties. Choose these properties:
    Quick-Edit-Mode: on
    Insert-Mode: on
    Font:7×12
    Window buffer size: w x h 120 x 3000, window size: 120 x 43
    Window background color: 244,244,188
    Window text color: 0,10,10

cygwin

DONE.