Skip to contentSkip to conversation

how to increase commandline size (fwd)

DISCUSSION Jeff Chua 5 participants 15 messages Oct 10, 2006 – Oct 13, 2006 Kbuild

lore
Share & tools
lore

Jeff Chua

author
#0 lore raw
Quoted 6 lines · Marco Gerards
Quoted 1 line

It seems to stop at 256 characters counting the input length

That's weird. Could you please have a look at loader/i386/pc/linux.c to see if it gets the entire line or just a part. Perhaps this limitation is in the protocol used to pass the command line to Linux, I don't this protocol.

Marco,

I managed to trace down the limitation to GRUB_LINUX_CL_END_OFFSET. This limits to 255 characters. I've expanded to 1536 and it seems ok. I've modified the code to rely on COMMAND_LINE_SIZE defined in the kernel.

ps. Marco had requested that I post this to the mailing list so that you all can help verify this is ok.

Here's the patch ...

Thanks for your help,

Jeff.

include/grub/i386/linux.h renamed from include/grub/i386/linux.h.org +5 -2
@@ -17,6 +17,8 @@
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#include <asm/param.h>
+
 #ifndef GRUB_LINUX_MACHINE_HEADER
 #define GRUB_LINUX_MACHINE_HEADER	1
 
@@ -41,8 +43,9 @@
 #define GRUB_LINUX_VID_MODE_ASK		0xFFFD
 
 #define GRUB_LINUX_CL_OFFSET		0x9000
-#define GRUB_LINUX_CL_END_OFFSET	0x90FF
-#define GRUB_LINUX_SETUP_MOVE_SIZE	0x9100
+#define GRUB_LINUX_CL_END_OFFSET	\
+		(GRUB_LINUX_CL_OFFSET + COMMAND_LINE_SIZE)
+#define GRUB_LINUX_SETUP_MOVE_SIZE	(GRUB_LINUX_CL_END_OFFSET + 1)
 #define GRUB_LINUX_CL_MAGIC		0xA33F
 
 #define GRUB_LINUX_EFI_SIGNATURE	\
kern/i386/pc/startup.S renamed from kern/i386/pc/startup.S.org +2 -1
@@ -51,6 +51,7 @@
 #include <grub/cpu/linux.h>
 #include <grub/machine/kernel.h>
 #include <grub/machine/multiboot.h>
+#include <asm/param.h>
 
 #define ABS(x)	((x) - EXT_C(start) + GRUB_BOOT_MACHINE_KERNEL_ADDR + 0x200)
 
@@ -760,7 +761,7 @@
 	/* copy the real mode code */
 	movl	EXT_C(grub_linux_tmp_addr), %esi
 	movl	%ebx, %edi
-	movl	$GRUB_LINUX_SETUP_MOVE_SIZE, %ecx
+	movl	$(GRUB_LINUX_CL_OFFSET + COMMAND_LINE_SIZE + 1), %ecx
 	cld
 	rep
 	movsb
Makefile renamed from Makefile.org +1 -1
@@ -61,7 +61,7 @@
 	 -DGRUB_LIBDIR=\"$(pkglibdir)\"
 TARGET_CC = gcc
 TARGET_CFLAGS = -Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes                  -Wundef -Wstrict-prototypes -g -Os -falign-jumps=1 -falign-loops=1 -falign-functions=1
-TARGET_CPPFLAGS =  -I. -Iinclude -I$(srcdir)/include \
+TARGET_CPPFLAGS =  -I/usr/include -I. -Iinclude -I$(srcdir)/include \
 	-Wall -W
 TARGET_LDFLAGS =
 OBJCOPY = objcopy
author
#1 lore raw

Re: how to increase commandline size (patch + changelog)

On Tue, 10 Oct 2006, Jeff Chua wrote:

Here's with ChangeLog included.

Quoted 15 lines · Marco Gerards
Quoted 7 lines
Quoted 2 lines

It seems to stop at 256 characters counting the input length

That's weird. Could you please have a look at loader/i386/pc/linux.c to see if it gets the entire line or just a part. Perhaps this limitation is in the protocol used to pass the command line to Linux, I don't this protocol.

Marco,

I managed to trace down the limitation to GRUB_LINUX_CL_END_OFFSET. This limits to 255 characters. I've expanded to 1536 and it seems ok. I've modified the code to rely on COMMAND_LINE_SIZE defined in the kernel.

Quoted 9 lines

ps. Marco had requested that I post this to the mailing list so that you all can help verify this is ok.

Here's the patch ...

Thanks for your help,

Jeff.

