Commit graph

22 commits

Author SHA1 Message Date
Richard Weinberger
07de470e43 switch_root: Add a sanity check
As switch_root basically does rm -Rf / we should make sure
that / is really an initramfs.

Signed-off-by: Richard Weinberger <richard@nod.at>
2013-02-13 14:55:30 +01:00
Karel Zak
17df84df27 switch_root: check open() return value [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-07 13:02:42 +02:00
Sami Kerola
add1b8afd0 translation: unify stat error messages
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-16 18:18:22 +02:00
Sami Kerola
efb8854f4c sys-utils: verify writing to streams was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-04 19:49:40 +02:00
Sami Kerola
dd41e06795 switch_root: close open file after usage [cppcheck]
[sys-utils/switch_root.c:159]: (error) Resource leak: cfd

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-02-08 14:23:28 +01:00
Harald Hoyer
944de78b5d switch_root: umount mount points we cannot move with MNT_DETACH
If a mount point cannot be moved to the new root, umount it with
MNT_DETACH, so that it is lazy umounted and does not show up in
/proc/mounts anymore.

[kzak@redhat.com: - add MNT_DETACH macro fallback]

Signed-off-by: Harald Hoyer <harald@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-11-14 14:49:37 +01:00
Sami Kerola
0fbd4c8572 switch_root: add nls support
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-10-30 14:47:31 +01:00
Sami Kerola
ed8d2938f3 switch_root: align with howto-usage-function.txt
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-10-30 14:45:14 +01:00
Harald Hoyer
acb03ad46a switch_root: handle /run and do not mount over existing mounts
Handle /run just like /dev, /sys and /proc

Do not mount move, if there is already something mounted on the
destination folder.

Signed-off-by: Harald Hoyer <harald@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-10-20 12:27:35 +02:00
Fabian Groffen
eb76ca98b0 build-sys: provide alternatives for err, errx, warn and warnx
Solaris lacks err, errx, warn and warnx.  This also means the err.h header
doesn't exist.  Removed err.h include from all files, and included err.h from
c.h instead if it exists, otherwise alternatives are provided.

Signed-off-by: Fabian Groffen <grobian@gentoo.org>
2011-02-14 17:45:24 +01:00
Karel Zak
558417e8c8 Revert "switch_root: add subroot support"
This reverts commit a692a87459.

On Wed, Nov 18, 2009 at 03:33:12PM +0000, Daniel Drake wrote:
> Booting into a system this way just leads to problems because
> you cannot remount the root read-only at shutdown (leading to unclean
> shutdowns).

> Miklos Szeredi pointed out a trick to turn any directory into a
> mount point which avoids this problem. Therefore we can simplify
> switch_root again and simply document that its users should set
2009-11-20 15:11:59 +01:00
Karel Zak
532c6cb199 switch_root: remove TIOCSCTTY and setsid()
requested by dracut developers because:

   bash: cannot set terminal process group (-1): Inappropriate ioctl for device

Addresses-Red-Hat-Bug: #519237
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-10-09 15:17:54 +02:00
Daniel Drake
a692a87459 switch_root: add subroot support
The current switch_root can only switch to a new root that is the root
of a mount point.

This patch adds support for "subroots", where the new root is
somewhere below a mount point. It does this by adding in a few extra
steps to chroot into the subroot after the enclosing partition has
been moved and entered.

This will be used by OLPC, who sort-of have 2 copies of Fedora stored
on a single partition under different directory trees, where the
initramfs decides which one to boot into

[kzak@redhat.com:
    - port to the current u-l-ng switch_root code
    - don't use static buffer for "dir" in get_parent_mount()]

CC: Peter Jones <pjones@redhat.com>
Signed-off-by: Daniel Drake <dsd@laptop.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-07-14 14:41:33 +02:00
Peter Jones
2a7ccc65e9 switch_root: do recursiveRemove after our root is moved to avoid races.
This way there's no race between unlinking the /newroot directory and
the MS_MOVE/chroot() to get away from it.

Signed-off-by: Peter Jones <pjones@redhat.com>
2009-06-22 21:45:25 +02:00
Peter Jones
4c2d96e62a switch_root: fork before cleaning up the filesystem.
Fork before cleaning up the old filesystem, so it becomes asyncronous,
which results in a faster boot time.

Signed-off-by: Peter Jones <pjones@redhat.com>
2009-06-22 21:45:25 +02:00
Peter Jones
82476a9080 switch_root: use file descriptor instead of path for recursiveRemove()
This makes recursiveRemove() use fdopendir() instead of taking a path,
so we're always sure about which namespace we're starting from.

Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-06-22 21:38:12 +02:00
Karel Zak
8f24e52ed7 switch_root: use snprintf() rather tan str{cpy,cat}()
Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-06-22 21:30:47 +02:00
Karel Zak
8b6457d06a switch_root: clean up argv[] usage, add -h and -V
Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-06-22 21:30:47 +02:00
Karel Zak
fcb495b1df switch_root: use err.h, clean up return codes
Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-06-22 21:30:47 +02:00
Karel Zak
a6fc8b07f9 switch_root: rewrite to use fstatat() and unlinkat()
Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-06-22 21:30:47 +02:00
Karel Zak
3ddbe4d26b switch_root: fix coding style
Signed-off-by: Peter Jones <pjones@redhat.com>
Acked-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-06-22 21:30:47 +02:00
Karel Zak
711ea7307d switch_root: new command
Copied from Dracut project:
git://dracut.git.sourceforge.net/gitroot/dracut

switch_root history in dracut.git repository:

$ git shortlog switch_root.c
Harald Hoyer (5):
      replace switch_root shell script with binary
      add \n to switch_root
      use switch_root code from http://pjones.fedorapeople.org/mkstart/usr/lib/mkstart/switchroot.c
      mount move instead of umount and fix the search for fallback inits
      setsid() and set controlling terminal for real /sbin/init

Victor Lowther (2):
      Simplify switch_root.c a bit
      Remove all files on the initramfs before switching root

Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-06-22 21:30:46 +02:00