LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-03-2016, 10:34 AM   #1
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Is it possible to sym link in chroot, if yes, how?


process used to mount USB for chroot
after the entire system has been installed into the USB Stick.

Code:
sudo mount /dev/sdc1 /void

sudo mount --rbind /dev /void/dev 

sudo mount --rbind /dev /void/dev 

sudo mount --rbind /proc /void/proc

sudo mount --rbind /sys /void/sys 

sudo chroot /void  
bash
available service daemons

Code:
bash-4.3# ls /etc/sv
acpid		agetty-tty2  agetty-ttyAMA0  dhclient	  sulogin
agetty-console	agetty-tty3  agetty-ttyS0    dhcpcd	  udevd
agetty-generic	agetty-tty4  agetty-ttyUSB0  dhcpcd-eth0  usbmuxd
agetty-serial	agetty-tty5  alsa	     dmeventd	  uuidd
agetty-tty1	agetty-tty6  dbus	     sshd	  wpa_supplicant
root directory needed to be linked to in order to be started on boot up. Showing empty, no links created.
Code:
bash-4.3# ls /var/service
/var/service
but when I go to link one it get an error is is already linked.

Code:
bash-4.3# ln -s /etc/sv/alsa /var/service
ln: failed to create symbolic link '/var/service': File exists
bash-4.3# ls /var/service
/var/service
tying to get it to link in a chroot enviorment failed too
Code:
bash-4.3# ls
bin   dev  home  lib32	lost+found  mnt  proc  run   sys  usr
boot  etc  lib	 lib64	media	    opt  root  sbin  tmp  var
bash-4.3# ls var/service
var/service
bash-4.3# ln -s etc/sv/alsa var/service/
ln: target 'var/service/' is not a directory: No such file or directory
bash-4.3# ln -s etc/sv/alsa var/service
ln: failed to create symbolic link 'var/service': File exists
bash-4.3# ln -s /etc/sv/alsa var/service
ln: failed to create symbolic link 'var/service': File exists
so is it possible to link in chroot, if yes, how?

if no, then I got to reboot into that new system then create my links in post install.
 
Old 12-03-2016, 12:03 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,021

Rep: Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199
I am not quite following You show that a file of some type /var/service exists and then try to create a symbolic to the same, yet the error message is quite correct that the file already exists
as you showed???

The short answer is yes that you can create symbolic links in a chroot environment, just like any other, with the obvious caveat that you cannot link to anything outside the chroot environment.

Are you able to explain further?
 
Old 12-03-2016, 12:20 PM   #3
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Original Poster
Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by grail View Post
I am not quite following You show that a file of some type /var/service exists and then try to create a symbolic to the same, yet the error message is quite correct that the file already exists
as you showed???

The short answer is yes that you can create symbolic links in a chroot environment, just like any other, with the obvious caveat that you cannot link to anything outside the chroot environment.

Are you able to explain further?
when one soft links one thing to another directory all that is needed be the command is this:
Code:
ln -s /source/file  /dir/
in a running install of the this system when one sym links the same method for sym (soft) links takes place.
Code:
Items available to link to service directory. 

[userx@USB8Void64Linux ~]$ ls /etc/sv
acpid           agetty-tty3     agetty-ttyUSB0  dhcpcd-eth0  uuidd
agetty-console  agetty-tty4     alsa            dmeventd     wpa_supplicant
agetty-generic  agetty-tty5     cgmanager       sshd
agetty-serial   agetty-tty6     dbus            sulogin
agetty-tty1     agetty-ttyAMA0  dhclient        udevd
agetty-tty2     agetty-ttyS0    dhcpcd          usbmuxd

service directory that the kernel uses to look at to start daemon on boot up.

[userx@USB8Void64Linux ~]$ ls /var/service
agetty-tty1  agetty-tty3  agetty-tty5  alsa  dhcpcd  uuidd
agetty-tty2  agetty-tty4  agetty-tty6  dbus  udevd


I remove a link first for this example

