ubuntu22.04备份系统的完整操作过程

我的ubuntu系统有5个扇区,划分如下

名称    用于    大小    挂载点    分区类型    说明

EFI分区    efi    512M        主分区    第一个设置项

/boot    ext4    512M    /boot    逻辑分区    

交换区    交换区间    4G(电脑内存够大的化不用划分)        逻辑分区    

/    ext4    40G    /    主分区    系统安装的地方,相当与win10的c盘

/home    ext4    剩余空间    /home    逻辑分区    相当与win10的d盘

————————————————

版权声明:本文为CSDN博主「绑个蝴蝶结」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/qq_38153833/article/details/123054055

备份系统需要进入U盘启动盘去操作,需要备份除了swap扇区以外的4个扇区。本文按照mksquashfs 命令备份。下面是备份系统整个过程的命令,需要的人可以参考。

ubuntu@ubuntu:~$ sudo su
root@ubuntu:/home/ubuntu# cd /
# 查看当前挂载点
root@ubuntu:/# df -kh
Filesystem                   Size  Used Avail Use% Mounted on
tmpfs                        3.2G   19M  3.1G   1% /run
/dev/sdc1                    3.6G  3.6G     0 100% /cdrom
/cow                          16G   75M   16G   1% /
/dev/disk/by-label/writable   12G   13M   11G   1% /var/log
tmpfs                         16G     0   16G   0% /dev/shm
tmpfs                        5.0M  8.0K  5.0M   1% /run/lock
tmpfs                         16G     0   16G   0% /tmp
tmpfs                        3.2G  144K  3.2G   1% /run/user/999
root@ubuntu:/# mkdir /mnt/efi /mnt/boot /mnt/root /mnt/home
root@ubuntu:/# fdisk -l
# 列举所有磁盘
Disk /dev/nvme0n1: 953.87 GiB, 1024209543168 bytes, 2000409264 sectors
Disk model: SAMSUNG MZVL21T0HCLR-00BL2              
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: E362169A-5959-41F8-B89B
Device             Start        End    Sectors   Size Type
/dev/nvme0n1p1      2048     616447     614400   300M EFI System
/dev/nvme0n1p2    616448     878591     262144   128M Microsoft reserved
/dev/nvme0n1p3    878592  336483630  335605039   160G Microsoft basic data
/dev/nvme0n1p4 336485176  337681207    1196032   584M Windows recovery environment
/dev/nvme0n1p5 337681208  784056319  446375112 212.8G Microsoft basic data
/dev/nvme0n1p6 784056320  951830527  167774208    80G Microsoft basic data
/dev/nvme0n1p7 951830528 2000409230 1048578703   500G Microsoft basic data
Disk /dev/sda: 465.76 GiB, 500107862016 bytes, 976773168 sectors
Disk model: PSSD T7         
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33553920 bytes
Disklabel type: gpt
Disk identifier: 477CF23C-DABB-464C-8503-0A20B221F810
# 这个是要被备份的Ubuntu系统所在的磁盘
Device         Start       End   Sectors   Size Type
/dev/sda1       2048   1050623   1048576   512M EFI System
/dev/sda2    1050624   2099199   1048576   512M Linux filesystem
/dev/sda3    2099200  10487807   8388608     4G Linux swap
/dev/sda4   10487808  94373887  83886080    40G Linux filesystem
/dev/sda5   94373888 157288447  62914560    30G Linux filesystem
/dev/sda6  157288448 576718847 419430400   200G Microsoft basic data
/dev/sda7  576718848 976773119 400054272 190.8G Microsoft basic data
Disk /dev/sdb: 698.64 GiB, 750156374016 bytes, 1465149168 sectors
Disk model:                 
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x1463c369
# 这个是打算备份到的区域
Device     Boot      Start        End    Sectors   Size Id Type
/dev/sdb1             2048 1347962879 1347960832 642.8G  7 HPFS/NTFS/exFAT
/dev/sdb2       1347962880 1465147391  117184512  55.9G 83 Linux
Disk /dev/sdc: 14.84 GiB, 15938355200 bytes, 31129600 sectors
Disk model: Flash Disk      
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: 9240A165-D190-4AB6-8A10-46DC207B42EE
Device       Start      End  Sectors  Size Type
/dev/sdc1       64  7465119  7465056  3.6G Microsoft basic data
/dev/sdc2  7465120  7473615     8496  4.1M EFI System
/dev/sdc3  7473616  7474215      600  300K Microsoft basic data
/dev/sdc4  7475200 31129536 23654337 11.3G Linux filesystem
# 挂载除了swap以外所有的ubuntu系统的盘
root@ubuntu:/# mount /dev/sda1 /mnt/efi
root@ubuntu:/# mount /dev/sda2 /mnt/boot
root@ubuntu:/# mount /dev/sda4 /mnt/root
root@ubuntu:/# mount /dev/sda5 /mnt/home
# 挂载备份的U盘
root@ubuntu:/# mkdir backup
root@ubuntu:/# mount /dev/sdb2 /backup
root@ubuntu:/# cd backup
# 以前有备份过,还是发现sfs更好用一些
root@ubuntu:/backup# ls
backupcommand.txt          fstab               lost+found
bk_boot_2.sfs              home_msy_Documents  ubuntu2204_@22-09-24:09:03.tar.gz
bk_home_5.sfs              home_msy_Downloads  ubuntu2204_boot@22-09-24:09:33.tar.gz
bk_mnt_4.sfs               home_msy_Pictures   ubuntu2204_home@22-09-24:09:24.tar.gz
bookmarks-2022-09-23.json  log.txt
# 正式开始制作备份,顺序随意都可
root@ubuntu:/backup# mksquashfs /mnt/root /backup/bk_09251950_root.sfs
Parallel mksquashfs: Using 16 processors
Creating 4.0 filesystem on /backup/bk_09251950_root.sfs, block size 131072.
[========================================================================/  ] 326433/333375  97%
Unrecognised xattr prefix system.posix_acl_access
[========================================================================-  ] 327612/333375  98%
Unrecognised xattr prefix system.posix_acl_access
Unrecognised xattr prefix system.posix_acl_access
[========================================================================\  ] 327838/333375  98%
Unrecognised xattr prefix system.posix_acl_access
[=========================================================================| ] 330313/333375  99%
Unrecognised xattr prefix system.posix_acl_access
[=========================================================================/ ] 330718/333375  99%
Unrecognised xattr prefix system.posix_acl_access
[=========================================================================- ] 332691/333375  99%
Unrecognised xattr prefix system.posix_acl_access
Unrecognised xattr prefix system.posix_acl_access
Unrecognised xattr prefix system.posix_acl_default
Unrecognised xattr prefix system.posix_acl_access
Unrecognised xattr prefix system.posix_acl_default
[==========================================================================|] 333375/333375 100%
Exportable Squashfs 4.0 filesystem, gzip compressed, data block size 131072
    compressed data, compressed metadata, compressed fragments,
    compressed xattrs, compressed ids
    duplicates are removed
