Blame view
init/do_mounts_initrd.c
3.21 KB
b24413180 License cleanup: ... |
1 |
// SPDX-License-Identifier: GPL-2.0 |
1da177e4c Linux-2.6.12-rc2 |
2 3 4 5 |
#include <linux/unistd.h> #include <linux/kernel.h> #include <linux/fs.h> #include <linux/minix_fs.h> |
1da177e4c Linux-2.6.12-rc2 |
6 7 8 |
#include <linux/romfs_fs.h> #include <linux/initrd.h> #include <linux/sched.h> |
7dfb71030 [PATCH] Add inclu... |
9 |
#include <linux/freezer.h> |
ba4df2808 don't bother with... |
10 |
#include <linux/kmod.h> |
1da177e4c Linux-2.6.12-rc2 |
11 12 13 14 15 16 |
#include "do_mounts.h" unsigned long initrd_start, initrd_end; int initrd_below_start_ok; unsigned int real_root_dev; /* do_proc_dointvec cannot handle kdev_t */ |
1da177e4c Linux-2.6.12-rc2 |
17 18 19 20 21 22 23 24 25 |
static int __initdata mount_initrd = 1; static int __init no_initrd(char *str) { mount_initrd = 0; return 1; } __setup("noinitrd", no_initrd); |
ba4df2808 don't bother with... |
26 |
static int init_linuxrc(struct subprocess_info *info, struct cred *new) |
1da177e4c Linux-2.6.12-rc2 |
27 |
{ |
9b32105ec kernel: add ksys_... |
28 |
ksys_unshare(CLONE_FS | CLONE_FILES); |
43b168202 make sure that /l... |
29 |
/* stdin/stdout/stderr for /linuxrc */ |
bae217ea8 fs: add ksys_open... |
30 |
ksys_open("/dev/console", O_RDWR, 0); |
c7248321a fs: add ksys_dup{... |
31 32 |
ksys_dup(0); ksys_dup(0); |
ba4df2808 don't bother with... |
33 |
/* move initrd over / and chdir/chroot in initrd root */ |
447016e96 fs: add ksys_chdi... |
34 |
ksys_chdir("/root"); |
312db1aa1 fs: add ksys_moun... |
35 |
ksys_mount(".", "/", NULL, MS_MOVE, NULL); |
a16fe33ab fs: add ksys_chro... |
36 |
ksys_chroot("."); |
e2aaa9f42 kernel: add ksys_... |
37 |
ksys_setsid(); |
ba4df2808 don't bother with... |
38 |
return 0; |
1da177e4c Linux-2.6.12-rc2 |
39 40 41 42 |
} static void __init handle_initrd(void) { |
907ed1328 usermodehelper: s... |
43 |
struct subprocess_info *info; |
ba4df2808 don't bother with... |
44 45 |
static char *argv[] = { "linuxrc", NULL, }; extern char *envp_init[]; |
1da177e4c Linux-2.6.12-rc2 |
46 |
int error; |
1da177e4c Linux-2.6.12-rc2 |
47 48 |
real_root_dev = new_encode_dev(ROOT_DEV); |
bdaf85293 [PATCH] devfs: Re... |
49 |
create_dev("/dev/root.old", Root_RAM0); |
1da177e4c Linux-2.6.12-rc2 |
50 51 |
/* mount initrd on rootfs' /root */ mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY); |
0101db7a3 fs: add do_mkdira... |
52 |
ksys_mkdir("/old", 0700); |
447016e96 fs: add ksys_chdi... |
53 |
ksys_chdir("/old"); |
1da177e4c Linux-2.6.12-rc2 |
54 |
|
bb813f4c9 init, block: try ... |
55 56 |
/* try loading default modules from initrd */ load_default_modules(); |
8baabde66 Freezer: Fix s2di... |
57 58 59 60 61 |
/* * In case that a resume from disk is carried out by linuxrc or one of * its children, we need to tell the freezer not to wait for us. */ current->flags |= PF_FREEZER_SKIP; |
907ed1328 usermodehelper: s... |
62 63 64 65 66 |
info = call_usermodehelper_setup("/linuxrc", argv, envp_init, GFP_KERNEL, init_linuxrc, NULL, NULL); if (!info) return; call_usermodehelper_exec(info, UMH_WAIT_PROC); |
8baabde66 Freezer: Fix s2di... |
67 68 |
current->flags &= ~PF_FREEZER_SKIP; |
1da177e4c Linux-2.6.12-rc2 |
69 70 |
/* move initrd to rootfs' /old */ |
312db1aa1 fs: add ksys_moun... |
71 |
ksys_mount("..", ".", NULL, MS_MOVE, NULL); |
1da177e4c Linux-2.6.12-rc2 |
72 |
/* switch root and cwd back to / of rootfs */ |
a16fe33ab fs: add ksys_chro... |
73 |
ksys_chroot(".."); |
1da177e4c Linux-2.6.12-rc2 |
74 75 |
if (new_decode_dev(real_root_dev) == Root_RAM0) { |
447016e96 fs: add ksys_chdi... |
76 |
ksys_chdir("/old"); |
1da177e4c Linux-2.6.12-rc2 |
77 78 |
return; } |
447016e96 fs: add ksys_chdi... |
79 |
ksys_chdir("/"); |
1da177e4c Linux-2.6.12-rc2 |
80 81 82 83 |
ROOT_DEV = new_decode_dev(real_root_dev); mount_root(); printk(KERN_NOTICE "Trying to move old root to /initrd ... "); |
312db1aa1 fs: add ksys_moun... |
84 |
error = ksys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL); |
1da177e4c Linux-2.6.12-rc2 |
85 86 87 88 |
if (!error) printk("okay "); else { |
bae217ea8 fs: add ksys_open... |
89 |
int fd = ksys_open("/dev/root.old", O_RDWR, 0); |
f220ab2a5 [PATCH] Improper ... |
90 91 92 93 94 95 |
if (error == -ENOENT) printk("/initrd does not exist. Ignored. "); else printk("failed "); |
1da177e4c Linux-2.6.12-rc2 |
96 97 |
printk(KERN_NOTICE "Unmounting old root "); |
3a18ef5c1 fs: add ksys_umou... |
98 |
ksys_umount("/old", MNT_DETACH); |
1da177e4c Linux-2.6.12-rc2 |
99 100 101 102 |
printk(KERN_NOTICE "Trying to free ramdisk memory ... "); if (fd < 0) { error = fd; } else { |
cbb60b924 fs: add ksys_ioct... |
103 |
error = ksys_ioctl(fd, BLKFLSBUF, 0); |
2ca2a09d6 fs: add ksys_clos... |
104 |
ksys_close(fd); |
1da177e4c Linux-2.6.12-rc2 |
105 106 107 108 109 110 |
} printk(!error ? "okay " : "failed "); } } |
f057f3b22 init/do_mounts: i... |
111 |
bool __init initrd_load(void) |
1da177e4c Linux-2.6.12-rc2 |
112 113 |
{ if (mount_initrd) { |
bdaf85293 [PATCH] devfs: Re... |
114 |
create_dev("/dev/ram", Root_RAM0); |
1da177e4c Linux-2.6.12-rc2 |
115 116 117 118 119 120 121 |
/* * Load the initrd data into /dev/ram0. Execute it as initrd * unless /dev/ram0 is supposed to be our actual root device, * in that case the ram disk is just set up here, and gets * mounted in the normal path. */ if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) { |
0f32ab8cf fs: add ksys_unli... |
122 |
ksys_unlink("/initrd.image"); |
1da177e4c Linux-2.6.12-rc2 |
123 |
handle_initrd(); |
f057f3b22 init/do_mounts: i... |
124 |
return true; |
1da177e4c Linux-2.6.12-rc2 |
125 126 |
} } |
0f32ab8cf fs: add ksys_unli... |
127 |
ksys_unlink("/initrd.image"); |
f057f3b22 init/do_mounts: i... |
128 |
return false; |
1da177e4c Linux-2.6.12-rc2 |
129 |
} |