[userx@USB8Void64Linux ~]$ sudo rm -v /var/service/dbus
removed '/var/service/dbus'

Show that it has indeed been removed.

[userx@USB8Void64Linux ~]$ ls /var/service
agetty-tty1  agetty-tty3  agetty-tty5  alsa    udevd
agetty-tty2  agetty-tty4  agetty-tty6  dhcpcd  uuidd

then Link it again to the service directory _ NOTICE the syntax is the same and the link takes place. 

[userx@USB8Void64Linux ~]$ sudo ln -s /etc/sv/dbus /var/service

[userx@USB8Void64Linux ~]$ ls /var/service
agetty-tty1  agetty-tty3  agetty-tty5  alsa  dhcpcd  uuidd
agetty-tty2  agetty-tty4  agetty-tty6  dbus  udevd

I start service 
[userx@USB8Void64Linux ~]$ sudo sv start dbus
ok: run: dbus: (pid 1826) 5s
[userx@USB8Void64Linux ~]$
two different environments only one works to apply a soft sym link.

I do not know what else to say . it is straight foreword.

Last edited by BW-userx; 12-03-2016 at 12:28 PM.
 
Old 12-03-2016, 02:07 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,021

Rep: Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199
Yes I understand and follow your example, however, if you look back at your original post, /var/service points to a file and not a directory. I can tell this because when you did your ls it did not show
the contents of a directory but rather the file itself, ie.
Code:
$ mkdir tmp
$ ls
tmp
$ ls tmp
$ touch tmp/service
$ ls tmp/service
tmp/service
$ mkdir tmp/service.d
$ ls tmp/service.d
$ touch tmp/service.d/file
$ ls tmp/service.d
file
So ls on a directory either yields nothing for an empty directory or the contents if any, whereas when performing ls of a path to a file returns the path to the file


So for whatever reason, inside your chroot environment you appear to have a file called 'service' in your /var directory ... hence the error
 
Old 12-03-2016, 02:24 PM   #5
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Original Poster
Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by grail View Post
Yes I understand and follow your example, however, if you look back at your original post, /var/service points to a file and not a directory. I can tell this because when you did your ls it did not show
the contents of a directory but rather the file itself, ie.
Code:
$ mkdir tmp
$ ls
tmp
$ ls tmp
$ touch tmp/service
$ ls tmp/service
tmp/service
$ mkdir tmp/service.d
$ ls tmp/service.d
$ touch tmp/service.d/file
$ ls tmp/service.d
file
So ls on a directory either yields nothing for an empty directory or the contents if any, whereas when performing ls of a path to a file returns the path to the file


So for whatever reason, inside your chroot environment you appear to have a file called 'service' in your /var directory ... hence the error
the directory structure is not a file, it is an actual dir/dir
it is the links itself that do not show up because they are symbolic links to a source dir/file or just dir.
perhaps due to the nature of chroot, that I am diffidently not knowledgeable about enough prevent sym links within that environment.

in chroot
Code:
bash-4.3# ls
bin   dev  home  lib32	lost+found  mnt  proc  run   sys  usr
boot  etc  lib	 lib64	media	    opt  root  sbin  tmp  var
bash-4.3# ls home
userx
bash-4.3# ls home/userx
Desktop    installedAlready16GBUSBStick  setbg	 var.lib.dbus.machine-id
Downloads  logout			 upwifi
bash-4.3# ls var/service
var/service
bash-4.3# ls /var/service
/var/service
bash-4.3# touch /var/service/no-link
touch: cannot touch '/var/service/no-link': No such file or directory
bash-4.3# touch var/service/no-link
touch: cannot touch 'var/service/no-link': No such file or directory
bash-4.3# ls
bin   dev  home  lib32	lost+found  mnt  proc  run   sys  usr
boot  etc  lib	 lib64	media	    opt  root  sbin  tmp  var
bash-4.3# touch var/no-link
bash-4.3# cd var
bash-4.3# ls
cache	db     lib   log   no-link  run      spool
chroot	empty  lock  mail  opt	    service  tmp
bash-4.3# cd service
bash: cd: service: No such file or directory
bash-4.3# ls service
service
Not chroot
Code:
userx@voided1.what~>> cd /mnt
userx@voided1.what/mnt>> ls
bin   dev  home  lib32  lost+found  mnt  proc  run   sys  usr
boot  etc  lib   lib64  media       opt  root  sbin  tmp  var
userx@voided1.what/mnt>> ls var
cache   db     lib   log   no-link  run      spool
chroot  empty  lock  mail  opt      service  tmp
userx@voided1.what/mnt>> ls var/service
var/service  <-- light blue in user bash colors
so Now I am more confused. because when I am in a running system, I can go into var/service just like it is a directory do ls and get a results showing all of my soft links to that directroy

