# Symbolic copy of source directory? -- solved

## 1clue

Hi,

Trying to get back something I used years ago, can't find the command args that work.

When I'm building a kernel I copy the raw kernel sources (in this case hardened-sources) over to a work directory.

I used to do something like:

```
cp -rs linux-4.3.3-hardened-r4 linux-4.3.3-hardened-r4-k01
```

This would copy the directory structure to a new root folder, but each real file would be a symbolic link to the original, thereby saving space.  I lost this some time back, and haven't done much about it because of plentiful disk space and not so many kernels.  Now though I'm facing a single directory structure supporting the host and several VMs, each of which want a different kernel.

Right now when I do this, I get a bunch of:

```

cp: ‘linux-4.3.3-hardened-r4-k01/firmware/radeon/RV770_me.bin.ihex’: can make relative symbolic links only in current directory

cp: ‘linux-4.3.3-hardened-r4-k01/firmware/radeon/RV770_pfp.bin.ihex’: can make relative symbolic links only in current directory

cp: ‘linux-4.3.3-hardened-r4-k01/firmware/sb16/alaw_main.csp.ihex’: can make relative symbolic links only in current directory

cp: ‘linux-4.3.3-hardened-r4-k01/firmware/sb16/ima_adpcm_capture.csp.ihex’: can make relative symbolic links only in current directory

cp: ‘linux-4.3.3-hardened-r4-k01/firmware/sb16/ima_adpcm_init.csp.ihex’: can make relative symbolic links only in current directory

cp: ‘linux-4.3.3-hardened-r4-k01/firmware/sb16/ima_adpcm_playback.csp.ihex’: can make relative symbolic links only in current directory

cp: ‘linux-4.3.3-hardened-r4-k01/firmware/sb16/mulaw_main.csp.ihex’: can make relative symbolic links only in current directory

cp: ‘linux-4.3.3-hardened-r4-k01/firmware/sun/cassini.bin.ihex’: can make relative symbolic links only in current directory

cp: ‘linux-4.3.3-hardened-r4-k01/firmware/tehuti/bdx.bin.ihex’: can make relative symbolic links only in current directory

cp: ‘linux-4.3.3-hardened-r4-k01/firmware/ti_3410.fw.ihex’: can make relative symbolic links only in current directory

```

Anyone know this off-hand? It would be very helpful right now.  I have 4.3g in /usr/src, and there's really no need for it IMO.Last edited by 1clue on Mon Feb 01, 2016 7:41 pm; edited 1 time in total

----------

## 1clue

I guess I worked around it by using an absolute path for the source directory.

----------

## Syl20

Visibly, the source and the destination directories are on the same filesystem. So why not using hard links (cp -rl), instead of symbolic ones (cp -rs) ?

----------

## 1clue

It may be a petty reason, but there is one.

I prefer the nature of the file (link/not link) to be obvious when I list the files.  Hard links are by their nature difficult to determine that way.

I have in the past edited the linked files thinking they were for my current version of the source when in fact my changes altered other projects I had going.  Not so much with kernel source, but with source in general.

----------

## s4e8

Symlink a directory structure is "lndir" command, "emerge lndir" to get it.

To compile kernel out of source tree:

```

mkdir newdir

bash /path/to/kernel-source-tree/scripts/mkmakefile /path/to/kernel-source-tree newdir

cd newdir

make menuconfig

```

----------

## 1clue

 *s4e8 wrote:*   

> Symlink a directory structure is "lndir" command, "emerge lndir" to get it.
> 
> To compile kernel out of source tree:
> 
> ```
> ...

 

This is awesome.  Never imagined it, it's exactly what I'm after.  Thanks!

----------

## netfab

 *Quote:*   

> 
> 
> Now though I'm facing a single directory structure supporting the host and several VMs, each of which want a different kernel.
> 
> 

 

If your goal is to compile the same kernel version using multiple different .config, you should try to use the in-kernel mechanism by using the KBUILD_OUTPUT env variable :

Change directory to your kernel tree :

```

 # cd /usr/src/linux

```

Prepare the build environment for your host, and compile the kernel :

```

 # mkdir build-host

 # export KBUILD_OUTPUT="/usr/src/linux/build-host"

 # cp /path/to/your/host/config ${KBUILD_OUTPUT}/.config

 # make

```

All generated files (including built kernel) will be in build-host/ subdirectory.

Prepare the build environment for your vm-1, and compile the kernel :

```

 # mkdir build-vm-1

 # export KBUILD_OUTPUT="/usr/src/linux/build-vm-1"

 # cp /path/to/your/vm-1/config ${KBUILD_OUTPUT}/.config

 # make

```

All generated files (including built kernel) will be in build-vm-1/ subdirectory.

----------

## szatox

 *Quote:*   

> cp -rs linux-4.3.3-hardened-r4 linux-4.3.3-hardened-r4-k01

 

How 'bout rsync?

 *Quote:*   

> rsync -a  --link-dest=/usr/src/linux/ /usr/src/linux/ /usr/src/newdir/

 

Has 2 advantages: it comes with gentoo by default, and it creates hard links (so you won't break your shadow copy when you delete the original).

The disadvantage is you must stay within a single filesystem (because hard links refer to files' inode and not to the name like softlinks do)

```
Quad src # du -hs linux/

1.3G   linux/

Quad src # du -hs linux/ newdir/

1.3G   linux/

18M   newdir/

Quad src # du -hs newdir/

1.3G   newdir/

```

I must say I like  *Quote:*   

> 
> 
> If your goal is to compile the same kernel version using multiple different .config, you should try to use the in-kernel mechanism by using the KBUILD_OUTPUT env variable : 

  though. Pretty much what I have been looking for  :Laughing: 

----------

## 1clue

My real goal has been to have multiple kernels compiled from the same source without interfering with other kernels in any way.

I should have figured that the kernel development people would need this much more than I do and would have a fantastic mechanism already in place.

The mkmakefile process that s4e8 mentioned sounds best to me.

Thanks.

----------