include/grub/i386/linux.h renamed from include/grub/i386/linux.h.org +5 -2
@@ -17,6 +17,8 @@
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#include <asm/param.h>
+
 #ifndef GRUB_LINUX_MACHINE_HEADER
 #define GRUB_LINUX_MACHINE_HEADER	1
 
@@ -41,8 +43,9 @@
 #define GRUB_LINUX_VID_MODE_ASK		0xFFFD
 
 #define GRUB_LINUX_CL_OFFSET		0x9000
-#define GRUB_LINUX_CL_END_OFFSET	0x90FF
-#define GRUB_LINUX_SETUP_MOVE_SIZE	0x9100
+#define GRUB_LINUX_CL_END_OFFSET	\
+		(GRUB_LINUX_CL_OFFSET + COMMAND_LINE_SIZE)
+#define GRUB_LINUX_SETUP_MOVE_SIZE	(GRUB_LINUX_CL_END_OFFSET + 1)
 #define GRUB_LINUX_CL_MAGIC		0xA33F
 
 #define GRUB_LINUX_EFI_SIGNATURE	\
kern/i386/pc/startup.S renamed from kern/i386/pc/startup.S.org +2 -1
@@ -51,6 +51,7 @@
 #include <grub/cpu/linux.h>
 #include <grub/machine/kernel.h>
 #include <grub/machine/multiboot.h>
+#include <asm/param.h>
 
 #define ABS(x)	((x) - EXT_C(start) + GRUB_BOOT_MACHINE_KERNEL_ADDR + 0x200)
 
@@ -760,7 +761,7 @@
 	/* copy the real mode code */
 	movl	EXT_C(grub_linux_tmp_addr), %esi
 	movl	%ebx, %edi
-	movl	$GRUB_LINUX_SETUP_MOVE_SIZE, %ecx
+	movl	$(GRUB_LINUX_CL_OFFSET + COMMAND_LINE_SIZE + 1), %ecx
 	cld
 	rep
 	movsb
Makefile renamed from Makefile.org +1 -1
@@ -61,7 +61,7 @@
 	 -DGRUB_LIBDIR=\"$(pkglibdir)\"
 TARGET_CC = gcc
 TARGET_CFLAGS = -Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes                  -Wundef -Wstrict-prototypes -g -Os -falign-jumps=1 -falign-loops=1 -falign-functions=1
-TARGET_CPPFLAGS =  -I. -Iinclude -I$(srcdir)/include \
+TARGET_CPPFLAGS =  -I/usr/include -I. -Iinclude -I$(srcdir)/include \
 	-Wall -W
 TARGET_LDFLAGS =
 OBJCOPY = objcopy
ChangeLog renamed from ChangeLog.org +11 -0
@@ -1,3 +1,14 @@
+2006-10-10  Jeff Chua <[email protected]>
+
+	* grub2/include/grub/i386/linux.h
+	(GRUB_LINUX_CL_END_OFFSET): determined from COMMAND_LINE_SIZE
+	(GRUB_LINUX_SETUP_MOVE_SIZE): Likewise.
+
+	* grub2/kern/i386/pc/startup.S (grub_linux_boot_bzimage):
+	Calculate command line offset based on COMMAND_LINE_SIZE
+
+	* grub2/Makefile: /usr/include added to locate <asm/param.h>
+
 2006-10-05  Tristan Gingold  <[email protected]>
 
 	* kern/misc.c (grub_strtoull): Guess the base only if not
#2 lore raw

Re: how to increase commandline size (patch + changelog)

Quoted 2 lines · Jeff Chua

+#include <asm/param.h>

I don't think this is a good idea because it requires we build on a Linux host.

-Hollis

author
#3 lore raw

Re: how to increase commandline size (patch + changelog)

Quoted 4 lines · Hollis Blanchard
Quoted 1 line

+#include <asm/param.h>

I don't think this is a good idea because it requires we build on a Linux host.

Shall I use '#ifdef __linux__' to include <asm/param.h> only on linux, and '#define COMMAND_LINE_SIZE 255' for non-linux system?

Sorry, I only thought of using grub2 on linux.

Thanks,
Jeff.

#4 lore raw

Re: how to increase commandline size (patch + changelog)

Quoted 9 lines · Jeff Chua
Quoted 4 lines · Hollis Blanchard
Quoted 1 line

+#include <asm/param.h>

I don't think this is a good idea because it requires we build on a Linux host.

Shall I use '#ifdef __linux__' to include <asm/param.h> only on linux, and '#define COMMAND_LINE_SIZE 255' for non-linux system?

Well, does this number change often? If not, let's just copy it.

If so, then we're screwed anyways because asm/param.h would only match the installed kernel's limit, so may not work for other kernel versions. In that case, let's just copy it and shrink it in a "lowest common denominator" approach.

