1c67e5382SH Hartley Sweeten /* 2c67e5382SH Hartley Sweeten * Many of the syscalls used in this file expect some of the arguments 3c67e5382SH Hartley Sweeten * to be __user pointers not __kernel pointers. To limit the sparse 4c67e5382SH Hartley Sweeten * noise, turn off sparse checking for this file. 5c67e5382SH Hartley Sweeten */ 6c67e5382SH Hartley Sweeten #ifdef __CHECKER__ 7c67e5382SH Hartley Sweeten #undef __CHECKER__ 8c67e5382SH Hartley Sweeten #warning "Sparse checking disabled for this file" 9c67e5382SH Hartley Sweeten #endif 10c67e5382SH Hartley Sweeten 111da177e4SLinus Torvalds #include <linux/module.h> 121da177e4SLinus Torvalds #include <linux/sched.h> 131da177e4SLinus Torvalds #include <linux/ctype.h> 141da177e4SLinus Torvalds #include <linux/fd.h> 151da177e4SLinus Torvalds #include <linux/tty.h> 161da177e4SLinus Torvalds #include <linux/suspend.h> 171da177e4SLinus Torvalds #include <linux/root_dev.h> 181da177e4SLinus Torvalds #include <linux/security.h> 191da177e4SLinus Torvalds #include <linux/delay.h> 20dd2a345fSDave Gilbert #include <linux/genhd.h> 21d53d9f16SAndrew Morton #include <linux/mount.h> 22d779249eSGreg Kroah-Hartman #include <linux/device.h> 2346595390SAdrian Bunk #include <linux/init.h> 24011e3fcdSAdrian Bunk #include <linux/fs.h> 2582c8253aSAdrian Bunk #include <linux/initrd.h> 2622a9d645SArjan van de Ven #include <linux/async.h> 275ad4e53bSAl Viro #include <linux/fs_struct.h> 285a0e3ad6STejun Heo #include <linux/slab.h> 2957f150a5SRob Landley #include <linux/ramfs.h> 3016203a7aSRob Landley #include <linux/shmem_fs.h> 311da177e4SLinus Torvalds 321da177e4SLinus Torvalds #include <linux/nfs_fs.h> 331da177e4SLinus Torvalds #include <linux/nfs_fs_sb.h> 341da177e4SLinus Torvalds #include <linux/nfs_mount.h> 351da177e4SLinus Torvalds 361da177e4SLinus Torvalds #include "do_mounts.h" 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds int __initdata rd_doload; /* 1 = load RAM disk, 0 = don't load */ 391da177e4SLinus Torvalds 409b04c997STheodore Ts'o int root_mountflags = MS_RDONLY | MS_SILENT; 41f56f6d30SAdrian Bunk static char * __initdata root_device_name; 421da177e4SLinus Torvalds static char __initdata saved_root_name[64]; 4379975f13SWill Drewry static int root_wait; 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds dev_t ROOT_DEV; 461da177e4SLinus Torvalds 471da177e4SLinus Torvalds static int __init load_ramdisk(char *str) 481da177e4SLinus Torvalds { 491da177e4SLinus Torvalds rd_doload = simple_strtol(str,NULL,0) & 3; 501da177e4SLinus Torvalds return 1; 511da177e4SLinus Torvalds } 521da177e4SLinus Torvalds __setup("load_ramdisk=", load_ramdisk); 531da177e4SLinus Torvalds 541da177e4SLinus Torvalds static int __init readonly(char *str) 551da177e4SLinus Torvalds { 561da177e4SLinus Torvalds if (*str) 571da177e4SLinus Torvalds return 0; 581da177e4SLinus Torvalds root_mountflags |= MS_RDONLY; 591da177e4SLinus Torvalds return 1; 601da177e4SLinus Torvalds } 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds static int __init readwrite(char *str) 631da177e4SLinus Torvalds { 641da177e4SLinus Torvalds if (*str) 651da177e4SLinus Torvalds return 0; 661da177e4SLinus Torvalds root_mountflags &= ~MS_RDONLY; 671da177e4SLinus Torvalds return 1; 681da177e4SLinus Torvalds } 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds __setup("ro", readonly); 711da177e4SLinus Torvalds __setup("rw", readwrite); 721da177e4SLinus Torvalds 736d0aed7aSJens Axboe #ifdef CONFIG_BLOCK 741ad7e899SStephen Warren struct uuidcmp { 751ad7e899SStephen Warren const char *uuid; 761ad7e899SStephen Warren int len; 771ad7e899SStephen Warren }; 781ad7e899SStephen Warren 79b5af921eSWill Drewry /** 80b5af921eSWill Drewry * match_dev_by_uuid - callback for finding a partition using its uuid 81b5af921eSWill Drewry * @dev: device passed in by the caller 821ad7e899SStephen Warren * @data: opaque pointer to the desired struct uuidcmp to match 83b5af921eSWill Drewry * 84b5af921eSWill Drewry * Returns 1 if the device matches, and 0 otherwise. 85b5af921eSWill Drewry */ 869f3b795aSMichał Mirosław static int match_dev_by_uuid(struct device *dev, const void *data) 87b5af921eSWill Drewry { 889f3b795aSMichał Mirosław const struct uuidcmp *cmp = data; 89b5af921eSWill Drewry struct hd_struct *part = dev_to_part(dev); 90b5af921eSWill Drewry 91b5af921eSWill Drewry if (!part->info) 92b5af921eSWill Drewry goto no_match; 93b5af921eSWill Drewry 941ad7e899SStephen Warren if (strncasecmp(cmp->uuid, part->info->uuid, cmp->len)) 95b5af921eSWill Drewry goto no_match; 96b5af921eSWill Drewry 97b5af921eSWill Drewry return 1; 98b5af921eSWill Drewry no_match: 99b5af921eSWill Drewry return 0; 100b5af921eSWill Drewry } 101b5af921eSWill Drewry 102b5af921eSWill Drewry 103b5af921eSWill Drewry /** 104b5af921eSWill Drewry * devt_from_partuuid - looks up the dev_t of a partition by its UUID 105a68b3108Schishanmingshen * @uuid_str: char array containing ascii UUID 106b5af921eSWill Drewry * 107b5af921eSWill Drewry * The function will return the first partition which contains a matching 108b5af921eSWill Drewry * UUID value in its partition_meta_info struct. This does not search 109b5af921eSWill Drewry * by filesystem UUIDs. 110b5af921eSWill Drewry * 111a68b3108Schishanmingshen * If @uuid_str is followed by a "/PARTNROFF=%d", then the number will be 11279975f13SWill Drewry * extracted and used as an offset from the partition identified by the UUID. 11379975f13SWill Drewry * 114b5af921eSWill Drewry * Returns the matching dev_t on success or 0 on failure. 115b5af921eSWill Drewry */ 1161ad7e899SStephen Warren static dev_t devt_from_partuuid(const char *uuid_str) 117b5af921eSWill Drewry { 118b5af921eSWill Drewry dev_t res = 0; 1191ad7e899SStephen Warren struct uuidcmp cmp; 120b5af921eSWill Drewry struct device *dev = NULL; 12179975f13SWill Drewry struct gendisk *disk; 12279975f13SWill Drewry struct hd_struct *part; 12379975f13SWill Drewry int offset = 0; 124283f8fc0SStephen Warren bool clear_root_wait = false; 125283f8fc0SStephen Warren char *slash; 12679975f13SWill Drewry 1271ad7e899SStephen Warren cmp.uuid = uuid_str; 1281ad7e899SStephen Warren 129283f8fc0SStephen Warren slash = strchr(uuid_str, '/'); 13079975f13SWill Drewry /* Check for optional partition number offset attributes. */ 131283f8fc0SStephen Warren if (slash) { 13279975f13SWill Drewry char c = 0; 13379975f13SWill Drewry /* Explicitly fail on poor PARTUUID syntax. */ 134283f8fc0SStephen Warren if (sscanf(slash + 1, 135283f8fc0SStephen Warren "PARTNROFF=%d%c", &offset, &c) != 1) { 136283f8fc0SStephen Warren clear_root_wait = true; 13779975f13SWill Drewry goto done; 13879975f13SWill Drewry } 139283f8fc0SStephen Warren cmp.len = slash - uuid_str; 140283f8fc0SStephen Warren } else { 141283f8fc0SStephen Warren cmp.len = strlen(uuid_str); 142283f8fc0SStephen Warren } 143283f8fc0SStephen Warren 144283f8fc0SStephen Warren if (!cmp.len) { 145283f8fc0SStephen Warren clear_root_wait = true; 146283f8fc0SStephen Warren goto done; 14779975f13SWill Drewry } 148b5af921eSWill Drewry 1491ad7e899SStephen Warren dev = class_find_device(&block_class, NULL, &cmp, 1501ad7e899SStephen Warren &match_dev_by_uuid); 151b5af921eSWill Drewry if (!dev) 152b5af921eSWill Drewry goto done; 153b5af921eSWill Drewry 154b5af921eSWill Drewry res = dev->devt; 155b5af921eSWill Drewry 15679975f13SWill Drewry /* Attempt to find the partition by offset. */ 15779975f13SWill Drewry if (!offset) 15879975f13SWill Drewry goto no_offset; 15979975f13SWill Drewry 16079975f13SWill Drewry res = 0; 16179975f13SWill Drewry disk = part_to_disk(dev_to_part(dev)); 16279975f13SWill Drewry part = disk_get_part(disk, dev_to_part(dev)->partno + offset); 16379975f13SWill Drewry if (part) { 16479975f13SWill Drewry res = part_devt(part); 16579975f13SWill Drewry put_device(part_to_dev(part)); 16679975f13SWill Drewry } 16779975f13SWill Drewry 16879975f13SWill Drewry no_offset: 16979975f13SWill Drewry put_device(dev); 170b5af921eSWill Drewry done: 171283f8fc0SStephen Warren if (clear_root_wait) { 172283f8fc0SStephen Warren pr_err("VFS: PARTUUID= is invalid.\n" 173283f8fc0SStephen Warren "Expected PARTUUID=<valid-uuid-id>[/PARTNROFF=%%d]\n"); 174283f8fc0SStephen Warren if (root_wait) 175283f8fc0SStephen Warren pr_err("Disabling rootwait; root= is invalid.\n"); 176283f8fc0SStephen Warren root_wait = 0; 177283f8fc0SStephen Warren } 178b5af921eSWill Drewry return res; 179b5af921eSWill Drewry } 1806d0aed7aSJens Axboe #endif 181b5af921eSWill Drewry 1821da177e4SLinus Torvalds /* 1831da177e4SLinus Torvalds * Convert a name into device number. We accept the following variants: 1841da177e4SLinus Torvalds * 1850bf37ae4SPavel Machek * 1) <hex_major><hex_minor> device number in hexadecimal represents itself 1860bf37ae4SPavel Machek * no leading 0x, for example b302. 1871da177e4SLinus Torvalds * 2) /dev/nfs represents Root_NFS (0xff) 1881da177e4SLinus Torvalds * 3) /dev/<disk_name> represents the device number of disk 1891da177e4SLinus Torvalds * 4) /dev/<disk_name><decimal> represents the device number 1901da177e4SLinus Torvalds * of partition - device number of disk plus the partition number 1911da177e4SLinus Torvalds * 5) /dev/<disk_name>p<decimal> - same as the above, that form is 1921da177e4SLinus Torvalds * used when disk name of partitioned disk ends on a digit. 193b5af921eSWill Drewry * 6) PARTUUID=00112233-4455-6677-8899-AABBCCDDEEFF representing the 194b5af921eSWill Drewry * unique id of a partition if the partition table provides it. 195d33b98fcSStephen Warren * The UUID may be either an EFI/GPT UUID, or refer to an MSDOS 196d33b98fcSStephen Warren * partition using the format SSSSSSSS-PP, where SSSSSSSS is a zero- 197d33b98fcSStephen Warren * filled hex representation of the 32-bit "NT disk signature", and PP 198d33b98fcSStephen Warren * is a zero-filled hex representation of the 1-based partition number. 19979975f13SWill Drewry * 7) PARTUUID=<UUID>/PARTNROFF=<int> to select a partition in relation to 20079975f13SWill Drewry * a partition with a known unique id. 2016c251611SSebastian Capella * 8) <major>:<minor> major and minor number of the device separated by 2026c251611SSebastian Capella * a colon. 2031da177e4SLinus Torvalds * 204edfaa7c3SKay Sievers * If name doesn't have fall into the categories above, we return (0,0). 205edfaa7c3SKay Sievers * block_class is used to check if something is a disk name. If the disk 206edfaa7c3SKay Sievers * name contains slashes, the device name has them replaced with 207edfaa7c3SKay Sievers * bangs. 2081da177e4SLinus Torvalds */ 2091da177e4SLinus Torvalds 2101da177e4SLinus Torvalds dev_t name_to_dev_t(char *name) 2111da177e4SLinus Torvalds { 2121da177e4SLinus Torvalds char s[32]; 2131da177e4SLinus Torvalds char *p; 2141da177e4SLinus Torvalds dev_t res = 0; 21530f2f0ebSKay Sievers int part; 2161da177e4SLinus Torvalds 2176d0aed7aSJens Axboe #ifdef CONFIG_BLOCK 218b5af921eSWill Drewry if (strncmp(name, "PARTUUID=", 9) == 0) { 219b5af921eSWill Drewry name += 9; 220b5af921eSWill Drewry res = devt_from_partuuid(name); 221b5af921eSWill Drewry if (!res) 222b5af921eSWill Drewry goto fail; 223b5af921eSWill Drewry goto done; 224b5af921eSWill Drewry } 2256d0aed7aSJens Axboe #endif 226b5af921eSWill Drewry 2271da177e4SLinus Torvalds if (strncmp(name, "/dev/", 5) != 0) { 2281da177e4SLinus Torvalds unsigned maj, min; 2291da177e4SLinus Torvalds 2301da177e4SLinus Torvalds if (sscanf(name, "%u:%u", &maj, &min) == 2) { 2311da177e4SLinus Torvalds res = MKDEV(maj, min); 2321da177e4SLinus Torvalds if (maj != MAJOR(res) || min != MINOR(res)) 2331da177e4SLinus Torvalds goto fail; 2341da177e4SLinus Torvalds } else { 2351da177e4SLinus Torvalds res = new_decode_dev(simple_strtoul(name, &p, 16)); 2361da177e4SLinus Torvalds if (*p) 2371da177e4SLinus Torvalds goto fail; 2381da177e4SLinus Torvalds } 2391da177e4SLinus Torvalds goto done; 2401da177e4SLinus Torvalds } 241edfaa7c3SKay Sievers 2421da177e4SLinus Torvalds name += 5; 2431da177e4SLinus Torvalds res = Root_NFS; 2441da177e4SLinus Torvalds if (strcmp(name, "nfs") == 0) 2451da177e4SLinus Torvalds goto done; 2461da177e4SLinus Torvalds res = Root_RAM0; 2471da177e4SLinus Torvalds if (strcmp(name, "ram") == 0) 2481da177e4SLinus Torvalds goto done; 2491da177e4SLinus Torvalds 2501da177e4SLinus Torvalds if (strlen(name) > 31) 2511da177e4SLinus Torvalds goto fail; 2521da177e4SLinus Torvalds strcpy(s, name); 2531da177e4SLinus Torvalds for (p = s; *p; p++) 2541da177e4SLinus Torvalds if (*p == '/') 2551da177e4SLinus Torvalds *p = '!'; 25630f2f0ebSKay Sievers res = blk_lookup_devt(s, 0); 25730f2f0ebSKay Sievers if (res) 25830f2f0ebSKay Sievers goto done; 25930f2f0ebSKay Sievers 26030f2f0ebSKay Sievers /* 26125985edcSLucas De Marchi * try non-existent, but valid partition, which may only exist 26230f2f0ebSKay Sievers * after revalidating the disk, like partitioned md devices 26330f2f0ebSKay Sievers */ 26430f2f0ebSKay Sievers while (p > s && isdigit(p[-1])) 26530f2f0ebSKay Sievers p--; 26630f2f0ebSKay Sievers if (p == s || !*p || *p == '0') 26730f2f0ebSKay Sievers goto fail; 26830f2f0ebSKay Sievers 26930f2f0ebSKay Sievers /* try disk name without <part number> */ 27030f2f0ebSKay Sievers part = simple_strtoul(p, NULL, 10); 27130f2f0ebSKay Sievers *p = '\0'; 27230f2f0ebSKay Sievers res = blk_lookup_devt(s, part); 27330f2f0ebSKay Sievers if (res) 27430f2f0ebSKay Sievers goto done; 27530f2f0ebSKay Sievers 27630f2f0ebSKay Sievers /* try disk name without p<part number> */ 27730f2f0ebSKay Sievers if (p < s + 2 || !isdigit(p[-2]) || p[-1] != 'p') 27830f2f0ebSKay Sievers goto fail; 27930f2f0ebSKay Sievers p[-1] = '\0'; 28030f2f0ebSKay Sievers res = blk_lookup_devt(s, part); 2811da177e4SLinus Torvalds if (res) 2821da177e4SLinus Torvalds goto done; 2831da177e4SLinus Torvalds 2841da177e4SLinus Torvalds fail: 285edfaa7c3SKay Sievers return 0; 286edfaa7c3SKay Sievers done: 287edfaa7c3SKay Sievers return res; 2881da177e4SLinus Torvalds } 2891da177e4SLinus Torvalds 2901da177e4SLinus Torvalds static int __init root_dev_setup(char *line) 2911da177e4SLinus Torvalds { 2921da177e4SLinus Torvalds strlcpy(saved_root_name, line, sizeof(saved_root_name)); 2931da177e4SLinus Torvalds return 1; 2941da177e4SLinus Torvalds } 2951da177e4SLinus Torvalds 2961da177e4SLinus Torvalds __setup("root=", root_dev_setup); 2971da177e4SLinus Torvalds 298cc1ed754SPierre Ossman static int __init rootwait_setup(char *str) 299cc1ed754SPierre Ossman { 300cc1ed754SPierre Ossman if (*str) 301cc1ed754SPierre Ossman return 0; 302cc1ed754SPierre Ossman root_wait = 1; 303cc1ed754SPierre Ossman return 1; 304cc1ed754SPierre Ossman } 305cc1ed754SPierre Ossman 306cc1ed754SPierre Ossman __setup("rootwait", rootwait_setup); 307cc1ed754SPierre Ossman 3081da177e4SLinus Torvalds static char * __initdata root_mount_data; 3091da177e4SLinus Torvalds static int __init root_data_setup(char *str) 3101da177e4SLinus Torvalds { 3111da177e4SLinus Torvalds root_mount_data = str; 3121da177e4SLinus Torvalds return 1; 3131da177e4SLinus Torvalds } 3141da177e4SLinus Torvalds 3151da177e4SLinus Torvalds static char * __initdata root_fs_names; 3161da177e4SLinus Torvalds static int __init fs_names_setup(char *str) 3171da177e4SLinus Torvalds { 3181da177e4SLinus Torvalds root_fs_names = str; 3191da177e4SLinus Torvalds return 1; 3201da177e4SLinus Torvalds } 3211da177e4SLinus Torvalds 3221da177e4SLinus Torvalds static unsigned int __initdata root_delay; 3231da177e4SLinus Torvalds static int __init root_delay_setup(char *str) 3241da177e4SLinus Torvalds { 3251da177e4SLinus Torvalds root_delay = simple_strtoul(str, NULL, 0); 3261da177e4SLinus Torvalds return 1; 3271da177e4SLinus Torvalds } 3281da177e4SLinus Torvalds 3291da177e4SLinus Torvalds __setup("rootflags=", root_data_setup); 3301da177e4SLinus Torvalds __setup("rootfstype=", fs_names_setup); 3311da177e4SLinus Torvalds __setup("rootdelay=", root_delay_setup); 3321da177e4SLinus Torvalds 3331da177e4SLinus Torvalds static void __init get_fs_names(char *page) 3341da177e4SLinus Torvalds { 3351da177e4SLinus Torvalds char *s = page; 3361da177e4SLinus Torvalds 3371da177e4SLinus Torvalds if (root_fs_names) { 3381da177e4SLinus Torvalds strcpy(page, root_fs_names); 3391da177e4SLinus Torvalds while (*s++) { 3401da177e4SLinus Torvalds if (s[-1] == ',') 3411da177e4SLinus Torvalds s[-1] = '\0'; 3421da177e4SLinus Torvalds } 3431da177e4SLinus Torvalds } else { 3441da177e4SLinus Torvalds int len = get_filesystem_list(page); 3451da177e4SLinus Torvalds char *p, *next; 3461da177e4SLinus Torvalds 3471da177e4SLinus Torvalds page[len] = '\0'; 3481da177e4SLinus Torvalds for (p = page-1; p; p = next) { 3491da177e4SLinus Torvalds next = strchr(++p, '\n'); 3501da177e4SLinus Torvalds if (*p++ != '\t') 3511da177e4SLinus Torvalds continue; 3521da177e4SLinus Torvalds while ((*s++ = *p++) != '\n') 3531da177e4SLinus Torvalds ; 3541da177e4SLinus Torvalds s[-1] = '\0'; 3551da177e4SLinus Torvalds } 3561da177e4SLinus Torvalds } 3571da177e4SLinus Torvalds *s = '\0'; 3581da177e4SLinus Torvalds } 3591da177e4SLinus Torvalds 3601da177e4SLinus Torvalds static int __init do_mount_root(char *name, char *fs, int flags, void *data) 3611da177e4SLinus Torvalds { 362d8c9584eSAl Viro struct super_block *s; 3631da177e4SLinus Torvalds int err = sys_mount(name, "/root", fs, flags, data); 3641da177e4SLinus Torvalds if (err) 3651da177e4SLinus Torvalds return err; 3661da177e4SLinus Torvalds 367c67e5382SH Hartley Sweeten sys_chdir("/root"); 368d8c9584eSAl Viro s = current->fs->pwd.dentry->d_sb; 369d8c9584eSAl Viro ROOT_DEV = s->s_dev; 37080cdc6daSMandeep Singh Baines printk(KERN_INFO 37180cdc6daSMandeep Singh Baines "VFS: Mounted root (%s filesystem)%s on device %u:%u.\n", 372d8c9584eSAl Viro s->s_type->name, 373d8c9584eSAl Viro s->s_flags & MS_RDONLY ? " readonly" : "", 374d8c9584eSAl Viro MAJOR(ROOT_DEV), MINOR(ROOT_DEV)); 3751da177e4SLinus Torvalds return 0; 3761da177e4SLinus Torvalds } 3771da177e4SLinus Torvalds 3781da177e4SLinus Torvalds void __init mount_block_root(char *name, int flags) 3791da177e4SLinus Torvalds { 380a608ca21SJeff Layton struct page *page = alloc_page(GFP_KERNEL | 381a608ca21SJeff Layton __GFP_NOTRACK_FALSE_POSITIVE); 382a608ca21SJeff Layton char *fs_names = page_address(page); 3831da177e4SLinus Torvalds char *p; 3849361401eSDavid Howells #ifdef CONFIG_BLOCK 3851da177e4SLinus Torvalds char b[BDEVNAME_SIZE]; 3869361401eSDavid Howells #else 3879361401eSDavid Howells const char *b = name; 3889361401eSDavid Howells #endif 3891da177e4SLinus Torvalds 3901da177e4SLinus Torvalds get_fs_names(fs_names); 3911da177e4SLinus Torvalds retry: 3921da177e4SLinus Torvalds for (p = fs_names; *p; p += strlen(p)+1) { 3931da177e4SLinus Torvalds int err = do_mount_root(name, p, flags, root_mount_data); 3941da177e4SLinus Torvalds switch (err) { 3951da177e4SLinus Torvalds case 0: 3961da177e4SLinus Torvalds goto out; 3971da177e4SLinus Torvalds case -EACCES: 3981da177e4SLinus Torvalds case -EINVAL: 3991da177e4SLinus Torvalds continue; 4001da177e4SLinus Torvalds } 4011da177e4SLinus Torvalds /* 4021da177e4SLinus Torvalds * Allow the user to distinguish between failed sys_open 4031da177e4SLinus Torvalds * and bad superblock on root device. 404dd2a345fSDave Gilbert * and give them a list of the available devices 4051da177e4SLinus Torvalds */ 4069361401eSDavid Howells #ifdef CONFIG_BLOCK 4071da177e4SLinus Torvalds __bdevname(ROOT_DEV, b); 4089361401eSDavid Howells #endif 4090e0cb892SBernhard Walle printk("VFS: Cannot open root device \"%s\" or %s: error %d\n", 4100e0cb892SBernhard Walle root_device_name, b, err); 411dd2a345fSDave Gilbert printk("Please append a correct \"root=\" boot option; here are the available partitions:\n"); 4121da177e4SLinus Torvalds 413dd2a345fSDave Gilbert printk_all_partitions(); 41455dc7db7STejun Heo #ifdef CONFIG_DEBUG_BLOCK_EXT_DEVT 41555dc7db7STejun Heo printk("DEBUG_BLOCK_EXT_DEVT is enabled, you need to specify " 41655dc7db7STejun Heo "explicit textual name for \"root=\" boot option.\n"); 41755dc7db7STejun Heo #endif 4181da177e4SLinus Torvalds panic("VFS: Unable to mount root fs on %s", b); 4191da177e4SLinus Torvalds } 42010975933SMiklos Szeredi if (!(flags & MS_RDONLY)) { 42110975933SMiklos Szeredi flags |= MS_RDONLY; 42210975933SMiklos Szeredi goto retry; 42310975933SMiklos Szeredi } 424be6e028bSAndy Whitcroft 425dd2a345fSDave Gilbert printk("List of all partitions:\n"); 426dd2a345fSDave Gilbert printk_all_partitions(); 427be6e028bSAndy Whitcroft printk("No filesystem could mount root, tried: "); 428be6e028bSAndy Whitcroft for (p = fs_names; *p; p += strlen(p)+1) 429be6e028bSAndy Whitcroft printk(" %s", p); 430be6e028bSAndy Whitcroft printk("\n"); 4319361401eSDavid Howells #ifdef CONFIG_BLOCK 4329361401eSDavid Howells __bdevname(ROOT_DEV, b); 4339361401eSDavid Howells #endif 4349361401eSDavid Howells panic("VFS: Unable to mount root fs on %s", b); 4351da177e4SLinus Torvalds out: 436a608ca21SJeff Layton put_page(page); 4371da177e4SLinus Torvalds } 4381da177e4SLinus Torvalds 4391da177e4SLinus Torvalds #ifdef CONFIG_ROOT_NFS 44043717c7dSChuck Lever 44143717c7dSChuck Lever #define NFSROOT_TIMEOUT_MIN 5 44243717c7dSChuck Lever #define NFSROOT_TIMEOUT_MAX 30 44343717c7dSChuck Lever #define NFSROOT_RETRY_MAX 5 44443717c7dSChuck Lever 4451da177e4SLinus Torvalds static int __init mount_nfs_root(void) 4461da177e4SLinus Torvalds { 44756463e50SChuck Lever char *root_dev, *root_data; 44843717c7dSChuck Lever unsigned int timeout; 44943717c7dSChuck Lever int try, err; 4501da177e4SLinus Torvalds 45143717c7dSChuck Lever err = nfs_root_data(&root_dev, &root_data); 45243717c7dSChuck Lever if (err != 0) 4531da177e4SLinus Torvalds return 0; 45443717c7dSChuck Lever 45543717c7dSChuck Lever /* 45643717c7dSChuck Lever * The server or network may not be ready, so try several 45743717c7dSChuck Lever * times. Stop after a few tries in case the client wants 45843717c7dSChuck Lever * to fall back to other boot methods. 45943717c7dSChuck Lever */ 46043717c7dSChuck Lever timeout = NFSROOT_TIMEOUT_MIN; 46143717c7dSChuck Lever for (try = 1; ; try++) { 46243717c7dSChuck Lever err = do_mount_root(root_dev, "nfs", 46343717c7dSChuck Lever root_mountflags, root_data); 46443717c7dSChuck Lever if (err == 0) 46556463e50SChuck Lever return 1; 46643717c7dSChuck Lever if (try > NFSROOT_RETRY_MAX) 46743717c7dSChuck Lever break; 46843717c7dSChuck Lever 46943717c7dSChuck Lever /* Wait, in case the server refused us immediately */ 47043717c7dSChuck Lever ssleep(timeout); 47143717c7dSChuck Lever timeout <<= 1; 47243717c7dSChuck Lever if (timeout > NFSROOT_TIMEOUT_MAX) 47343717c7dSChuck Lever timeout = NFSROOT_TIMEOUT_MAX; 47443717c7dSChuck Lever } 47543717c7dSChuck Lever return 0; 4761da177e4SLinus Torvalds } 4771da177e4SLinus Torvalds #endif 4781da177e4SLinus Torvalds 4791da177e4SLinus Torvalds #if defined(CONFIG_BLK_DEV_RAM) || defined(CONFIG_BLK_DEV_FD) 4801da177e4SLinus Torvalds void __init change_floppy(char *fmt, ...) 4811da177e4SLinus Torvalds { 4821da177e4SLinus Torvalds struct termios termios; 4831da177e4SLinus Torvalds char buf[80]; 4841da177e4SLinus Torvalds char c; 4851da177e4SLinus Torvalds int fd; 4861da177e4SLinus Torvalds va_list args; 4871da177e4SLinus Torvalds va_start(args, fmt); 4881da177e4SLinus Torvalds vsprintf(buf, fmt, args); 4891da177e4SLinus Torvalds va_end(args); 4901da177e4SLinus Torvalds fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0); 4911da177e4SLinus Torvalds if (fd >= 0) { 4921da177e4SLinus Torvalds sys_ioctl(fd, FDEJECT, 0); 4931da177e4SLinus Torvalds sys_close(fd); 4941da177e4SLinus Torvalds } 4951da177e4SLinus Torvalds printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf); 4961da177e4SLinus Torvalds fd = sys_open("/dev/console", O_RDWR, 0); 4971da177e4SLinus Torvalds if (fd >= 0) { 4981da177e4SLinus Torvalds sys_ioctl(fd, TCGETS, (long)&termios); 4991da177e4SLinus Torvalds termios.c_lflag &= ~ICANON; 5001da177e4SLinus Torvalds sys_ioctl(fd, TCSETSF, (long)&termios); 5011da177e4SLinus Torvalds sys_read(fd, &c, 1); 5021da177e4SLinus Torvalds termios.c_lflag |= ICANON; 5031da177e4SLinus Torvalds sys_ioctl(fd, TCSETSF, (long)&termios); 5041da177e4SLinus Torvalds sys_close(fd); 5051da177e4SLinus Torvalds } 5061da177e4SLinus Torvalds } 5071da177e4SLinus Torvalds #endif 5081da177e4SLinus Torvalds 5091da177e4SLinus Torvalds void __init mount_root(void) 5101da177e4SLinus Torvalds { 5111da177e4SLinus Torvalds #ifdef CONFIG_ROOT_NFS 512377485f6SSasha Levin if (ROOT_DEV == Root_NFS) { 5131da177e4SLinus Torvalds if (mount_nfs_root()) 5141da177e4SLinus Torvalds return; 5151da177e4SLinus Torvalds 5161da177e4SLinus Torvalds printk(KERN_ERR "VFS: Unable to mount root fs via NFS, trying floppy.\n"); 5171da177e4SLinus Torvalds ROOT_DEV = Root_FD0; 5181da177e4SLinus Torvalds } 5191da177e4SLinus Torvalds #endif 5201da177e4SLinus Torvalds #ifdef CONFIG_BLK_DEV_FD 5211da177e4SLinus Torvalds if (MAJOR(ROOT_DEV) == FLOPPY_MAJOR) { 5221da177e4SLinus Torvalds /* rd_doload is 2 for a dual initrd/ramload setup */ 5231da177e4SLinus Torvalds if (rd_doload==2) { 5241da177e4SLinus Torvalds if (rd_load_disk(1)) { 5251da177e4SLinus Torvalds ROOT_DEV = Root_RAM1; 5261da177e4SLinus Torvalds root_device_name = NULL; 5271da177e4SLinus Torvalds } 5281da177e4SLinus Torvalds } else 5291da177e4SLinus Torvalds change_floppy("root floppy"); 5301da177e4SLinus Torvalds } 5311da177e4SLinus Torvalds #endif 5329361401eSDavid Howells #ifdef CONFIG_BLOCK 533bdaf8529SGreg Kroah-Hartman create_dev("/dev/root", ROOT_DEV); 5341da177e4SLinus Torvalds mount_block_root("/dev/root", root_mountflags); 5359361401eSDavid Howells #endif 5361da177e4SLinus Torvalds } 5371da177e4SLinus Torvalds 5381da177e4SLinus Torvalds /* 5391da177e4SLinus Torvalds * Prepare the namespace - decide what/where to mount, load ramdisks, etc. 5401da177e4SLinus Torvalds */ 5411da177e4SLinus Torvalds void __init prepare_namespace(void) 5421da177e4SLinus Torvalds { 5431da177e4SLinus Torvalds int is_floppy; 5441da177e4SLinus Torvalds 5451da177e4SLinus Torvalds if (root_delay) { 5461da177e4SLinus Torvalds printk(KERN_INFO "Waiting %d sec before mounting root device...\n", 5471da177e4SLinus Torvalds root_delay); 5481da177e4SLinus Torvalds ssleep(root_delay); 5491da177e4SLinus Torvalds } 5501da177e4SLinus Torvalds 551216773a7SArjan van de Ven /* 552216773a7SArjan van de Ven * wait for the known devices to complete their probing 553216773a7SArjan van de Ven * 554216773a7SArjan van de Ven * Note: this is a potential source of long boot delays. 555216773a7SArjan van de Ven * For example, it is not atypical to wait 5 seconds here 556216773a7SArjan van de Ven * for the touchpad of a laptop to initialize. 557216773a7SArjan van de Ven */ 558216773a7SArjan van de Ven wait_for_device_probe(); 559d779249eSGreg Kroah-Hartman 5601da177e4SLinus Torvalds md_run_setup(); 5611da177e4SLinus Torvalds 5621da177e4SLinus Torvalds if (saved_root_name[0]) { 5631da177e4SLinus Torvalds root_device_name = saved_root_name; 5642d62f488SAdrian Hunter if (!strncmp(root_device_name, "mtd", 3) || 5652d62f488SAdrian Hunter !strncmp(root_device_name, "ubi", 3)) { 566e9482b43SJoern Engel mount_block_root(root_device_name, root_mountflags); 567e9482b43SJoern Engel goto out; 568e9482b43SJoern Engel } 5691da177e4SLinus Torvalds ROOT_DEV = name_to_dev_t(root_device_name); 5701da177e4SLinus Torvalds if (strncmp(root_device_name, "/dev/", 5) == 0) 5711da177e4SLinus Torvalds root_device_name += 5; 5721da177e4SLinus Torvalds } 5731da177e4SLinus Torvalds 5741da177e4SLinus Torvalds if (initrd_load()) 5751da177e4SLinus Torvalds goto out; 5761da177e4SLinus Torvalds 577cc1ed754SPierre Ossman /* wait for any asynchronous scanning to complete */ 578cc1ed754SPierre Ossman if ((ROOT_DEV == 0) && root_wait) { 579cc1ed754SPierre Ossman printk(KERN_INFO "Waiting for root device %s...\n", 580cc1ed754SPierre Ossman saved_root_name); 581cc1ed754SPierre Ossman while (driver_probe_done() != 0 || 582cc1ed754SPierre Ossman (ROOT_DEV = name_to_dev_t(saved_root_name)) == 0) 583cc1ed754SPierre Ossman msleep(100); 584216773a7SArjan van de Ven async_synchronize_full(); 585cc1ed754SPierre Ossman } 586cc1ed754SPierre Ossman 587cc1ed754SPierre Ossman is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR; 588cc1ed754SPierre Ossman 5891da177e4SLinus Torvalds if (is_floppy && rd_doload && rd_load_disk(0)) 5901da177e4SLinus Torvalds ROOT_DEV = Root_RAM0; 5911da177e4SLinus Torvalds 5921da177e4SLinus Torvalds mount_root(); 5931da177e4SLinus Torvalds out: 5942b2af54aSKay Sievers devtmpfs_mount("dev"); 5951da177e4SLinus Torvalds sys_mount(".", "/", NULL, MS_MOVE, NULL); 596c67e5382SH Hartley Sweeten sys_chroot("."); 5971da177e4SLinus Torvalds } 59857f150a5SRob Landley 5996e19ededSRob Landley static bool is_tmpfs; 60057f150a5SRob Landley static struct dentry *rootfs_mount(struct file_system_type *fs_type, 60157f150a5SRob Landley int flags, const char *dev_name, void *data) 60257f150a5SRob Landley { 60357f150a5SRob Landley static unsigned long once; 6046e19ededSRob Landley void *fill = ramfs_fill_super; 60557f150a5SRob Landley 60657f150a5SRob Landley if (test_and_set_bit(0, &once)) 60757f150a5SRob Landley return ERR_PTR(-ENODEV); 60857f150a5SRob Landley 6096e19ededSRob Landley if (IS_ENABLED(CONFIG_TMPFS) && is_tmpfs) 6106e19ededSRob Landley fill = shmem_fill_super; 6116e19ededSRob Landley 6126e19ededSRob Landley return mount_nodev(fs_type, flags, data, fill); 61357f150a5SRob Landley } 61457f150a5SRob Landley 61557f150a5SRob Landley static struct file_system_type rootfs_fs_type = { 61657f150a5SRob Landley .name = "rootfs", 61757f150a5SRob Landley .mount = rootfs_mount, 61857f150a5SRob Landley .kill_sb = kill_litter_super, 61957f150a5SRob Landley }; 62057f150a5SRob Landley 62157f150a5SRob Landley int __init init_rootfs(void) 62257f150a5SRob Landley { 62357f150a5SRob Landley int err = register_filesystem(&rootfs_fs_type); 62457f150a5SRob Landley 62557f150a5SRob Landley if (err) 62657f150a5SRob Landley return err; 62757f150a5SRob Landley 6286e19ededSRob Landley if (IS_ENABLED(CONFIG_TMPFS) && !saved_root_name[0] && 6296e19ededSRob Landley (!root_fs_names || strstr(root_fs_names, "tmpfs"))) { 63016203a7aSRob Landley err = shmem_init(); 6316e19ededSRob Landley is_tmpfs = true; 6326e19ededSRob Landley } else { 63357f150a5SRob Landley err = init_ramfs_fs(); 6346e19ededSRob Landley } 63516203a7aSRob Landley 63657f150a5SRob Landley if (err) 63757f150a5SRob Landley unregister_filesystem(&rootfs_fs_type); 63857f150a5SRob Landley 63957f150a5SRob Landley return err; 64057f150a5SRob Landley } 641