Announcement

Collapse
No announcement yet.

How to move "/opt" directory to new partition?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to move "/opt" directory to new partition?

    Ok, so this may be located somewhere else in the forum but I have not been able to locate it, so if it is please point me in that direction.

    Basically, what I would like to accomplish is to move the "/opt" directory from a partition that is currently dedicated only to /opt - to a folder on the /home directory and then rededicate that partion for other uses.
    What I am afraid is going to happen though is that once the /opt directory is relocated, none of the programs in it will maintain the shortcuts in the kickoff application launcher or the other associated program pointers. So I guess there really is a couple of questions.

    Current Disk volume setup:
    sda1: fat32 - Reserved for future use if I absolutely have to put XP on this system.
    sda2: ext4 - / (boot)
    sda3: sda5: ext4 /home
    sda6: ext4 /opt
    sda4: Swap partition
    So, I am sure some are wondering why I would do such a thing - but basically it boils down to being new to linux. It was a fresh drive when I was loading kubuntu 9.10 and I knew that I did not want the whole thing as one partition and as I had done some research on the file systems available and how to set them up so I could put windows-crap on it later if need be, I had not run across the "/opt" terminology - so I equated it to user-defined-optional, thinking that this would be where I would stick all the multimedia and other mostly static files. Only later did I find out - because the partition did not mount the way I expected it to (read as: not directly visible in Dolphin) that for some unknown reason opt is the directory that all the applications get loaded into. Go figure... Really, wouldn't /app or /apps be a better suited name?

    So... what I think I know:
    From the man page on the move command mv and the associated info file, it looks like this could copy the files, so for example, I could use (from root):
    mv -n /opt -T /home/opt
    but this appears to be a 'drag-n-drop' sort of option, if you will. And I am not certain, but would appear to break any existing links. Plus of course, they are both mounted partitions.

    There is of course in the man page for mount, the move option also.
    Mount -M /opt /home/opt
    But while this will solve the mounted issue, it still appears to be a d-n-d.

    Other then that, I'm at a loss. The partitions are the correct size and location that I want so I don't think a Live partition CD is going to do what I want. Maybe there is one that will, I just don't know.

    So question one: am I worried over nothing? Is moving the /opt directory just not that big of a deal? and that kubuntu will sort it all out after I do it so that all the application links still work?

    Q2: if it is at least a bit of an ordeal, then how do you suggest I go about it? What would be the best method? Do I just need to reload the boot disk and start over? Or is there a command out there that will work? One of the above? Or something else?

    Thanks - in - advance

    #2
    Re: How to move "/opt" directory to new partition?

    I see no problems here: you simply move /opt to another partition, unmount the partition /opt was living in, modify stab, and move /opt to the root partition

    Afterward you may do with the former /opt partition as you like
    Join the dark side<br />---------------------------------------------------------------------<br />Samsung NC10 netbook running<br />PCLinuxOS 2010 // Win XP

    Comment


      #3
      Re: How to move &quot;/opt&quot; directory to new partition?

      Here is a rough skeleton of how I would do it; bear in mind that there is no single *right* way:

      First, copy the files from where they were to where you want them. Don' delete anything until you are sure everything works.
      Code:
      sudo rsync -av /opt /home
      This will create an opt directory in /home, and preserve all of the ownership flags in the files and directories.

      Then unmount your current opt partition (be sure to cd to somewhere other than /opt before doing this)
      Code:
      sudo umount /dev/sda6
      Now the opt directory normally resides in / , so I would make a symbolic link from /opt to the new opt directory:
      Code:
      sudo ln -s /home/opt /opt
      then test it:
      Code:
      ls -al /opt
      and see if your files are there. Also try some apps from your menu that use /opt, and see if they work

      If all is well, then you can remove the /opt partition from your /etc/fstab file. Actually, don't remove it, but change the mount point to something else. The entry in fstab probably looks something like this:

      Code:
      #/dev/sda4
      UUID=06fdb5bb-014e-48e0-973a-1e743d80fc00 /opt    ext4  defaults 0    2
      (the uuid, if you are using that method, will of course be different)

      Change the mount point from /opt to, just for testing purposes, /media/extra
      then make an extra directory in /media, and
      Code:
      sudo mount -a
      look in your /media/extra directory and see if all of your (old) opt stuff is there.

      -------------------------------------------------------------------

      The other alternative is move your actual files into /opt in the root partition, and not on /home.
      You can do it that way, too.

      First, copy over the files to a new / directory:
      Code:
      sudo rsync -av /opt/ /newopt
      Note the extra slash after /opt. This will create a new directory on / with all your opt files in it.
      Then unmount /opt as above, then sudo mv /newopt /opt.Test you applications, then make the changes in fstab as above.
      We only have to look at ourselves to see how intelligent life might develop into something we wouldn't want to meet. -- Stephen Hawking

      Comment


        #4
        Re: How to move &quot;/opt&quot; directory to new partition?

        Thanks doc, that helps a lot

        I do have a couple of questions though. Since /opt is normally in root I will go the route of your second suggestion and move it there. But after I create the new directory /newopt and unmount the old partition - the directory /opt still shows up in root?

        Code:
        root@HomeSys2:~# rsync -av /opt/ /newopt
        sending incremental file list      
        created directory /newopt 
        ...skip verbose out...
        sent 76812289 bytes received 14864 bytes 13968573.27 bytes/sec
        total size is 76755468 speedup is 1.00
        root@HomeSys2:~# umount /dev/sda6
        root@HomeSys2:~# ls /
        bin  dev home      lib  lost+found newopt root   srv usr   vmlinuz.old
        boot  dos initrd.img   lib32 media    opt   sbin   sys var
        cdrom etc initrd.img.old lib64 mnt     proc  selinux tmp vmlinuz
        root@HomeSys2:~#
        So if I use mv it just puts the newopt directory under opt and the apps do not see the links they need to. After a little research I found that mv actually works two ways, and that if I removed the opt directory first (which is safe because hda6 is unmounted and contains a backup copy) then the mv command you provided above will just rename /newopt to /opt.

        Code:
        root@HomeSys2:~# rm -r /opt
        root@HomeSys2:~# ls /
        bin  dev home      lib  lost+found newopt sbin   sys var
        boot  dos initrd.img   lib32 media    proc  selinux tmp vmlinuz
        cdrom etc initrd.img.old lib64 mnt     root  srv   usr vmlinuz.old
        root@HomeSys2:~# mv /newopt /opt
        root@HomeSys2:~# ls /
        bin  dev home      lib  lost+found opt  sbin   sys var
        boot  dos initrd.img   lib32 media    proc selinux tmp vmlinuz
        cdrom etc initrd.img.old lib64 mnt     root srv   usr vmlinuz.old
        root@HomeSys2:~#
        Which makes the directories look the way they should. And the links work! HooRah

        Having done this though, I still need to update the fstab file. And that is where I am having a little trouble. You talked to not removing the /opt mount point in your instructions, I assume this is because I was asking how to move it to the home directory instead of the normal location in root? Y/N? Since I opted to move to root, can I safely remove this mount point to /opt in fstab altogether?
        Once I solve that, then I can go on and make the changes to the other partition sda6.

        Thx Agn.

        Comment


          #5
          Re: How to move &quot;/opt&quot; directory to new partition?

          Since I opted to move to root, can I safely remove this mount point to /opt in fstab altogether?
          Once I solve that, then I can go on and make the changes to the other partition sda6.
          Yes, you can. I just wanted you to leave it in there in case something went wrong, and you had to go back to your old setup to get your files out. The other reason is, to have access to the partition at all, it needs to be in fstab (or entered each time you mount it, a real pain). So you can change the mount point for it in fstab just by changing the /opt to something else, and not have to enter the whole thing all over again. As I said, there is no single "right" way to do it.
          We only have to look at ourselves to see how intelligent life might develop into something we wouldn't want to meet. -- Stephen Hawking

          Comment

          Working...
          X