一切都取决于您使用 QEMU 加载的 VM 映像。例如,就我而言,我只是将所需的命令添加到 /etc/profile
但它需要在脚本执行之前登录。为了进行自动登录,我对 /etc/inittab 进行了以下更改:
# Startup the system
::sysinit:/bin/mount -t proc proc /proc
::sysinit:/bin/mount -o remount,rw /
::sysinit:/bin/mkdir -p /dev/pts
::sysinit:/bin/mkdir -p /dev/shm
::sysinit:/bin/mount -a
::sysinit:/bin/hostname -F /etc/hostname
# now run any rc scripts
::sysinit:/etc/init.d/rcS
::sysinit:/bin/login -f root
# Put a getty on the serial port
ttyAMA0::respawn:/sbin/getty -L ttyAMA0 0 vt100 # GENERIC_SERIAL
# Stuff to do for the 3-finger salute
#::ctrlaltdel:/sbin/reboot
# Stuff to do before rebooting
::shutdown:/etc/init.d/rcK
::shutdown:/sbin/swapoff -a
::shutdown:/bin/umount -a -r
以下命令强制使用用户名“root”登录并执行 /etc/profile 脚本:
::sysinit:/bin/login -f root