Blame view
init/do_mounts_initrd.c
3.53 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> |
e262e32d6 vfs: Suppress MS_... |
11 |
#include <uapi/linux/mount.h> |
1da177e4c Linux-2.6.12-rc2 |
12 13 14 15 16 17 |
#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 |
18 |
static int __initdata mount_initrd = 1; |
b1ab95c63 arch: Make phys_i... |
19 20 |
phys_addr_t phys_initrd_start __initdata; unsigned long phys_initrd_size __initdata; |
1da177e4c Linux-2.6.12-rc2 |
21 22 23 24 25 26 27 |
static int __init no_initrd(char *str) { mount_initrd = 0; return 1; } __setup("noinitrd", no_initrd); |
229c55ccb arch: Move initrd... |
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
static int __init early_initrd(char *p) { phys_addr_t start; unsigned long size; char *endp; start = memparse(p, &endp); if (*endp == ',') { size = memparse(endp + 1, NULL); phys_initrd_start = start; phys_initrd_size = size; } return 0; } early_param("initrd", early_initrd); |
ba4df2808 don't bother with... |
44 |
static int init_linuxrc(struct subprocess_info *info, struct cred *new) |
1da177e4c Linux-2.6.12-rc2 |
45 |
{ |
9b32105ec kernel: add ksys_... |
46 |
ksys_unshare(CLONE_FS | CLONE_FILES); |
43b168202 make sure that /l... |
47 |
/* stdin/stdout/stderr for /linuxrc */ |
bae217ea8 fs: add ksys_open... |
48 |
ksys_open("/dev/console", O_RDWR, 0); |
c7248321a fs: add ksys_dup{... |
49 50 |
ksys_dup(0); ksys_dup(0); |
ba4df2808 don't bother with... |
51 |
/* move initrd over / and chdir/chroot in initrd root */ |
447016e96 fs: add ksys_chdi... |
52 |
ksys_chdir("/root"); |
312db1aa1 fs: add ksys_moun... |
53 |
ksys_mount(".", "/", NULL, MS_MOVE, NULL); |
a16fe33ab fs: add ksys_chro... |
54 |
ksys_chroot("."); |
e2aaa9f42 kernel: add ksys_... |
55 |
ksys_setsid(); |
ba4df2808 don't bother with... |
56 |
return 0; |
1da177e4c Linux-2.6.12-rc2 |
57 58 59 60 |
} static void __init handle_initrd(void) { |
907ed1328 usermodehelper: s... |
61 |
struct subprocess_info *info; |
ba4df2808 don't bother with... |
62 63 |
static char *argv[] = { "linuxrc", NULL, }; extern char *envp_init[]; |
1da177e4c Linux-2.6.12-rc2 |
64 |
int error; |
1da177e4c Linux-2.6.12-rc2 |
65 66 |
real_root_dev = new_encode_dev(ROOT_DEV); |
bdaf85293 [PATCH] devfs: Re... |
67 |
create_dev("/dev/root.old", Root_RAM0); |
1da177e4c Linux-2.6.12-rc2 |
68 69 |
/* mount initrd on rootfs' /root */ mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY); |
0101db7a3 fs: add do_mkdira... |
70 |
ksys_mkdir("/old", 0700); |
447016e96 fs: add ksys_chdi... |
71 |
ksys_chdir("/old"); |
1da177e4c Linux-2.6.12-rc2 |
72 |
|
8baabde66 Freezer: Fix s2di... |
73 74 75 76 77 |
/* * 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... |
78 79 80 81 82 |
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... |
83 84 |
current->flags &= ~PF_FREEZER_SKIP; |
1da177e4c Linux-2.6.12-rc2 |
85 86 |
/* move initrd to rootfs' /old */ |
312db1aa1 fs: add ksys_moun... |
87 |
ksys_mount("..", ".", NULL, MS_MOVE, NULL); |
1da177e4c Linux-2.6.12-rc2 |
88 |
/* switch root and cwd back to / of rootfs */ |
a16fe33ab fs: add ksys_chro... |
89 |
ksys_chroot(".."); |
1da177e4c Linux-2.6.12-rc2 |
90 91 |
if (new_decode_dev(real_root_dev) == Root_RAM0) { |
447016e96 fs: add ksys_chdi... |
92 |
ksys_chdir("/old"); |
1da177e4c Linux-2.6.12-rc2 |
93 94 |
return; } |
447016e96 fs: add ksys_chdi... |
95 |
ksys_chdir("/"); |
1da177e4c Linux-2.6.12-rc2 |
96 97 98 99 |
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... |
100 |
error = ksys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL); |
1da177e4c Linux-2.6.12-rc2 |
101 102 103 104 |
if (!error) printk("okay "); else { |
bae217ea8 fs: add ksys_open... |
105 |
int fd = ksys_open("/dev/root.old", O_RDWR, 0); |
f220ab2a5 [PATCH] Improper ... |
106 107 108 109 110 111 |
if (error == -ENOENT) printk("/initrd does not exist. Ignored. "); else printk("failed "); |
1da177e4c Linux-2.6.12-rc2 |
112 113 |
printk(KERN_NOTICE "Unmounting old root "); |
3a18ef5c1 fs: add ksys_umou... |
114 |
ksys_umount("/old", MNT_DETACH); |
1da177e4c Linux-2.6.12-rc2 |
115 116 117 118 |
printk(KERN_NOTICE "Trying to free ramdisk memory ... "); if (fd < 0) { error = fd; } else { |
cbb60b924 fs: add ksys_ioct... |
119 |
error = ksys_ioctl(fd, BLKFLSBUF, 0); |
2ca2a09d6 fs: add ksys_clos... |
120 |
ksys_close(fd); |
1da177e4c Linux-2.6.12-rc2 |
121 122 123 124 125 126 |
} printk(!error ? "okay " : "failed "); } } |
f057f3b22 init/do_mounts: i... |
127 |
bool __init initrd_load(void) |
1da177e4c Linux-2.6.12-rc2 |
128 129 |
{ if (mount_initrd) { |
bdaf85293 [PATCH] devfs: Re... |
130 |
create_dev("/dev/ram", Root_RAM0); |
1da177e4c Linux-2.6.12-rc2 |
131 132 133 134 135 136 137 |
/* * 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... |
138 |
ksys_unlink("/initrd.image"); |
1da177e4c Linux-2.6.12-rc2 |
139 |
handle_initrd(); |
f057f3b22 init/do_mounts: i... |
140 |
return true; |
1da177e4c Linux-2.6.12-rc2 |
141 142 |
} } |
0f32ab8cf fs: add ksys_unli... |
143 |
ksys_unlink("/initrd.image"); |
f057f3b22 init/do_mounts: i... |
144 |
return false; |
1da177e4c Linux-2.6.12-rc2 |
145 |
} |