原创文章,转载请注明出处
https://qiedd.com/

基于此教程制作:https://github.com/cattyhouse/N1-install

镜像下载地址:
github 备份

镜像制作脚本

可用于备份自己的镜像

#!/bin/bash

#Create Image
#这里可以基于自己的系统占用修改生成的img
fallocate -l 2G /Arch-N1.img

#Resize Image
cat > /fdisk.cmd <<-EOF
o
n
p
1
 
+512MB
t
c
n
p
2
 
 
w
EOF
fdisk /Arch-N1.img < /fdisk.cmd
rm /fdisk.cmd

#Mount As Loop Device
losetup -f -P --show /Arch-N1.img
sleep 5

#Mount And Format Partition
mkfs.vfat -n "BOOT" /dev/loop0p1
mke2fs -F -q -t ext4 -L ROOTFS -m 0 /dev/loop0p2
mkdir /img
mount /dev/loop0p2 /img
mkdir /img/boot
mount /dev/loop0p1 /img/boot

#Backup
cd /
DIR_INSTALL=/img
cp -r /boot/* /img/boot/
mkdir -p $DIR_INSTALL/dev
mkdir -p $DIR_INSTALL/media
mkdir -p $DIR_INSTALL/mnt
mkdir -p $DIR_INSTALL/proc
mkdir -p $DIR_INSTALL/run
mkdir -p $DIR_INSTALL/sys
mkdir -p $DIR_INSTALL/tmp
 
tar -cf - bin | (cd $DIR_INSTALL; tar -xpf -)
tar -cf - boot | (cd $DIR_INSTALL; tar -xpf -)
tar -cf - etc | (cd $DIR_INSTALL; tar -xpf -)
tar -cf - home | (cd $DIR_INSTALL; tar -xpf -)
tar -cf - lib | (cd $DIR_INSTALL; tar -xpf -)
tar -cf - opt | (cd $DIR_INSTALL; tar -xpf -)
tar -cf - root | (cd $DIR_INSTALL; tar -xpf -)
tar -cf - sbin | (cd $DIR_INSTALL; tar -xpf -)
tar -cf - srv | (cd $DIR_INSTALL; tar -xpf -)
tar -cf - usr | (cd $DIR_INSTALL; tar -xpf -)
tar -cf - var | (cd $DIR_INSTALL; tar -xpf -)

sync

umount -R /img

exit 0

将系统写入EMMC

#!/bin/bash

MMC=$(lsblk -f|grep -o  mmcblk.|uniq)
BOOT_UUID=$(blkid -s UUID -o value /dev/${MMC}p1)
ROOTFS_UUID=$(blkid -s UUID -o value /dev/${MMC}p2)

#Resize Partition
cat > /fdisk.cmd <<-EOF
o
n
p
1
221184
1269760
t
c
n
p
2
1400832
15269887
p
w
EOF
fdisk /dev/$MMC < /fdisk.cmd
rm /fdisk.cmd

#Format Partition
mkfs.vfat /dev/${MMC}p1
mkfs.ext4 /dev/${MMC}p2

MMC=$(lsblk -f|grep -o  mmcblk.|uniq)
BOOT_UUID=$(blkid -s UUID -o value /dev/${MMC}p1)
ROOTFS_UUID=$(blkid -s UUID -o value /dev/${MMC}p2)

#Mount Partition
mount /dev/${MMC}p2 /mnt
mkdir -p /mnt/boot
mount /dev/${MMC}p1 /mnt/boot

#Rsync Data To MMC
rsync -avPhHAX --numeric-ids  --delete --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/lost+found"} / /mnt

#Set UUID
sed -i "s/root=LABEL=ROOTFS/root=UUID=${ROOTFS_UUID}/" /mnt/boot/extlinux/extlinux.conf
sed -i "s/LABEL=ROOTFS/UUID=${ROOTFS_UUID}/" /mnt/etc/fstab
sed -i "s/LABEL=BOOT/UUID=${BOOT_UUID}/" /mnt/etc/fstab 

umount -R /mnt

exit 0
分类: Linux搞机

1 条评论

mdog · 2021年11月23日 下午2:39

谢谢大佬,小米盒子4启动成功

发表回复

Avatar placeholder

您的邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据