Filesystem size 8135844.52 Kbytes (7945.16 Mbytes)
    52.81% of uncompressed filesystem size (15407224.84 Kbytes)
Inode table size 3141744 bytes (3068.11 Kbytes)
    26.81% of uncompressed inode table size (11716539 bytes)
Directory table size 3085659 bytes (3013.34 Kbytes)
    39.74% of uncompressed directory table size (7764869 bytes)
Xattr table size 396 bytes (0.39 Kbytes)
    30.48% of uncompressed xattr table size (1299 bytes)
Number of duplicate files found 50779
Number of inodes 318290
Number of files 249544
Number of fragments 16731
Number of symbolic links 40228
Number of device nodes 7
Number of fifo nodes 0
Number of socket nodes 2
Number of directories 28509
Number of ids (unique uids + gids) 39
Number of uids 19
    root (0)
    lp (7)
    systemd-oom (108)
    whoopsie (117)
    usbmux (111)
    systemd-network (100)
    messagebus (102)
    unknown (1000)
    colord (122)
    gdm (127)
    rtkit (116)
    syslog (104)
    man (6)
    unknown (62803)
    tss (106)
    saned (121)
    gnome-initial-setup (125)
    sssd (118)
    pulse (124)
Number of gids 32
    root (0)
    dip (30)
    lp (7)
    shadow (42)
    render (110)
    nogroup (65534)
    tcpdump (117)
    audio (29)
    systemd-network (102)
    utmp (43)
    unknown (1000)
    lpadmin (122)
    scanner (127)
    messagebus (105)
    unknown (139)
    uuidd (115)
    tty (5)
    input (107)
    mail (8)
    staff (50)
    systemd-oom (116)
    man (12)
    unknown (62803)
    systemd-timesync (106)
    tss (112)
    avahi (121)
    sssd (125)
    unknown (136)
    pulse (131)
    pulse-access (132)
    adm (4)
    systemd-journal (101)
