Linux 内核编译
查看帮助make help
QEMU-KVM guest rootfs read-only issue
qemu 启动参数-append 为"root=/dev/sda rw" 而不是"root=/dev/sda"
Booting a Custom Linux Kernel in QEMU and Debugging It With GDB
# one time setup
$ mkinitramfs -o ramdisk.img
$ echo "add-auto-load-safe-path path/to/linux/scripts/gdb/vmlinux-gdb.py" >> ~/.gdbinit
# one time kernel setup
$ cd linux
$ ./scripts/config -e DEBUG_INFO -e GDB_SCRIPTS
$ <make kernel image>
# each debug session run
$ qemu-system-x86_64 \
-kernel arch/x86_64/boot/bzImage \
-nographic \
-append "console=ttyS0 nokaslr" \
-initrd ramdisk.img \
-m 512 \
--enable-kvm \
-cpu host \
-s -S &
$ gdb vmlinux
(gdb) target remote :1234
(gdb) hbreak start_kernel
(gdb) c
(gdb) lx-dmesg
Ubuntu下gcc多版本共存和版本切换
添加gcc
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 40
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 50
添加g++
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 50
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 40
配置:
sudo update-alternatives --config gcc
删除
sudo update-alternatives --remove gcc /usr/bin/gcc-4.9
在QEMU中启动linux kernel,不需要完整的启动镜像.通常在Linux kernel 测试时很有用
命令:
qemu-system-x86_64 -kernel bzImage -hda rootdisk.img -append "root=/dev/hda"
- -kernel 制定 linux kernel 镜像
- -append 制定内核命令行参数
- -initrd 选项提供INITRD镜像
如果你不需要图形界面输出.可以通过选项-nographic
讲输出重定向到虚拟串口:
qemu-system-x86_64 -kernel bzImage -hda rootdisk.img -append "root=/dev/hda console=ttyS0" -nographic
通过按键 Ctrl-a c 在虚拟串口和QEMU中切换
mount -a 按照/etc/fstab内容挂载设备
How to build and boot a custom disk image in qemu
glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for
POSIX shared memory (shm_open, shm_unlink). Adding the following
line to /etc/fstab should take care of this:
tmpfs /dev/shm tmpfs defaults 0 0
Ubuntu 20.04 Kernel更新
sudo apt-cache search linux-image-*
sudo apt-cache search linux-headers-*
sudo apt-get install linux-image-unsigned-5.8.0-36-generic
sudo apt-get install linux-headers-5.8.0-36-generic
sudo update-initramfs -u -k all
sudo update-grub
更新内核到5.8.0-36,用于测试Dirty pipe漏洞