Code:
userx@voided1.what/mnt>> cd /var/service
userx@voided1.what/var/service>> ls
NetworkManager  agetty-tty3  bftpd       dbus      rsyslogd  uuidd
acpid           agetty-tty4  bluetoothd  dcron     sshd
agetty-tty1     agetty-tty5  cgmanager   dhclient  thermald
agetty-tty2     agetty-tty6  consolekit  lxdm      udevd
userx@voided1.what/var/service>>
 
Old 12-04-2016, 03:27 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,021

Rep: Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199
Please provide a long listing /var/service in both environments?
 
Old 12-04-2016, 12:30 PM   #7
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Original Poster
Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
I already did, as that other person stated that when I am in chroot, it sees /var/service as a file not a directory, I guess due to everything in that service directory are soft links. But when I boot into the system normally I then can see every soft link that has been added to that directory.

this is chroot
Code:
bash-4.3# ls /var/service
/var/service
this is the system boot up in a normal environment. what you see would be what is already in there, because it was added by the system install process.

Code:
userx@voided1.what~>> ls /var/service
agetty-tty1   agetty-tty4 
agetty-tty2   agetty-tty5 
agetty-tty3   agetty-tty6
this is that install process I use to get it in there
Quote:
create partitions on USB Stick, flag boot partition
/dev/sdc1 /
/dev/sdc2 swap


mkdir /mnt/void

mount /dev/sdc1 /mnt/void


sudo xbps-install -S -R http://repo3.voidlinux.eu/current -r /void base-system ( here is where one adds whatever they want in the system to be added and configured in the install process)

Last edited by BW-userx; 12-04-2016 at 12:34 PM.
 
Old 12-04-2016, 01:05 PM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,021

Rep: Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199
Well you didn't answer my request as I asked for long listings (ie. using -l), but maybe your issue is that the path itself (/var/service) is a link to another location and once chrooted
the link is dead.
 
Old 12-04-2016, 01:24 PM   #9
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Original Poster
Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by grail View Post
Well you didn't answer my request as I asked for long listings (ie. using -l), but maybe your issue is that the path itself (/var/service) is a link to another location and once chrooted
the link is dead.
well alrighty' then, so you're saying that it actually matters.. Sorry get right back to you on that one, asap.

I just didn't see the need to post it in list format as apposed to the other way. sorry again.

Last edited by BW-userx; 12-04-2016 at 01:28 PM.
 
Old 12-04-2016, 01:32 PM   #10
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Original Poster
Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
wow I just learned something, thanks... it is linked to another directory.

Quote:
Originally Posted by grail View Post
Well you didn't answer my request as I asked for long listings (ie. using -l), but maybe your issue is that the path itself (/var/service) is a link to another location and once chrooted
the link is dead.
Quote:
bash-4.3# ls -la /var/service
lrwxrwxrwx 1 root root 29 Sep 13 2015 /var/service -> ../run/runit/runsvdir/current
when one links a daemon for boot start it is to be linked in /var/service

should have stated that in your first request. save a kilobyte or two of electronic paper.

Last edited by BW-userx; 12-04-2016 at 01:39 PM.
 
