linux调整磁盘分区大小(代码片段)

Sonictl Sonictl     2022-12-14     307

关键词:

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.



lvm逻辑卷操作(代码片段)

...新对硬盘分区,然后恢复数据到新分区。虽然有很多动态调整磁盘的工具可以使用,例如PartitionMagic等等,但是它并不能完全解决问题,因为某个分区可能会再次被耗尽;另外一个方面这需要重新引导系统才能实现,对于很多关... 查看详情

linux磁盘与分区(代码片段)

查看磁盘和分区信息fdisk-lu可以看到,我这台服务器共有2个磁盘,他们的大小分别为200G,和160G,ps:不知道为什么会显示多一点点。通过lsblk命令也可以查看已有分区的文件系统类型df-Th执行结果如下所示。其... 查看详情

linux磁盘与分区(代码片段)

查看磁盘和分区信息fdisk-lu可以看到,我这台服务器共有2个磁盘,他们的大小分别为200G,和160G,ps:不知道为什么会显示多一点点。通过lsblk命令也可以查看已有分区的文件系统类型df-Th执行结果如下所示。其... 查看详情

linux磁盘与分区(代码片段)

查看磁盘和分区信息fdisk-lu可以看到,我这台服务器共有2个磁盘,他们的大小分别为200G,和160G,ps:不知道为什么会显示多一点点。通过lsblk命令也可以查看已有分区的文件系统类型df-Th执行结果如下所示。其... 查看详情

通过虚拟机增加linux的磁盘(分区容量)(代码片段)

因为安装oracle设置的磁盘空间不足,所以安装失败。这里总结一下如何添加磁盘挂载1.右键虚拟机点击设置,然后点击磁盘,点击添加按钮2.然后点击下一步下一步,直到安装成功3.然后输入fdisk-l查看增加的磁盘  4.然后输... 查看详情

linux分区命令parted的用法(代码片段)

...fdisk工具来进行分区,但是目前在实际生产环境中使用的磁盘空间越来越大,呈TiB级别增长;而常用的fdisk这个工具对分区是有大小限制的,它只能划分小于2T的磁盘,所以在划大于2T磁盘分区的时候fdisk就无法满足要求了;这个... 查看详情

linux磁盘与分区(代码片段)

查看磁盘和分区信息fdisk-lu可以看到,我这台服务器共有2个磁盘,他们的大小分别为200G,和160G,ps:不知道为什么会显示多一点点。通过lsblk命令也可以查看已有分区的文件系统类型df-Th执行结果如下所示。其... 查看详情

linux固件开发|几分钟看透gpt分区(代码片段)

...),只包含一个类型值为0xEE的分区项,在小于2TB的磁盘上,大小为整个磁盘;在更大的磁盘上,它的大小固定为2TB。它的作用是阻止不能识别GPT分区的磁盘工具试图对其进行分区或格式化等操作,所以该扇... 查看详情

linux查看磁盘空间(代码片段)

Linux查看磁盘空间可以使用 df 和 du 命令。dfdf以磁盘分区为单位查看文件系统,可以获取硬盘被占用了多少空间,目前还剩下多少空间等信息。例如,我们使用df-h命令来查看磁盘信息, -h 选项为根据大小适当... 查看详情

shlinux的查看分区,磁盘空间大小(代码片段)

查看详情

linux磁盘分区(代码片段)

磁盘分区磁盘命名分区管理磁盘创建分区创建文件系统挂载交换分区增加交换分区准备分区格式化挂载逻辑卷创建LVMVG管理LV扩容磁盘命名kernel对不同硬盘命名方式CentOS7:1、SATA(单口)/dev/sda/dev:设备文件目录;s:sata单口;d:磁盘;a... 查看详情

linux磁盘分区(代码片段)

磁盘分区磁盘命名分区管理磁盘创建分区创建文件系统挂载交换分区增加交换分区准备分区格式化挂载逻辑卷创建LVMVG管理LV扩容磁盘命名kernel对不同硬盘命名方式CentOS7:1、SATA(单口)/dev/sda/dev:设备文件目录;s:sata单口;d:磁盘;a... 查看详情

怎么调整磁盘分区的大小

目前调整分区大小主要有两种方式:使用磁盘管理器调整和使用分区工具调整。这两种方式都可以做到无损调整,不影响现有数据第一种:使用磁盘管理器调整:打开磁盘管理器:右击“我的电脑”-管理-磁盘管理如果硬盘上没... 查看详情

linux磁盘分区(代码片段)

Linux磁盘分区荣涛2021年11月18日文档修改日志日期修改内容修改人备注2021年11月18日创建荣涛1.引言1.1.查看磁盘空间1.1.1.df命令如何查看磁盘空间大小,使用df命令:$dfFilesystem1K-blocksUsedAvailableUse%Mountedondevtmpfs6729704067297040%/de... 查看详情

linux磁盘分区(代码片段)

Linux磁盘分区荣涛2021年11月18日文档修改日志日期修改内容修改人备注2021年11月18日创建荣涛1.引言1.1.查看磁盘空间1.1.1.df命令如何查看磁盘空间大小,使用df命令:$dfFilesystem1K-blocksUsedAvailableUse%Mountedondevtmpfs6729704067297040%/de... 查看详情

linux系统的磁盘管理(代码片段)

Linux系统的磁盘管理一、环境介绍1.Linux系统版本2.系统磁盘情况二、磁盘介绍1.磁盘分区理解2.MBR分区方案2.GPT分区分区方案三、分区工具fidsk使用1.查看磁盘和分区信息2.查看指定设备信息3.对新磁盘进行分区4.格式化文件系统四、... 查看详情

vmware下linux非lvm管理的根目录扩容(代码片段)

...了,无法正常安装,此时需要将虚拟机硬盘从20Gb调整到40G,然后再把根分区扩大到30Gb,以下是扩容的整体操作步骤。2.操作环境运行平台:VMware虚拟化操作系统:CentOS7.3.1611源磁盘容量:20Gb根分区容量... 查看详情

vmware下linux非lvm管理的根目录扩容(代码片段)

...了,无法正常安装,此时需要将虚拟机硬盘从20Gb调整到40G,然后再把根分区扩大到30Gb,以下是扩容的整体操作步骤。2.操作环境运行平台:VMware虚拟化操作系统:CentOS7.3.1611源磁盘容量:20Gb根分区容量... 查看详情