新建个2G的img文件,不要小于系统占用空间大小:
fallocate -l $(( 2048 * 1024 *1024 )) ubuntu.img
分区:
cat > fdisk.cmd <<-EOF
o
n
p
1
+128MB
t
c
n
p
2
w
EOF
fdisk ubuntu.img < fdisk.cmd
挂载img为loop设备:
losetup -f -P --show ubuntu.img
/dev/loop0
格式化及挂载:
mkfs.vfat -n "BOOTFS" /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
备份系统:
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 - selinux | (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 /img/boot
umount /img
losetup -d /dev/loop0
用作U盘启动,boot/uEnv.ini文件:
bootargs=root=LABEL=ROOTFS rootflags=data=writeback rw console=ttyAML0,115200n8 console=tty0 no_console_suspend consoleblank=0 fsck.fix=yes fsck.repair=yes net.ifnames=0
etc/fstab文件:
LABEL=ROOTFS / ext4 defaults,noatime,nodiratime,commit=600,errors=remount-ro 0 1
LABEL=BOOTFS /boot vfat defaults 0 2
tmpfs /tmp tmpfs defaults,nosuid 0 0
标签:none