root@ubuntu:/backup# mksquashfs /mnt/home /backup/bk_09251954_home.sfs
Parallel mksquashfs: Using 16 processors
Creating 4.0 filesystem on /backup/bk_09251954_home.sfs, block size 131072.
[==========================================================================|] 217891/217891 100%
Exportable Squashfs 4.0 filesystem, gzip compressed, data block size 131072
    compressed data, compressed metadata, compressed fragments,
    compressed xattrs, compressed ids
    duplicates are removed
Filesystem size 8383808.83 Kbytes (8187.31 Mbytes)
    65.61% of uncompressed filesystem size (12777668.24 Kbytes)
Inode table size 1830146 bytes (1787.25 Kbytes)
    26.21% of uncompressed inode table size (6982206 bytes)
Directory table size 2782229 bytes (2717.02 Kbytes)
    43.70% of uncompressed directory table size (6366060 bytes)
Xattr table size 107 bytes (0.10 Kbytes)
    103.88% of uncompressed xattr table size (103 bytes)
Number of duplicate files found 15127
Number of inodes 161150
Number of files 132526
Number of fragments 12038
Number of symbolic links 3671
Number of device nodes 0
Number of fifo nodes 0
Number of socket nodes 0
Number of directories 24953
Number of ids (unique uids + gids) 2
Number of uids 2
    root (0)
    unknown (1000)
Number of gids 2
    root (0)
    unknown (1000)
root@ubuntu:/backup# mksquashfs /mnt/boot /backup/bk_09251957_boot.sfs
Parallel mksquashfs: Using 16 processors
Creating 4.0 filesystem on /backup/bk_09251957_boot.sfs, block size 131072.
[==============================================================================-] 1578/1578 100%
Exportable Squashfs 4.0 filesystem, gzip compressed, data block size 131072
    compressed data, compressed metadata, compressed fragments,
    compressed xattrs, compressed ids
    duplicates are removed
Filesystem size 149700.70 Kbytes (146.19 Mbytes)
    89.45% of uncompressed filesystem size (167355.44 Kbytes)
Inode table size 5528 bytes (5.40 Kbytes)
    36.39% of uncompressed inode table size (15190 bytes)
Directory table size 3032 bytes (2.96 Kbytes)
    49.56% of uncompressed directory table size (6118 bytes)
Number of duplicate files found 1
Number of inodes 310
Number of files 299
Number of fragments 23
Number of symbolic links 4
Number of device nodes 0
Number of fifo nodes 0
Number of socket nodes 0
Number of directories 7
Number of ids (unique uids + gids) 1
Number of uids 1
    root (0)
Number of gids 1
    root (0)
root@ubuntu:/backup# mksquashfs /mnt/efi /backup/bk_09251958_efi.sfs
Parallel mksquashfs: Using 16 processors
Creating 4.0 filesystem on /backup/bk_09251958_efi.sfs, block size 131072.
[==================================================================================|] 57/57 100%
Exportable Squashfs 4.0 filesystem, gzip compressed, data block size 131072
    compressed data, compressed metadata, compressed fragments,
    compressed xattrs, compressed ids
    duplicates are removed
Filesystem size 1359.45 Kbytes (1.33 Mbytes)
    21.72% of uncompressed filesystem size (6259.26 Kbytes)
Inode table size 303 bytes (0.30 Kbytes)
    41.97% of uncompressed inode table size (722 bytes)
Directory table size 233 bytes (0.23 Kbytes)
    67.73% of uncompressed directory table size (344 bytes)
Number of duplicate files found 3
Number of inodes 16
Number of files 11
Number of fragments 1
Number of symbolic links 0
Number of device nodes 0
Number of fifo nodes 0
Number of socket nodes 0
Number of directories 5
Number of ids (unique uids + gids) 1
Number of uids 1
    root (0)
Number of gids 1
    root (0)
# 同步一下这4个盘的改动
root@ubuntu:/backup# sync
root@ubuntu:/backup# umount /mnt/*
# 至此就完成了备份
# 手动制作一个log备份,把上面的命令行输出复制到U盘里
root@ubuntu:/backup# mount /dev/sda7 /mnt
root@ubuntu:/backup# nautilus .
root@ubuntu:/backup# cp bk0925_log.txt /mnt/bk0925_log.txt

猜你喜欢

转载自blog.csdn.net/NICAI001/article/details/127042513