-Hollis

author
#5 lore raw

Re: how to increase commandline size (patch + changelog)

Quoted 3 lines · Hollis Blanchard
Quoted 2 lines

Shall I use '#ifdef __linux__' to include <asm/param.h> only on linux, and '#define COMMAND_LINE_SIZE 255' for non-linux system?

5B> Well, does this number change often? If not, let's just copy it.

Quoted 3 lines

If so, then we're screwed anyways because asm/param.h would only match the installed kernel's limit, so may not work for other kernel versions.

You're right. asm/param.h determines the limit. We've read this from here for linux.

The idea is that there are users out there who wants to pass quite a few parameters during boot, and loadlin currently handles this. I'm passing network address, netmask, broadcast, hostname, modules_to_load and boot the system up using ramdisk. This allow every system to be unique and yet able to boot from the same CDROM/image.

So, another approach is to use "configure --CommandLineSize=1024" to specify the size, but I thought reading from asm/param.h would be easier.

Setting the current limit to 255 essentially means grub sets it's own limit, and even the kernel supports 1024, grub doesn't.

Jeff.

#6 lore raw

Re: how to increase commandline size (patch + changelog)

Quoted 19 lines · Jeff Chua
Quoted 3 lines · Hollis Blanchard
Quoted 2 lines

Shall I use '#ifdef __linux__' to include <asm/param.h> only on linux, and '#define COMMAND_LINE_SIZE 255' for non-linux system?

5B> Well, does this number change often? If not, let's just copy it.

Quoted 3 lines

If so, then we're screwed anyways because asm/param.h would only match the installed kernel's limit, so may not work for other kernel versions.

You're right. asm/param.h determines the limit. We've read this from here for linux.

The idea is that there are users out there who wants to pass quite a few parameters during boot, and loadlin currently handles this. I'm passing network address, netmask, broadcast, hostname, modules_to_load and boot the system up using ramdisk. This allow every system to be unique and yet able to boot from the same CDROM/image.

Quoted 3 lines

So, another approach is to use "configure --CommandLineSize=1024" to specify the size, but I thought reading from asm/param.h would be easier.

I don't like limits that are introduced at compile time. It means that either things break when a kernel with other limits are used. Or that users will get binaries with limits (for example, when using a GRUB 2 package).

--
Marco

#7 lore raw

Re: how to increase commandline size (patch + changelog)

In reply to Hollis Blanchard
Quoted 11 lines · Hollis Blanchard
Quoted 9 lines · Jeff Chua
Quoted 4 lines · Hollis Blanchard
Quoted 1 line

+#include <asm/param.h>

I don't think this is a good idea because it requires we build on a Linux host.

Shall I use '#ifdef __linux__' to include <asm/param.h> only on linux, and '#define COMMAND_LINE_SIZE 255' for non-linux system?

Quoted 6 lines

Well, does this number change often? If not, let's just copy it.

If so, then we're screwed anyways because asm/param.h would only match the installed kernel's limit, so may not work for other kernel versions. In that case, let's just copy it and shrink it in a "lowest common denominator" approach.

Isn't it possible to use the kernel binary to determine this? For example, is the maximum commandline size stored somewhere? Perhaps, we can determine it by looking at some version field? According to the documentation it is has a maximum length of 255 bytes for every Linux version:

"The kernel command line is a null-terminated string up to 255 characters long, plus the final null."

I don't want the loader to rely on being compiled on GNU/Linux. GRUB 2, when compiled on *BSD, should be capable of loading Linux just as GRUB 2 compiled on GNU/Linux would.

--
Marco

author
#8 lore raw

Re: how to increase commandline size (patch + changelog)

Quoted 5 lines · Marco Gerards

Isn't it possible to use the kernel binary to determine this? For example, is the maximum commandline size stored somewhere? Perhaps, we can determine it by looking at some version field? According to the documentation it is has a maximum length of 255 bytes for every Linux version:

But, user can overwrite this to expand the commandline. It's documented, and tested. See http://www.x86-64.org/lists/discuss/msg06193.html

Quoted 3 lines

I don't want the loader to rely on being compiled on GNU/Linux. GRUB 2, when compiled on *BSD, should be capable of loading Linux just as GRUB 2 compiled on GNU/Linux would.

Agree. So, standard 255 is ok, but then it'll be nice to allow user to
compile "grub2" to expand the commandline. I don't know whether any distributions expand more than 255 characters.

Thanks,
Jeff.

#9 lore raw

Re: how to increase commandline size (patch + changelog)

Quoted 3 lines · Jeff Chua

