使用debootstrap创建可启动的Debian映像

埃勒

在过去的两天里,我一直在尝试创建可启动的debian(jessie / 8.4)映像,据我所知,我拥有正确的过程,但无法获得正确的文件系统。我相对确定我在这里做错了什么,由于安装或而丢失了某些东西/etc/fstab我的图像中没有一个)。我希望有一些经验的人能够帮助我/向我展示我所缺少的东西。

这是我启动qemu-system-x86时看到的错误:

作为文本,然后作为实际的屏幕截图:

错误:

fsck: error 2 (No such file or directory) while executing fsck.ext2 for /dev/sda1
fsck exited with status code 8
[FAILED] Failed to start Load/Save Random Seed
See `systemctl status systemd-random-seed.service` for details.
[FAILED] Failed to start Various fixups to make systemd work better on Debian.
See `systemctl status debian-fixup.service` for details.
...
[FAILED] Failed to start Update UTMP about System Boot/Shutdown.
See `systemctl status systemd-update-utmp.service` for details.
[DEPEND] Dependency failed for Update UTMP about System Runlevel Changes.

在此处输入图片说明 在此处输入图片说明

以下是我为自己写的说明/已采取的步骤:

cd ~
mkdir debootstrap
cd debootstrap/
# get newest
wget http://ftp.debian.org/debian/pool/main/d/debootstrap/debootstrap_1.0.80_all.deb
ar -x debootstrap_1.0.80_all.deb
zcat /root/debootstrap/data.tar.gz | tar xv

apt-get install parted


# 1.5Gbytes
dd if=/dev/zero of=1445.img bs=1024 count=1 seek=1536k

parted -s 1445.img -- mklabel msdos mkpart primary 1m 1.5g toggle 1 boot
losetup --show -f 1445.img
# prints out `/dev/loopX`, enter this on the next lin
partprobe /dev/loop0
# only have to make the filesytem once --> if you are troubleshooting steps, do not redo this line
mkfs -t ext2 /dev/loop0p1
mount /dev/loop0p1 /mnt

debootstrap --verbose --components=main,contrib,non-free \
--include=firmware-realtek,linux-image-amd64,grub-pc,ssh,vim \
--exclude=nano \
--arch amd64 jessie /mnt http://ftp.us.debian.org/debian

有关使用--components的信息的来源

  • Ensure that the kernel is installed, it should appear in /boot within the chroot, that is /mnt/boot with the following files:

    • initrd.img-3.16.0-4-amd64
    • vmlinuz-3.16.0-4-amd64
    • config-3.16.0-4-amd64
    • System.map-3.16.0-4-amd64
  • install grub

    grub-install --boot-directory=/mnt/boot --modules=part_msdos /dev/loop0
    
  • Set up APT

    • copy over the apt sources

      cp /etc/apt/sources.list /mnt/etc/apt/sources.list
      
    • ensure the cdrom source is commented out

    • add the line:

      deb http://ftp.debian.org/debian stable-backports main contrib non-free
      

Setup a chroot

mount --bind /dev/pts /mnt/dev/pts
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
mount --bind /dev /mnt/dev

# if you want your pushprofilesettings
cp ~/.bashrc /mnt/root/
cp ~/.vimrc /mnt/root/

# chroot -- enter the system as if it were thy own
chroot /mnt /bin/bash
export HOME=/root
export LC_ALL=C
export LANG=C.UTF-8
export TERM=xterm-256color

mount from man mount:
--bind Remount a subtree somewhere else (its contents are available in both places).
-t <type> Mount of filesystem type, with this, mount will attempt to auto determine

setup serial/console access

edit /etc/default/grub:

  1. Set GRUB_CMDLINE_LINUX="" to:

    GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200n8"
    
  2. Uncomment GRUB_TERMINAL=console

  3. Beneath, add the line:

    GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
    

Make the grub config - This MUST be done in a non-systemd-nspawn shell (that means chroot)

grub-mkconfig -o /boot/grub/grub.cfg

Exit chroot

exit

Clean up for chroot'ed

umount /mnt/sys
umount /mnt/dev
umount /mnt/dev/pts
umount /mnt/proc

Can check for additional mounts with: mount | grep /mnt and then unmount them with umount

Enter systemd-nspawn

systemd-nspawn -D /mnt
# not you are in a special container

Set the password for root with passwd

In /etc/ssh/sshd_config comment out PermitRootLogin without-password to read #PermitRootLogin without-password and insert PermitRootLogin yes beneath it

Now enable ssh on startup

systemctl enable ssh

clean up

# this is needed to clean up both chroot and systemd-nspawn -D /mnt
# once this is run you can not do systemd-nspawn either so wait until you are entirely done
exit
umount /mnt
losetup -d /dev/loop0

Check for additional mounts with: mount | grep /mnt If ANYTHING is returned, unmount them with umount

Recover (only necessary in ERROR)

If you broke something, or need to retry, RE-MOUNT / SETUP CHROOT on existing .img:

losetup --show -f 1445.img
# prints out `/dev/loopX`, enter this on the next lin
partprobe /dev/loop0
mount /dev/loop0p1 /mnt

testing img

qemu-system-x86_64 -hda 1445.img -m 1024 -vnc :0
ehiller

Kept at it and figured it out, relatively straight forward from here, but not just a matter of setting up /etc/fstab, here is the rest:

not necessary but a good idea to clean things up

apt-get autoclean

设置/etc/fstab-检查mount以确保您使用的是正确的文件系统类型

echo "/dev/sda1 / ext4 defaults,errors=remount-ro 0 1" > /etc/fstab

这将重建initramfs并使其干净启动

update-initramfs -u -k all

这样做,机器启动干净,在QEMU中进行了测试,然后我现在就在硬件上运行它。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Debian中创建可启动的Windows 10映像?

如何使用预装的软件创建Windows 10的可启动映像?

如何使用MAAS创建Debian映像?

如何使用Photon创建QNX中微子7.0.0可启动CD映像?

如何创建其中包含多个ISO映像的可启动USB

如何为我的BeagleBone创建可启动的备份磁盘映像

如何使用Windows创建可启动的Debian USB驱动器

如何使用Debian Squeeze创建可启动的USB记忆棒

如何从可启动的闪存驱动器创建可启动的iso映像?

如何使用内核创建可引导CD映像?

使用可启动 USB 创建 iso

使用Windows创建可启动的DVD磁盘

使用Windows创建可启动的PenDrive

尝试创建可启动的Linux发行映像时,我缺少哪些步骤?

无法创建可启动的USB来挂载kali linux iso映像?

从ext4分区映像创建可启动磁盘

从Ubuntu启动板构建Debian映像

如何从可启动DVD制作可启动ISO映像?

cp命令使可启动iso映像usb

制作 VirtualBox 机器的可启动映像?

使用安装在硬盘驱动器上的可启动实时CD磁盘映像

使用mkisofs和-eltorito-boot efiboot.img制作可启动UEFI的映像

创建可移植的Debian安装

从我的启动盘创建映像文件

从映像创建Docker容器而不启动它

如何创建加密的可增长磁盘映像?

如何在Linux上使用命令行从可启动ISO创建可启动USB?

如何通过使用Debian 10 dd克隆另一个可启动USB来制作可启动USB?

如何使用 MacOS 创建可启动的拇指驱动器