扩容openwrt版本generic-ext4-combined

扩容openwrt-21.02.1-x86-64-generic-ext4-combined-efi.img

env

  • rockylinux-9.4

1.img扩容

gzip -d openwrt-x86-64-generic-ext4-combined-efi.img.gz 

dd if=/dev/zero bs=1M count=5000 >> openwrt-x86-64-generic-ext4-combined-efi.img

dd if=/dev/zero bs=1M  count=1000 >> openwrt-x86-64-generic-ext4-combined-efi.img 

追加空间

or

qemu-img resize xxxxxxxx.img 1024M

2.重新分区img

1.挂载到loop设备
losetup -f xxx.img 

或者
顺便读取分区信息,加载到系统
losetup -Pf xxx.img

或者
losetup /dev/loop0 disk.img

2.查看挂在哪个loop设备上 
losetup -a

[root@vgt-rocky9-60 ~]# losetup -a
/dev/loop0: [2053]:17686 (/root/openwrt-x86-64-generic-ext4-combined-efi.img)

3.读取分区信息,加载到系统 
partx -a /dev/loop0
1
2
3
4
5
6
7
8
partx -d /dev/loop4
#卸载系统中的分区信息

losetup -d /dev/loop4` #卸载 loop 设备

partx -u /dev/loop4
#更新系统中的分区信息,**一定要更新**,否则后面扩容会失败

3.新建分区

1.查看分区uuid/start扇区信息

fdisk /dev/loop0
    m 显示fdisk的命令帮助
    x 进入高级菜单  
    p 列出分区表,查看uuid等信息
    r 返回基本菜单

or
    p 列出分区表,看看分区Type,大小  
    i
        2 显示分区2的信息UUID会用到

2.删除新建分区

//删除新建
fdisk /dev/loop0
d
    2 删除分区2  

n
    2 创建分区2
    Start扇区要和原来保持一致,结束扇区只要比之前大就可以
    是否要清楚分区签名 no

//修改分区类型(新版本默认不用修改)
t
    2 修改分区2的类型
        op23的官方版,类型为20 (Linux filesystem), 默认就是

//修改新建分区uuid

    x 进入高级菜单  
    u 修改分区2的UUID和原来保持一致

    r 返回基本菜单
    w 保存

4.格式转换

dnf install -y qemu-img
qemu-img convert -f raw -O vdi disk.img disk.vdi
qemu-img convert -f raw -O qcow2 test.img test.qcow2

or

VBoxManage convertdd disk.img disk.vdi

5.挂载磁盘启动

  • pass

losetup help

[root@vgt-rocky9-60 ~]# losetup --help

Usage:
 losetup [options] [<loopdev>]
 losetup [options] -f | <loopdev> <file>

Set up and control loop devices.

Options:
 -a, --all                     list all used devices
 -d, --detach <loopdev>...     detach one or more devices ### 移除设备
 -D, --detach-all              detach all used devices    ### 移除所有未使用设备
 -f, --find                    find first unused device   ### 自动挂载未使用第一个loop设备 loop0..loopn
 -c, --set-capacity <loopdev>  resize the device
 -j, --associated <file>       list all devices associated with <file>
 -L, --nooverlap               avoid possible conflict between devices

 -o, --offset <num>            start at offset <num> into file
     --sizelimit <num>         device is limited to <num> bytes of the file
 -b, --sector-size <num>       set the logical sector size to <num>
 -P, --partscan                create a partitioned loop device  ### 分区设备盘
 -r, --read-only               set up a read-only loop device
     --direct-io[=<on|off>]    open backing file with O_DIRECT
     --show                    print device name after setup (with -f)
 -v, --verbose                 verbose mode

 -J, --json                    use JSON --list output format
 -l, --list                    list info about all or specified (default)
 -n, --noheadings              don't print headings for --list output
 -O, --output <cols>           specify columns to output for --list
     --output-all              output all columns
     --raw                     use raw --list output format

 -h, --help                    display this help
 -V, --version                 display version

fdisk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
[root@vgt-rocky9-60 ~]# fdisk  openwrt-x86-64-generic-ext4-combined-efi.img 

Welcome to fdisk (util-linux 2.37.4).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk openwrt-x86-64-generic-ext4-combined-efi.img: 1.43 GiB, 1535409664 bytes, 2998847 sectors
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: 38948C92-761D-992A-2027-0CEE23BA4000

Device Start End Sectors Size Type
openwrt-x86-64-generic-ext4-combined-efi.img1 512 33279 32768 16M Linux filesystem
openwrt-x86-64-generic-ext4-combined-efi.img2 33280 2998813 2965534 1.4G Linux filesystem
openwrt-x86-64-generic-ext4-combined-efi.img128 34 511 478 239K BIOS boot

Partition table entries are not in disk order.

Command (m for help): m

Help:

GPT
M enter protective/hybrid MBR

Generic
d delete a partition ### 删除分区
F list free unpartitioned space
l list known partition types
n add a new partition ### 添加新分区
p print the partition table
t change a partition type ### 修改分区
v verify the partition table
i print information about a partition ### 查看分区信息

Misc
m print this menu
x extra functionality (experts only) ### 进入扩展功能

Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file

Save & Exit
w write table to disk and exit ### 写分区表,保存退出
q quit without saving changes

Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty DOS partition table
s create a new empty Sun partition table


Command (m for help):


Command (m for help): i
Partition number (1,2,128, default 128): 2

Device: openwrt-x86-64-generic-ext4-combined-efi.img2
Start: 33280
End: 2998813
Sectors: 2965534
Size: 1.4G
Type: Linux filesystem
Type-UUID: 0FC63DAF-8483-4772-8E79-3D69D8477DE4
UUID: 38948C92-761D-992A-2027-0CEE23BA4002

Command (m for help): x

Expert command (m for help): p
Disk openwrt-x86-64-generic-ext4-combined-efi.img: 1.43 GiB, 1535409664 bytes, 2998847 sectors
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: 38948C92-761D-992A-2027-0CEE23BA4000
First LBA: 34
Last LBA: 2998813
Alternative LBA: 2998846
Partition entries LBA: 2
Allocated partition entries: 128

Device Start End Sectors Type-UUID UUID Name Attrs
openwrt-x86-64-generic-ext4-combined-efi.img1 512 33279 32768 0FC63DAF-8483-4772-8E79-3D69D8477DE4 38948C92-761D-992A-2027-0CEE23BA4001 LegacyBIOSBootable
openwrt-x86-64-generic-ext4-combined-efi.img2 33280 2998813 2965534 0FC63DAF-8483-4772-8E79-3D69D8477DE4 38948C92-761D-992A-2027-0CEE23BA4002
openwrt-x86-64-generic-ext4-combined-efi.img128 34 511 478 21686148-6449-6E6F-744E-656564454649 38948C92-761D-992A-2027-0CEE23BA4080

Partition table entries are not in disk order.

Expert command (m for help): m

Help (expert commands):

GPT
i change disk GUID
n change partition name
u change partition UUID ### 更新分区表uuid
l change table length
M enter protective/hybrid MBR

A toggle the legacy BIOS bootable flag
B toggle the no block IO protocol flag
R toggle the required partition flag
S toggle the GUID specific bits

Generic
p print the partition table
v verify the partition table
d print the raw data of the first sector from the device
D print the raw data of the disklabel from the device
f fix partitions order
m print this menu

Save & Exit
q quit without saving changes
r return to main menu ### 退回正常菜单


Expert command (m for help): r