Linux笔记

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

Direct Linux Boot

在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中切换

/etc/fstab

mount -a 按照/etc/fstab内容挂载设备

How to build and boot a custom disk image in qemu

文件系统tmpfs

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漏洞

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值