Old 12-04-2016, 02:32 PM   #11
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,021

Rep: Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199Reputation: 3199
As I do not run a similar type system I had no idea what type of file service was, other than your first post which indicated it was a file of a type other than directory.

Always goes to show that more information is always better

Glad we got there in the end
 
Old 12-04-2016, 02:40 PM   #12
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Original Poster
Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by grail View Post
As I do not run a similar type system I had no idea what type of file service was, other than your first post which indicated it was a file of a type other than directory.

Always goes to show that more information is always better

Glad we got there in the end
yep, and it is a good thing my shoes are not even worn out yet.

for a situation like this, have you ever dealt with it?

I don't think trying to link it to the parent directory in chroot would work do you?

I am doing it again, just to get the steps down so I cold give it a try but I think it will error out in the end.
 
Old 12-04-2016, 08:54 PM   #13
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,892
Blog Entries: 4

Rep: Reputation: 4000Reputation: 4000Reputation: 4000Reputation: 4000Reputation: 4000Reputation: 4000Reputation: 4000Reputation: 4000Reputation: 4000Reputation: 4000Reputation: 4000
Two things to remember:

(1) Fundamentally, a symlink is "a file." It's a very special file that contains a file-name. The filesystem will attempt to resolve the link by looking-up the specified file. (It will also repeat this process a certain small number of times.) Obviously you cannot create a symlink if a file by that name already exists, just as you cannot create any type of file if a file by that name already exists.

(2) "Successfully creating" the symlink does not mean that you can successfully access the target. In fact, you can create a symlink to a target that does not exist. Unlike hard links, symbolic links are resolved when they are referenced, and they are resolved to a file-name, not an inode. The target-filename contained in the symlink will be resolved according to the filename-resolution rules that apply to you right now. If you are "in jail," you stay there.
 
1 members found this post helpful.
Old 12-05-2016, 05:39 AM   #14
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Original Poster
Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by sundialsvcs View Post
Two things to remember:

(1) Fundamentally, a symlink is "a file." It's a very special file that contains a file-name. The filesystem will attempt to resolve the link by looking-up the specified file. (It will also repeat this process a certain small number of times.) Obviously you cannot create a symlink if a file by that name already exists, just as you cannot create any type of file if a file by that name already exists.

(2) "Successfully creating" the symlink does not mean that you can successfully access the target. In fact, you can create a symlink to a target that does not exist. Unlike hard links, symbolic links are resolved when they are referenced, and they are resolved to a file-name, not an inode. The target-filename contained in the symlink will be resolved according to the filename-resolution rules that apply to you right now. If you are "in jail," you stay there.


thanks.

Last edited by BW-userx; 12-05-2016 at 06:27 AM.
 
Old 12-06-2016, 03:41 AM   #15
Jjanel
Member
 
Registered: Jun 2016
Distribution: any&all, in VBox; Ol'UnixCLI; NO GUI resources
Posts: 999
Blog Entries: 12

Rep: Reputation: 364Reputation: 364Reputation: 364Reputation: 364
You'd *LOVE* this book, guaranteed! 3.4.8: mknod; 4.5 'internals' of fs; 2.17.2 links
How.Linux.Works.What.Every.Superuser.Should.Know.2nd.Edition.PDF
(but I can't find where I got it from; I guess you could read it on Amazon)
But it doesn't mention chroot p.s. a fascinating Google: chroot "hard link"

Last edited by Jjanel; 12-06-2016 at 07:54 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
creating a sym link in cygwin/linux so I can grep from the link? willc86 Linux - Newbie 2 07-20-2015 10:02 AM
About sym link directory satimis Linux - General 2 11-09-2012 08:06 AM
cannot create sym link kkpal Programming 3 11-28-2007 10:29 PM
Recursive sym link in aaa_base-12.0? Woodsman Slackware 6 07-08-2007 07:21 PM
Sym link disaepears after shut down/restart usr_wifi Linux - Software 0 02-13-2005 02:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration