老毛子拓展ext4分区大小

老毛子拓展ext4分区大小

起因

分区的时候分了一个1TB的机械硬盘,如下:

文件名 起始柱面 结束柱面 大小 格式
/dev/sda1 2048 1048580095 500G ext4
/dev/sda2 1048580096 1953525167 461G NTFS

现在我想把/dev/sda2删除了,并将整个盘剩余空间分给/dev/sda1

结果

扩容成功,扩容前的内容没有丢失🐶

参考

相关命令

fdisk

fdisk工具删除/dev/sda1,/dev/sda2分区,然后创建新分区,注意开始的磁柱号要和原来的一致(是保证数据不丢失的关键步骤),我/dev/sda1是2048,所以分区号还是1,终止柱面号默认回车使用剩余磁盘的全部柱面。(我的1TB机械默认的2048扇区头和1953525167扇区尾)

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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
Using username "oldgerman".
oldgerman@192.168.233.1's password:


BusyBox v1.29.3 (2020-10-28 16:48:12 CST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

[XY-C1 3.4.3.9-099_20-10-2]# 2020-10-30 15:51:57
[EK-C1 /home/root]# fdisk -l
Disk /dev/mtdblock0: 0 MB, 196608 bytes, 384 sectors
0 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Disk /dev/mtdblock0 doesn't contain a valid partition table
Disk /dev/mtdblock1: 0 MB, 65536 bytes, 128 sectors
0 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Disk /dev/mtdblock1 doesn't contain a valid partition table
Disk /dev/mtdblock2: 0 MB, 65536 bytes, 128 sectors
0 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Disk /dev/mtdblock2 doesn't contain a valid partition table
Disk /dev/mtdblock3: 1 MB, 1484288 bytes, 2899 sectors
0 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Disk /dev/mtdblock3 doesn't contain a valid partition table
Disk /dev/mtdblock4: 14 MB, 15292416 bytes, 29868 sectors
1 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Disk /dev/mtdblock4 doesn't contain a valid partition table
Disk /dev/mtdblock5: 15 MB, 16449536 bytes, 32128 sectors
1 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Disk /dev/mtdblock5 doesn't contain a valid partition table
Disk /dev/mtdblock6: 16 MB, 16777216 bytes, 32768 sectors
2 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Disk /dev/mtdblock6 doesn't contain a valid partition table
Disk /dev/sda: 932 GB, 1000204886016 bytes, 1953525168 sectors
121601 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Device Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type
/dev/sda1 * 0,32,33 1023,254,63 2048 1048580095 1048578048 500G 83 Linux
[EK-C1 /home/root]# fdisk /dev/sda

The number of cylinders for this disk is set to 121601.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p
Disk /dev/sda: 932 GB, 1000204886016 bytes, 1953525168 sectors
121601 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Device Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type
/dev/sda1 * 0,32,33 1023,254,63 2048 1048580095 1048578048 500G 83 Linux

Command (m for help): d
Selected partition 1

Command (m for help): p
Disk /dev/sda: 932 GB, 1000204886016 bytes, 1953525168 sectors
121601 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Device Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type

Command (m for help): n
Partition type
p primary partition (1-4)
e extended
p
Partition number (1-4):
Value is out of range
Partition number (1-4):
Value is out of range
Partition number (1-4): 1
First sector (2048-1953525167, default 2048):
Using default value 2048
Last sector or +size{,K,M,G,T} (2048-1953525167, default 1953525167):
Using default value 1953525167

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table
[EK-C1 /home/root]# e2fsck -f /dev/sda
e2fsck 1.45.4 (23-Sep-2019)
ext2fs_open2: Bad magic number in super-block
e2fsck: Superblock invalid, trying backup blocks...
e2fsck: Bad magic number in super-block while trying to open /dev/sda

The superblock could not be read or does not describe a valid ext2/ext3/ext4
filesystem. If the device is valid and it really contains an ext2/ext3/ext4
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
e2fsck -b 8193 <device>
or
e2fsck -b 32768 <device>

[EK-C1 /home/root]# e2fsck -f /dev/sda1
e2fsck 1.45.4 (23-Sep-2019)
e2fsck: No such file or directory while trying to open /dev/sda1
Possibly non-existent device?
[EK-C1 /home/root]# e2fsck -f /dev/sda1
e2fsck 1.45.4 (23-Sep-2019)
e2fsck: No such file or directory while trying to open /dev/sda1
Possibly non-existent device?
[EK-C1 /home/root]# df -h
Filesystem Size Used Available Use% Mounted on
rootfs 12.4M 12.4M 0 100% /
/dev/root 12.4M 12.4M 0 100% /
tmpfs 8.0K 0 8.0K 0% /dev
tmpfs 20.0M 2.1M 17.9M 10% /etc
tmpfs 1.0M 4.0K 1020.0K 0% /home
tmpfs 8.0K 0 8.0K 0% /media
tmpfs 8.0K 0 8.0K 0% /mnt
tmpfs 40.0M 1.5M 38.5M 4% /tmp
tmpfs 4.0M 104.0K 3.9M 3% /var
tmpfs 40.0M 1.5M 38.5M 4% /opt
[EK-C1 /home/root]# fdisk -l
Disk /dev/mtdblock0: 0 MB, 196608 bytes, 384 sectors
0 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Disk /dev/mtdblock0 doesn't contain a valid partition table
Disk /dev/mtdblock1: 0 MB, 65536 bytes, 128 sectors
0 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Disk /dev/mtdblock1 doesn't contain a valid partition table
Disk /dev/mtdblock2: 0 MB, 65536 bytes, 128 sectors
0 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Disk /dev/mtdblock2 doesn't contain a valid partition table
Disk /dev/mtdblock3: 1 MB, 1484288 bytes, 2899 sectors
0 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Disk /dev/mtdblock3 doesn't contain a valid partition table
Disk /dev/mtdblock4: 14 MB, 15292416 bytes, 29868 sectors
1 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Disk /dev/mtdblock4 doesn't contain a valid partition table
Disk /dev/mtdblock5: 15 MB, 16449536 bytes, 32128 sectors
1 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Disk /dev/mtdblock5 doesn't contain a valid partition table
Disk /dev/mtdblock6: 16 MB, 16777216 bytes, 32768 sectors
2 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Disk /dev/mtdblock6 doesn't contain a valid partition table
Disk /dev/sda: 932 GB, 1000204886016 bytes, 1953525168 sectors
382818 cylinders, 81 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Device Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type
/dev/sda1 0,32,33 769,80,63 2048 1953525167 1953523120 931G 83 Linux
[EK-C1 /home/root]# e2fsck -f /dev/sda1
e2fsck 1.45.4 (23-Sep-2019)
e2fsck: No such file or directory while trying to open /dev/sda1
Possibly non-existent device?
[EK-C1 /home/root]# e2fsck -f /dev/sda
e2fsck 1.45.4 (23-Sep-2019)
ext2fs_open2: Bad magic number in super-block
e2fsck: Superblock invalid, trying backup blocks...
e2fsck: Bad magic number in super-block while trying to open /dev/sda

The superblock could not be read or does not describe a valid ext2/ext3/ext4
filesystem. If the device is valid and it really contains an ext2/ext3/ext4
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
e2fsck -b 8193 <device>
or
e2fsck -b 32768 <device>

[EK-C1 /home/root]# resize2fs /dev/sda1
-sh: resize2fs: not found
[EK-C1 /home/root]# e2fsck
Usage: e2fsck [-panyrcdfktvDFV] [-b superblock] [-B blocksize]
[-l|-L bad_blocks_file] [-C fd] [-j external_journal]
[-E extended-options] [-z undo_file] device

Emergency help:
-p Automatic repair (no questions)
-n Make no changes to the filesystem
-y Assume "yes" to all questions
-c Check for bad blocks and add them to the badblock list
-f Force checking even if filesystem is marked clean
-v Be verbose
-b superblock Use alternative superblock
-B blocksize Force blocksize when looking for superblock
-j external_journal Set location of the external journal
-l bad_blocks_file Add to badblocks list
-L bad_blocks_file Set badblocks list
-z undo_file Create an undo file
[EK-C1 /home/root]# e2fsck -f /dev/sda1
e2fsck 1.45.4 (23-Sep-2019)
e2fsck: No such file or directory while trying to open /dev/sda1
Possibly non-existent device?
[EK-C1 /home/root]# fdisk -l
Disk /dev/mtdblock0: 0 MB, 196608 bytes, 384 sectors
0 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Disk /dev/mtdblock0 doesn't contain a valid partition table
Disk /dev/mtdblock1: 0 MB, 65536 bytes, 128 sectors
0 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Disk /dev/mtdblock1 doesn't contain a valid partition table
Disk /dev/mtdblock2: 0 MB, 65536 bytes, 128 sectors
0 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Disk /dev/mtdblock2 doesn't contain a valid partition table
Disk /dev/mtdblock3: 1 MB, 1484288 bytes, 2899 sectors
0 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Disk /dev/mtdblock3 doesn't contain a valid partition table
Disk /dev/mtdblock4: 14 MB, 15292416 bytes, 29868 sectors
1 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Disk /dev/mtdblock4 doesn't contain a valid partition table
Disk /dev/mtdblock5: 15 MB, 16449536 bytes, 32128 sectors
1 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Disk /dev/mtdblock5 doesn't contain a valid partition table
Disk /dev/mtdblock6: 16 MB, 16777216 bytes, 32768 sectors
2 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Disk /dev/mtdblock6 doesn't contain a valid partition table
Disk /dev/sda: 932 GB, 1000204886016 bytes, 1953525168 sectors
382818 cylinders, 81 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Device Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type
/dev/sda1 0,32,33 769,80,63 2048 1953525167 1953523120 931G 83 Linux
[EK-C1 /home/root]# mount
rootfs on / type rootfs (rw)
/dev/root on / type squashfs (ro,relatime)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
usbfs on /proc/bus/usb type usbfs (rw,relatime)
tmpfs on /dev type tmpfs (rw,relatime,size=8k)
tmpfs on /etc type tmpfs (rw,noatime,size=20480k)
tmpfs on /home type tmpfs (rw,relatime,size=1024k)
tmpfs on /media type tmpfs (rw,relatime,size=8k)
tmpfs on /mnt type tmpfs (rw,relatime,size=8k)
tmpfs on /tmp type tmpfs (rw,relatime,size=40960k)
tmpfs on /var type tmpfs (rw,relatime,size=4096k)
devpts on /dev/pts type devpts (rw,relatime,mode=600)
tmpfs on /opt type tmpfs (rw,relatime,size=40960k)
[EK-C1 /home/root]# e2fsck -f /dev/sdb1
e2fsck 1.45.4 (23-Sep-2019)
e2fsck: No such file or directory while trying to open /dev/sdb1
Possibly non-existent device?
[EK-C1 /home/root]# cd /dev
[EK-C1 /dev]# ls
bus mtd1 network_latency
console mtd1ro network_throughput
cpu_dma_latency mtd2 null
full mtd2ro nvram
gpio mtd3 port
hwnat0 mtd3ro ppp
i2cM0 mtd4 ptmx
kmsg mtd4ro pts
log mtd5 random
loop-control mtd5ro rdm0
loop0 mtd6 root
loop1 mtd6ro sda
loop2 mtdblock0 sg0
loop3 mtdblock1 spiS0
loop4 mtdblock2 tty
loop5 mtdblock3 ttyS0
loop6 mtdblock4 urandom
loop7 mtdblock5 usbdev1.1
mem mtdblock6 usbdev2.1
mtd0 mtk_esw zero
mtd0ro net
[EK-C1 /dev]# e2fsck -f /dev/sda
e2fsck 1.45.4 (23-Sep-2019)
ext2fs_open2: Bad magic number in super-block
e2fsck: Superblock invalid, trying backup blocks...
e2fsck: Bad magic number in super-block while trying to open /dev/sda

The superblock could not be read or does not describe a valid ext2/ext3/ext4
filesystem. If the device is valid and it really contains an ext2/ext3/ext4
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
e2fsck -b 8193 <device>
or
e2fsck -b 32768 <device>

[EK-C1 /dev]# fsck -f /dev/sda
-sh: fsck: not found
[EK-C1 /dev]#

e2fsck

重启老毛子,在磁盘页取消挂载后用putty进入ssh,对fdisk扩容后的/dev/sda1分区使用e2fsck 命令:

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
Using username "oldgerman".
oldgerman@192.168.233.1's password:


BusyBox v1.29.3 (2020-10-28 16:48:12 CST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

[XY-C1 3.4.3.9-099_20-10-2]# 2020-10-30 16:07:09
[EK-C1 /home/root]# e2fsck -f /dev/sda
e2fsck 1.45.4 (23-Sep-2019)
ext2fs_open2: Bad magic number in super-block
e2fsck: Superblock invalid, trying backup blocks...
e2fsck: Bad magic number in super-block while trying to open /dev/sda

The superblock could not be read or does not describe a valid ext2/ext3/ext4
filesystem. If the device is valid and it really contains an ext2/ext3/ext4
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
e2fsck -b 8193 <device>
or
e2fsck -b 32768 <device>

[EK-C1 /home/root]# e2fsck -f /dev/sda1
e2fsck 1.45.4 (23-Sep-2019)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sda1: 73680/61054976 files (1.1% non-contiguous), 81815376/244190390 blocks

[EK-C1 /home/root]#

重启,resize2fs检查

老毛子默认是没有resize2fs命令的,我用电脑科学上网到http://bin.entware.net/mipselsf-k3.4/resize2fs_1.45.6-1_mipsel-3.4.ipk下载后传到/tmp文件夹用 opkg install 安装的,安装完自动配置环境变量,而且tmp下的安装包也不见了就很神奇

1
2
3
4
5
6
7
8
9
10
11
12
13
Using username "oldgerman".
oldgerman@192.168.233.1's password:


BusyBox v1.29.3 (2020-10-28 16:48:12 CST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

[XY-C1 3.4.3.9-099_20-10-2]# 2020-10-30 16:13:38
[EK-C1 /opt/home/admin]# resize2fs /dev/sda1
resize2fs 1.45.6 (20-Mar-2020)
The filesystem is already 244190390 (4k) blocks long. Nothing to do!

[EK-C1 /opt/home/admin]#

检查

opt挂载正常,可道云正常

20201030164355