ソースを参照

convert to UUID; make panic-reboot-time a flag; prevent automatic fsck

note: uuid.patch currently still panics ☹

Signed-off-by: Thorsten Glaser <tg@mirbsd.org>
Thorsten Glaser 13 年 前
コミット
2140694397
4 ファイル変更189 行追加17 行削除
  1. 1 3
      mk/rootfs.mk
  2. 14 6
      scripts/install.sh
  3. 0 8
      target/Config.in
  4. 174 0
      target/linux/patches/2.6.36/uuid.patch

+ 1 - 3
mk/rootfs.mk

@@ -8,8 +8,6 @@ FS_CMDLINE:=$(3)
 endif
 endef
 
-ADK_TARGET_ROOTFS_USB_DEVICE:=$(strip $(subst ",, $(ADK_TARGET_ROOTFS_USB_DEVICE)))
-
 ifeq ($(ADK_LINUX_MIPS_RB532),y)
 ROOTFS:=	root=/dev/sda2
 MTDDEV:=	root=/dev/mtdblock1
@@ -24,7 +22,7 @@ ROOTFS:=	root=/dev/mmcblk0p2 rootwait
 endif
 
 $(eval $(call rootfs_template,ext2-block,EXT2_BLOCK,$(ROOTFS)))
-$(eval $(call rootfs_template,usb,USB,root=$(ADK_TARGET_ROOTFS_USB_DEVICE) rootdelay=3))
+$(eval $(call rootfs_template,usb,USB,rootdelay=3))
 $(eval $(call rootfs_template,archive,ARCHIVE))
 $(eval $(call rootfs_template,initramfs,INITRAMFS))
 $(eval $(call rootfs_template,initramfs-piggyback,INITRAMFS_PIGGYBACK))

+ 14 - 6
scripts/install.sh

@@ -73,22 +73,28 @@ cfgfs=1
 quiet=0
 serial=0
 speed=115200
+panicreboot=10
 
 function usage {
 cat >&2 <<EOF
-Syntax: $me [-c cfgfssize] [±qt] [-s serialspeed] /dev/sdb image
-Defaults: -c 1 -s 115200
+Syntax: $me [-c cfgfssize] [-p panictime] [±q] [-s serialspeed]
+    [±t] /dev/sdb image
+Defaults: -c 1 -p 10 -s 115200; -t = enable serial console
 EOF
 	exit $1
 }
 
-while getopts "c:hqs:t" ch; do
+while getopts "c:hp:qs:t" ch; do
 	case $ch {
 	(c)	if (( (cfgfs = OPTARG) < 0 || cfgfs > 5 )); then
 			print -u2 "$me: -c $OPTARG out of bounds"
 			exit 1
 		fi ;;
 	(h)	usage 0 ;;
+	(p)	if (( (panicreboot = OPTARG) < 0 || panicreboot > 300 )); then
+			print -u2 "$me: -p $OPTARG out of bounds"
+			exit 1
+		fi ;;
 	(q)	quiet=1 ;;
 	(+q)	quiet=0 ;;
 	(s)	if [[ $OPTARG != @(96|192|384|576|1152)00 ]]; then
@@ -281,7 +287,8 @@ dd if="$T/firsttrack" of="$tgt"
 q=
 (( quiet )) && q=-q
 mke2fs $q "$part"
-#partuuid=$(tune2fs -l /dev/sd0i | sed -n '/^Filesystem UUID:[	 ]*/s///p')
+partuuid=$(tune2fs -l "$part" | sed -n '/^Filesystem UUID:[	 ]*/s///p')
+tune2fs -c 0 -i 0 "$part"
 
 (( quiet )) || print Extracting installation archive...
 mount_ext2fs "$part" "$T"
@@ -311,8 +318,9 @@ mkdir -p boot/grub
 	fi
 	print
 	print 'menuentry "GNU/Linux (OpenADK)" {'
-#	print "\tlinux /boot/vmlinuz-adk root=UUID=$partuuid $consargs panic=10"
-	print "\tlinux /boot/vmlinuz-adk $consargs panic=10"
+	linuxargs="root=UUID=$partuuid $consargs"
+	(( panicreboot )) && linuxargs="$linuxargs panic=$panicreboot"
+	print "\tlinux /boot/vmlinuz-adk $linuxargs"
 	print '}'
 ) >boot/grub/grub.cfg
 set -A grubfiles

+ 0 - 8
target/Config.in

@@ -770,14 +770,6 @@ config ADK_TARGET_ROOTFS_ENCRYPTED
 
 endchoice
 
-config ADK_TARGET_ROOTFS_USB_DEVICE
-	prompt "Target device node for USB stick"
-	string
-	depends on ADK_TARGET_ROOTFS_USB
-	default "/dev/sdb1"
-	help
-	  Target device node for the USB stick.
-
 choice
 prompt "Compression method for initramfs and kernel"
 	depends on ADK_TARGET_ROOTFS_INITRAMFS || ADK_TARGET_ROOTFS_INITRAMFS_PIGGYBACK

+ 174 - 0
target/linux/patches/2.6.36/uuid.patch

@@ -0,0 +1,174 @@
+# DP: Add support for specifying the root device using UUIDs on the
+# DP: kernel command line like this without the need for an initrd:
+# DP: linux ... root=UUID=ce40d6b2-18eb-4a75-aefe-7ddb0995ce63
+# DP:
+# DP: Written © 2010 by Thorsten Glaser <tg@debian.org>
+# DP: Idea from 1999 by David Balazic <david.balazic@uni-mb.si>
+
+--- linux-2.6.36/block/genhd.c~	Wed Oct 20 22:30:22 2010
++++ linux-2.6.36/block/genhd.c	Sat Nov 20 23:14:03 2010
+@@ -35,7 +35,7 @@ struct kobject *block_depr;
+ static DEFINE_MUTEX(ext_devt_mutex);
+ static DEFINE_IDR(ext_devt_idr);
+ 
+-static struct device_type disk_type;
++struct device_type disk_type;
+ 
+ /**
+  * disk_get_part - get partition
+@@ -1019,7 +1019,7 @@ static char *block_devnode(struct device *dev, mode_t 
+ 	return NULL;
+ }
+ 
+-static struct device_type disk_type = {
++struct device_type disk_type = {
+ 	.name		= "disk",
+ 	.groups		= disk_attr_groups,
+ 	.release	= disk_release,
+--- linux-2.6.36/init/do_mounts.c~	Wed Oct 20 22:30:22 2010
++++ linux-2.6.36/init/do_mounts.c	Sat Nov 20 23:16:07 2010
+@@ -32,6 +32,84 @@ static int __initdata root_wait;
+ 
+ dev_t ROOT_DEV;
+ 
++#ifdef CONFIG_EXT2_FS
++/* support for root=UUID=ce40d6b2-18eb-4a75-aefe-7ddb0995ce63 bootargs */
++
++#include <linux/buffer_head.h>
++#include <linux/ext2_fs.h>
++
++__u8 root_dev_label[16];
++int root_dev_type;	/* 0 = normal (/dev/hda1, 0301); 1 = UUID; 3 = bad */
++
++/* imported from block/genhd.c after removing its static qualifier */
++extern struct device_type disk_type;
++
++static __u8 __init fromhex(char c)
++{
++	if (c >= '0' && c <= '9')
++		return (c - '0');
++	c &= ~32;
++	if (c >= 'A' && c <= 'F')
++		return (c - 'A' + 10);
++	return (0xFF);
++}
++
++static void __init parse_uuid(const char *s)
++{
++	int i;
++	__u8 j, k;
++
++	if (strlen(s) != 36 || s[8] != '-' || s[13] != '-' ||
++	    s[18] != '-' || s[23] != '-')
++		goto bad_uuid;
++	for (i = 0; i < 16; i++) {
++		if (*s == '-')
++			++s;
++		j = fromhex(*s++);
++		k = fromhex(*s++);
++		if (j == 0xFF || k == 0xFF)
++			goto bad_uuid;
++		root_dev_label[i] = (j << 4) | k;
++	}
++	return;
++ bad_uuid:
++	/* we cannot panic here, defer */
++	root_dev_type = 3;
++}
++
++static int __init check_dev(dev_t devt, int blocksize)
++{
++	/* most of this taken from fs/ext2/super.c */
++
++	struct buffer_head * bh;
++	struct ext2_super_block * es;
++	struct block_device *bdev;
++	unsigned long sb_block = 1;
++	unsigned long logic_sb_block;
++	unsigned long offset = 0;
++	int rv = 0;
++
++	bdev = bdget(devt);
++
++	if (blocksize != BLOCK_SIZE) {
++		logic_sb_block = (sb_block*BLOCK_SIZE) / blocksize;
++		offset = (sb_block*BLOCK_SIZE) % blocksize;
++	} else {
++		logic_sb_block = sb_block;
++	}
++
++	if (!(bh = __bread(bdev, logic_sb_block, blocksize)))
++		return (0);
++	es = (struct ext2_super_block *)(((char *)bh->b_data) + offset);
++	if (le16_to_cpu(es->s_magic) == EXT2_SUPER_MAGIC) {
++		if (!memcmp(es->s_uuid, root_dev_label, 16))
++			rv = 1;
++	}
++	brelse(bh);
++	return (rv);
++}
++#endif /* CONFIG_EXT2_FS for UUID support */
++
+ static int __init load_ramdisk(char *str)
+ {
+ 	rd_doload = simple_strtol(str,NULL,0) & 3;
+@@ -148,6 +226,13 @@ done:
+ static int __init root_dev_setup(char *line)
+ {
+ 	strlcpy(saved_root_name, line, sizeof(saved_root_name));
++#ifdef CONFIG_EXT2_FS
++	root_dev_type = 0;
++	if (!strncmp(line, "UUID=", 5)) {
++		root_dev_type = 1;
++		parse_uuid(line + 5);
++	}
++#endif /* CONFIG_EXT2_FS for UUID support */
+ 	return 1;
+ }
+ 
+@@ -333,6 +418,45 @@ void __init change_floppy(char *fmt, ...)
+ 
+ void __init mount_root(void)
+ {
++#ifdef CONFIG_EXT2_FS
++	/* UUID support */
++	if (root_dev_type == 1) {
++		int blocksize;
++
++		/* from block/genhd.c printk_all_partitions */
++		struct class_dev_iter iter;
++		struct device *dev;
++
++		class_dev_iter_init(&iter, &block_class, NULL, &disk_type);
++		while (root_dev_type && (dev = class_dev_iter_next(&iter))) {
++			struct gendisk *disk = dev_to_disk(dev);
++			struct disk_part_iter piter;
++			struct hd_struct *part;
++			if (get_capacity(disk) == 0 ||
++			    (disk->flags & GENHD_FL_SUPPRESS_PARTITION_INFO))
++				continue;
++			blocksize = queue_logical_block_size(disk->queue);
++
++			disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
++			while (root_dev_type && (part = disk_part_iter_next(&piter))) {
++				/* avoid empty or too small partitions */
++				if (part->nr_sects < 8)
++					continue;
++				if (check_dev(part_devt(part), blocksize)) {
++					ROOT_DEV = part_devt(part);
++					root_dev_type = 0;
++				}
++			}
++			disk_part_iter_exit(&piter);
++		}
++		class_dev_iter_exit(&iter);
++	}
++	if (root_dev_type == 1)
++		printk(KERN_ERR "VFS: Unable to find root by UUID %s.\n", saved_root_name + 5);
++	else if (root_dev_type == 3)
++		panic("Badly formatted UUID %s was supplied as kernel parameter root", saved_root_name + 5);
++#endif /* CONFIG_EXT2_FS for UUID support */
++
+ #ifdef CONFIG_ROOT_NFS
+ 	if (MAJOR(ROOT_DEV) == UNNAMED_MAJOR) {
+ 		if (mount_nfs_root())