1'\" te 2.\" Copyright (c) 2004, Sun Microsystems, Inc. All Rights Reserved. 3.\" Copyright 1989 AT&T 4.\" 5.\" The contents of this file are subject to the terms of the 6.\" Common Development and Distribution License (the "License"). 7.\" You may not use this file except in compliance with the License. 8.\" 9.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10.\" or http://www.opensolaris.org/os/licensing. 11.\" See the License for the specific language governing permissions 12.\" and limitations under the License. 13.\" 14.\" When distributing Covered Code, include this CDDL HEADER in each 15.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16.\" If applicable, add the following below this CDDL HEADER, with the 17.\" fields enclosed by brackets "[]" replaced with your own identifying 18.\" information: Portions Copyright [yyyy] [name of copyright owner] 19.\" 20.\" Portions Copyright 2021 OmniOS Community Edition (OmniOSce) Association. 21.\" 22.Dd March 18, 2021 23.Dt CHROOT 8 24.Os 25.Sh NAME 26.Nm chroot 27.Nd change root directory for a command 28.Sh SYNOPSIS 29.Nm 30.Ar newroot 31.Ar command 32.Sh DESCRIPTION 33The 34.Nm 35utility causes 36.Ar command 37to be executed relative to 38.Ar newroot . 39The meaning of any initial slash 40.Pq / 41in the path names is changed to 42.Ar newroot 43for 44.Ar command 45and any of its child processes. 46Upon execution, the initial working directory is 47.Ar newroot . 48.Pp 49Notice that redirecting the output of 50.Ar command 51to a file, such as in: 52.Pp 53.D1 Nm chroot Ar newroot Ar command Sy > Pa xyz 54.Pp 55will create the file 56.Pa xyz 57relative to the original root of 58.Ar command , 59not the new one. 60.Pp 61The new root path name is always relative to the current root. 62Even if a 63.Nm 64is currently in effect, the 65.Ar newroot 66argument is relative to the current root of the running process. 67.Pp 68This command can be run only by the super-user. 69.Sh EXIT STATUS 70The exit status of 71.Nm 72is the exit status of 73.Ar command . 74.Sh OPERANDS 75The following operands are supported: 76.Bl -tag -width Ar 77.It Ar newroot 78The new root directory. 79.It Ar command 80The command to be executed relative to 81.Ar newroot . 82.El 83.Sh EXAMPLES 84.Sy Example 1 85Using the 86.Nm 87Utility 88.Pp 89The 90.Nm 91utility provides an easy way to extract 92.Sy tar 93files 94.Pq see Xr tar 1 95written with absolute filenames to a different location. 96It is necessary to copy the shared libraries used by 97.Sy tar 98.Pq see Xr ldd 1 99to the 100.Ar newroot 101filesystem. 102.Bd -literal -offset indent 103example# mkdir -p /tmp/lib /tmp/usr/lib 104example# cd /lib && cp ld.so.1 \e 105 libavl.so.1 libc.so.1 libcmdutils.so.1 libcustr.so.1 \e 106 libm.so.2 libmd.so.1 libmp.so.2 libnsl.so.1 \e 107 libnvpair.so.1 libsec.so.1 libsecdb.so.1 libtsol.so.2 \e 108 libuutil.so.1 /tmp/lib/ 109example# cp /usr/lib/libidmap.so.1 /tmp/usr/lib/ 110example# cp /usr/bin/tar /tmp 111example# dd if=/dev/rmt/0 | chroot /tmp tar xvf - 112.Ed 113.Sh SEE ALSO 114.Xr cd 1 , 115.Xr ldd 1 , 116.Xr tar 1 , 117.Xr chroot 2 , 118.Xr ttyname 3C , 119.Xr attributes 7 120.Sh NOTES 121Exercise extreme caution when referencing device files in the new root file 122system. 123.Pp 124References by routines such as 125.Xr ttyname 3C 126to 127.Dv stdin , 128.Dv stdout , 129and 130.Dv stderr 131will find that the device associated with the file descriptor is unknown after 132.Nm 133is run. 134