Agree. So, standard 255 is ok, but then it'll be nice to allow user to compile "grub2" to expand the commandline. I don't know whether any distributions expand more than 255 characters.

At least Knoppix 4.0.2 uses a patch to extend the boot commandline to 512 characters.

Signature · 1 line
Markus Laire
#10 lore raw

Re: how to increase commandline size (patch + changelog)

In reply to Jeff Chua
Quoted 11 lines · Jeff Chua
Quoted 5 lines · Marco Gerards

Isn't it possible to use the kernel binary to determine this? For example, is the maximum commandline size stored somewhere? Perhaps, we can determine it by looking at some version field? According to the documentation it is has a maximum length of 255 bytes for every Linux version:

But, user can overwrite this to expand the commandline. It's documented, and tested. See
http://www.x86-64.org/lists/discuss/msg06193.html

Well, a protocol change which is not official and an email is not really documentation.

Quoted 7 lines
Quoted 3 lines

I don't want the loader to rely on being compiled on GNU/Linux. GRUB 2, when compiled on *BSD, should be capable of loading Linux just as GRUB 2 compiled on GNU/Linux would.

Agree. So, standard 255 is ok, but then it'll be nice to allow user to compile "grub2" to expand the commandline. I don't know whether any distributions expand more than 255 characters.

Compile time arguments are not really an option to me. In that case I prefer something run-time. Or something that can be detected at run-time. It seems all the official versions do not make this change, so changing this is actually non-standard.

You can not rely on the header files when compiling GRUB. Who says the headers you use is for the kernel you load? The same is true for compile time arguments.

So there are two things we can do:

- Detect this somehow by looking at the binary. This should be reliable. I don't think this is possible.

- Add some run-time argument to the loader to override the command line length. But I do not like this either because it allows breaking the Linux boot protocol.

--
Marco

#11 lore raw

Re: how to increase commandline size (patch + changelog)

Quoted 4 lines · Marco Gerards

- Add some run-time argument to the loader to override the command line length. But I do not like this either because it allows breaking the Linux boot protocol.

What exactly happens if we give the kernel a longer cmdline than it supports? Does it just truncate, or fail to boot?

Why not allow users to pass as much as they want, and just warn them if it's >255?

-Hollis

#12 lore raw

Re: how to increase commandline size (patch + changelog)

Quoted 8 lines · Hollis Blanchard
Quoted 4 lines · Marco Gerards

- Add some run-time argument to the loader to override the command line length. But I do not like this either because it allows breaking the Linux boot protocol.

What exactly happens if we give the kernel a longer cmdline than it supports? Does it just truncate, or fail to boot?

It truncates.

Quoted 2 lines

Why not allow users to pass as much as they want, and just warn them if it's >255?

I am not sure what the impact is. Linux has a memory map and I assume the memory after the commandline is used for other things, or might be overwritten.

--
Marco

author
#13 lore raw

Re: how to increase commandline size (patch + changelog)

Quoted 4 lines · Marco Gerards
Quoted 2 lines · Hollis Blanchard

What exactly happens if we give the kernel a longer cmdline than it supports? Does it just truncate, or fail to boot?

Quoted 8 lines

It truncates.

Quoted 2 lines

Why not allow users to pass as much as they want, and just warn them if it's >255?

I am not sure what the impact is. Linux has a memory map and I assume the memory after the commandline is used for other things, or might be overwritten.

Is it possible to "calculate" the needed offset for the exact cmdline length user pass in to grub and set this in grub2/kern/i386/pc/startup.S, then we don't need to worry about what the user pass in.

Jeff.

#14 lore raw

Re: how to increase commandline size (patch + changelog)

Quoted 10 lines · Jeff Chua
Quoted 9 lines · Marco Gerards
Quoted 2 lines · Hollis Blanchard

What exactly happens if we give the kernel a longer cmdline than it supports? Does it just truncate, or fail to boot?

It truncates.

Quoted 2 lines

Why not allow users to pass as much as they want, and just warn them if it's >255?

Quoted 7 lines
Quoted 3 lines

I am not sure what the impact is. Linux has a memory map and I assume the memory after the commandline is used for other things, or might be overwritten.

Is it possible to "calculate" the needed offset for the exact cmdline length user pass in to grub and set this in grub2/kern/i386/pc/startup.S, then we don't need to worry about what the user pass in.

I do not like it very much. Linux specifies how it is loaded precisely, so we should follow it carefully. Even if loadlin passes anything and it is useful for you, it is a bug feature, and I don't appreciate that way.

BTW this is a kind of FAQ. I have answered the same question several times until now. All I have been saying is that you should improve Linux before changing GRUB. I thought someone took an action for this, but the specification hasn't changed AFAIK.

Okuji