加载ubuntu
dd if=/dev/zero of=ubuntu.img bs=1M count=8192
qemu-img create -f qcow2 ubuntu.img 40G
./build/qemu-system-x86_64 \
-m 2G -smp 2 \
--enable-kvm \
-boot order=dc \
-hda ubuntu.img \
-cdrom ubuntu-20.04.4-live-server-amd64.iso \
-vnc :1
./build/qemu-system-x86_64 \
-m 2G -smp 2 \
--enable-kvm \
-boot order=c \
-hda ubuntu.img \
-nic user,id=virtionet1,model=virtio-net-pci,tftp=root/tftp,hostfwd=tcp::8869-:22 \
-vnc :1
安装成功后,首次普通启动
qemu和宿主机共享磁盘
qemu-img create -f raw disk.raw 10G
mkfs -t ext4 ./disk.raw
sudo mount -o loop ./disk.raw ./img
sudo umount ./disk.raw
./build/qemu-system-x86_64 \
-m 2G -smp 2 \
--enable-kvm \
-boot order=c \
-hda ubuntu.img \
-hdb ./disk.raw \
-nic user,id=virtionet1,model=virtio-net-pci,tftp=root/tftp,hostfwd=tcp::8869-:22 \
-vnc :1
使用 lsblk 查看添加上的磁盘 使用mount命令挂载/dev/sdb 到某个目录,如 sudo mount /dev/sdb /mnt/sdb , 可以在/mnt/sdb 目录下访问共享磁盘
sudo mkdir /mnt/sdb
sudo mount /dev/sdb /mnt/sdb
编译内核
参考 Ubuntu下编译内核
sudo apt install build-essential flex bison libssl-dev libelf-dev libncurses-dev dwarves zstd
make mrproper
cp /boot/config-`uname -r` ./.config
make menuconfig
make -j$(nproc)
sudo make install
sudo update-grub2
编译出现的错误,可能的解决方案 Q1: FAILED: load BTF from vmlinux: Unknown error -2make : *** [Makefile:1162: vmlinux] Error 255
Q2: make modules_install报错make[1]: *** [arch/x86/crypto/aegis128-aesni.ko] Error 1 Makefile
- 在编译前配置阶段编辑
vim .config , 通过搜索把 CONFIG_SYSTEM_TRUSTED_KEYS="debian/canonical-certs.pem" 修改成 CONFIG_SYSTEM_TRUSTED_KEYS="" , 对于CONFIG_MODULE_SIG_KEY="" 不一定要修成空,可能也会安装不上
Q3: 在执行安装发现 Write error : cannot write compressed block
Q4: 在直接make & sudo make install 安装的内核,在启动时ifconfig -a 没有检查出相应网卡
- 相关的驱动是编译成模块,而在编译时没有安装相关模块, 可以修改配置文件,比如 修改
CONFIG_E1000=y 直接编译到内核中 - 检查
/lib/modules/$(uname -r)/ 是否存在相关模块,然后通过insmod 进行安装
参考关于Ubuntu开机启动菜单grub2
sudo vim /etc/default/grub
GRUB_DEFAULT=0
GRUB_TIMEOUT1=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="maybe-ubiquity"
GRUB_CMDLINE_LINUX=""
sudo update-grub2
qcow2 扩容
参考KVM 虚拟机磁盘扩容
qemu-img resize ubuntu.img +20G
qemu-img info ubuntu.img
sudo fdisk -l
Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 6457B4B2-9E0C-4FEE-8586-1412B99781D5
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 1861631 1857536 907M Linux filesystem
/dev/sda3 1861632 20969471 19107840 9.1G Linux filesystem
sudo fdisk /dev/sda
Command (m for help): t
Partition number (1-4, default 4): 4
Partition type (type L to list all types): 8e
sudo vgdisplay
sudo pvcreate /dev/sda4
sudo vgextend ubuntu-vg /dev/sda4
df -TH
/dev/mapper/ubuntu--vg-ubuntu--lv ext4 9.0G 5.0G 3.6G 59% /
sudo lvresize -L +19G /dev/mapper/ubuntu--vg-ubuntu--lv
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
|