Linux调整磁盘分区大小

本文介绍了如何在Linux系统中调整磁盘分区大小,包括使用parted列出分区、使用fdisk查看磁盘信息、扩展第二分区以利用全部磁盘空间、重启加载更新的分区表、以root权限扩展文件系统等步骤。对于可能出现的问题,如resize2fs权限被拒绝,提供了手动在Linux PC上调整大小的链接。此外,还提到了针对Raspberry Pi等嵌入式系统的SD卡手动调整方法和计算分区大小的公式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Resize the disk (Linux调整磁盘分区大小)

Resize the partition. Run parted: $ parted

Show the partition list: (parted) print

There should be two partitions; 1 should be a boot partition, about 64MB; the second should be the main partition, about 3.6G

Some Disk Commands of Linux, that you should know:

  • sudo df -h          Display the FileSystem that you mounted
  • sudo fdisk -l    Show your disk information that is unmounted or un-parted

Sonictl: Here I didn't see two partitions by print command. but fdisk -l showed me that.

Resize the second partition to use the whole disk: (parted) resizepart 2 32GB

Sonictl: Here you may meet error: "Unrecognized disk label", useselect command to chang the device from "/dev/mmcblk1boot0" to "/dev/mmcble0", then try again.

Close parted: (parted) quit

Reboot to load the updated partition table: $ reboot

Log in as root again, resize the filesystem: $ resize2fs /dev/mmcblk0p2

Now you should have the full capacity of your microSD card available.

for some reason, you may meet: resize2fs: Permission denied to resize filesystem, you can fix this by Link:Manually Resize on Linux PC

======= above seems works well for Lubuntu/ubuntu =======

For most Embedded OS(raspbian/lubuntu/...), ref: Manually resizing the SD card on Raspberry Pi

======== for calculating the Cylinder# ========

Make a new partition with the exact size you got from the block count. Since you cannot enter block size in fdisk, you need to figure out how many cylinders to request. Here is the formula:

  (number of needed cylinders) = (number of blocks) / (block size)

  (block size) = (unit size) / 1024

  (unit size) = (number of heads) * (number of sectors/cylinder) * (number of bytes/sector)

Consider the following example, where a hard drive has been partitioned into four primary partitions of 1, 2, 4, and 8 cylinders.

disk /dev/sda: 16 heads, 63 sectors, 23361 cylinders
Units = cylinders of 1008 * 512 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/sda1             1         2       976+  83  Linux
/dev/sda2             3         5      1512   83  Linux
/dev/sda3             6        10      2520   83  Linux
/dev/sda4            11        19      4536   83  Linux
fdisk provides the configuration information I need in the head of the output. The unit size is 516096 ( 16 heads * 63 sectors/cyl * 512 bytes/sector ). The block size is 504 ( 516096 / 1024 ). The number of needed cylinders for the second partition is therefore 3 ( 1512 blocks / 504 ). The partition table shows that this is indeed the case: the first cylinder is 3, the second 4, and the last is 5, for a total of three cylinders. The number of needed cylinders for the third partition is calculated similarly: 2520 blocks / 504 = 5, which corresponds to blocks 6,7,8,9,10 . Notice that this calculation does not work for the first partition because the block count is wrong ( 976 instead of 1008 ). The plus sign indicates that not all the blocks are included in the fdisk value. When you try the calculation ( 976 / 504 ) you get 1.937. Knowing that the number of cylinders must be an integer, you can simply round up.



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值