欢迎访问分类目录网
快审联系QQ:158925126当前位置:分类目录网 » 站长资讯 » 技术教程 » 文章详细 订阅RssFeed

linux下btrfs文件系统扩容实录

来源:本站原创 浏览:773次 时间:2016-10-08

  对于许多linux用户来说,ext3,ext4文件系统可能会比较熟悉,但是btrfs还真有不少人不知道,其实Btrfs 被称为是下一代 Linux 文件系统,据说它采用了很多先进的文件系统设计,不仅解决了 ext2/3 的扩展性问题,还让人们看到了下一代文件系统所具有的许多其他特性。而因为有个应用, 之前分配磁盘空间不够用了(只分了1TB), 现在找管理员分多2TB, 加起来就是3TB可用空间. 后端用的是CEPH文件系统, 所以在我的系统中, 看到的分区是这样的

  Model: Virtio Block Device (virtblk)

  Disk /dev/vdd: 3299GB

  Sector size (logical/physical): 512B/512B

  Partition Table: msdos Number Start End Size Type File system Flags 1 1049kB 1100GB 1100GB primary btrf

  可以看到, 我的vdd第一个分区vdd1, 就是我原来的分区(1TB), 现在vdd已经从原来的1TB扩容到3TB, 如何把3TB的空间都移给vdd1?

  不能直接 btrfs resize

  幸好我用的是btrfs文件系统, 它的扩展性有目共睹, 用网上说明的方法来试下

  root@hostname:/home/igi# btrfs filesystem resize +1024G /home/data/ Resize '/home/data/' of '+1024G' ERROR: unable to resize '/home/data/' - File too large

  我先试了加多1TB, 不过直接报错, 提示过大, 无论如何也无法调高, 但可以在目前1TB的大小内调整

  root@hostname:/home/igi# btrfs filesystem resize -10G /home/data/ Resize '/home/data/' of '-10G' root@hostname:/home/igi# df -h | grep data /dev/vdd1 1014G 725G 288G 72% /home/data root@hostname:/home/igi# btrfs filesystem resize +10G /home/data/ Resize '/home/data/' of '+10G' root@hostname:/home/igi# df -h | grep data /dev/vdd1 1.0T 725G 298G 71% /home/data

  在与网友的交流中, nerd有句话提醒了我' 文件系统是在分区之内的东东 ', 嗯, btrfs是构建在分区之上的文件系统, 它应该不能修改分区的大小

  而后nerd给了个链接, 里面提到了使用fdisk和resize2fs来调整ext文件系统的大小, 总体思路是: 删除分区->使用新大小新建分区->做fsck->resize2fs->最后就可以重新挂载并且数据一般不会丢失!

  参考链接: resize-filesystem-fdisk-resize2fs

  这种思路在btrfs应该也行! 来试试

  先fdick调整分区大小, 再btrfs resize, 关键是fsck!

  root@hostname:/home/igi# umount /home/data/

  root@hostname:/home/igi# fdisk /dev/vdd

  WARNING: The size of this disk is 3.3 TB (3298534883328 bytes).

  DOS partition table format can not be used on drives for volumes

  larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID

  partition table format (GPT).

  Command (m for help): d (删除分区)

  Selected partition 1

  Command (m for help): p

  Disk /dev/vdd: 3298.5 GB, 3298534883328 bytes

  3 heads, 2 sectors/track, 1073741824 cylinders, total 6442450944 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

  Disk identifier: 0x5cd07a6b Device Boot Start End Blocks Id System

  Command (m for help): w (保存分区)

  The partition table has been altered!

  Calling ioctl() to re-read partition table.

  Syncing disks.

  root@hostname:/home/igi# fdisk /dev/vdd

  WARNING: The size of this disk is 3.3 TB (3298534883328 bytes).

  DOS partition table format can not be used on drives for volumes

  larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID

  partition table format (GPT).

  Command (m for help): n (新建分区)

  Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p (新建主分区, 后续步骤一路默认值, 回车)

  Partition number (1-4, default 1): 1 First sector (2048-4294967295, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-4294967294, default 4294967294): Using default value 4294967294 Command (m for help): p

  Disk /dev/vdd: 3298.5 GB, 3298534883328 bytes 16 heads, 63 sectors/track, 6391320 cylinders, total 6442450944 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

  Disk identifier: 0x5cd07a6b Device Boot Start End Blocks Id System

  /dev/vdd1 2048 4294967294 2147482623+ 83 Linux

  Command (m for help): w (保存分区)

  The partition table has been altered!

  Calling ioctl() to re-read partition table.

  Syncing disks.

  root@hostname:/home# btrfsck /dev/vdd1 #一定要做fsck!

  checking extents

  checking fs roots

  checking root refs found 923277586432 bytes used err is 0 total csum bytes: 898793244 total tree bytes: 2683535360 total fs tree bytes: 1454723072 btree space waste bytes: 514669023 file data blocks allocated: 920594051072 referenced 920594051072 Btrfs Btrfs v0.19 root@hostname:/home/igi# resize2fs /dev/vdd1 #这里证实resize2fs不支持btrfs

  resize2fs 1.42.5 (29-Jul-2012)

  resize2fs: Bad magic number in super-block while trying to open /dev/vdd1

  Couldn't find valid filesystem superblock.

  root@hostname:/home/igi# mount -a #重新挂载修改后的分区

  root@hostname:/home/igi# df -h | grep data #可以看到还是1TB!!!

  /dev/vdd1 1.0T 863G 160G 85% /home/data

  root@hostname:/home# btrfs filesystem resize max /home/data #调整大小

  Resize '/home/data' of 'max'

  root@hostname:/home# df -h | grep data

  /dev/vdd1 2.0T 863G 1.2T 43% /home/data

  看到最后的大小了么, 不是3T, 而是2T, 我也纳闷, 用默认值来新建, 应该是最大的3T, 后来想到MBR分区的问题(MBR分区只能最大2.2TB), 嗯, 我用的fdisk不支持GPT分区, 得改用parted工具来重新弄了

  MBR和GPT参考文档: MBR和GPT分区格式

  用parted再来一次

  root@hostname:/home# parted /dev/vdd

  GNU Parted 2.3

  Using /dev/vdd

  Welcome to GNU Parted! Type 'help' to view a list of commands.

  (parted) print

  Model: Virtio Block Device (virtblk)

  Disk /dev/vdd: 3299GB

  Sector size (logical/physical): 512B/512B

  Partition Table: msdos Number Start End Size Type File system Flags 1 1049kB 2199GB 2199GB primary btrfs

  (parted) rm 1 (重新删除分区)

  (parted) print

  Model: Virtio Block Device (virtblk)

  Disk /dev/vdd: 3299GB

  Sector size (logical/physical): 512B/512B

  Partition Table: msdos Number Start End Size Type File system Flags

  (parted) mklabel gpt (转为GPT分区, 会提醒数据丢失! 勇敢的续续吧)

  Warning: The existing disk label on /dev/vdd will be destroyed and all data on this disk will be lost. Do you want to continue?

  Yes/No? Yes

  (parted) mkpart primary (新建分区)

  File system type? [ext2]? btrfs Start? 1049kB End? 3299GB

  (parted) print

  Model: Virtio Block Device (virtblk)

  Disk /dev/vdd: 3299GB

  Sector size (logical/physical): 512B/512B

  Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 3299GB 3299GB btrfs primary (parted) quit

  Information: You may need to update /etc/fstab.

  root@hostname:/home# btrfsck /dev/vdd1 #一定要记得fsck!

  checking extents

  checking fs roots

  checking root refs found 923277582336 bytes used err is 0 total csum bytes: 898793244 total tree bytes: 2683531264 total fs tree bytes: 1454723072 btree space waste bytes: 514665137 file data blocks allocated: 920594051072 referenced 920594051072 Btrfs Btrfs v0.19 root@hostname:/home/igi# mount -a #重新挂载修改后的分区

  root@hostname:/home# btrfs filesystem resize max /home/data

  Resize '/home/data' of 'max' root@hostname:/home# df -h | grep data

  /dev/vdd1 3.0T 863G 2.2T 29% /home/data

  终于3TB了, 而且一切数据还在, 胜利!

  后话: 数据有风险, 操作需谨慎, 请做好备份, 任何一步出错, 都可能丢失数据! 同时也感谢nerd!

  原文 http://www.igigo.net/post/xiao-za-sui/diao-zheng-btrfsfen-qu-da-xiao


公司企业大全

推荐站点

  • 游软盟 游软盟

    游软盟是一个免费的应用下载网站,为用户提供好玩的手机游戏、实用的手机软件下载,我们也会及时

    app.ufolm.com
  • 股道边资源网 股道边资源网

    股道边网是国内拥有非常丰富齐全的股票期货指标公式量化模型资源分享中心,拥有丰富的股票指标公

    www.de6688.com
  • 任推帮 任推帮

    任推邦.地推产品中心,是BD邦是商务地推服务平台,BD邦通过汇集海量的商务合作信息,聚集各

    dt.bd.cn
  • 好完美 好完美

    完美国际私服【www.haowm.com】好完美每日更新国内好玩完美sf游戏,包括最新完美

    www.haowm.com
  • 印度代购 印度代购

    阿熊印度代购是一家专业从事男性双效片印度代购的机构,主要代购产品有:必利劲,希爱力,艾力达

    www.yindudaigou.org
  • 宝鸡便民网 宝鸡便民网

    宝鸡便民网/宝鸡信息网/宝鸡生活网/0917/(www.0917.cn)宝鸡便民信息推广平

    www.0917.cn
  • 问答联盟 问答联盟

    问答客是一个回答各种问题的网站,在这里,也许你的疑惑可以得到解决

    ask.ufolm.com
  • 重庆自动化设备 重庆自动化设备

    重庆磊明工业自动化设备有限公司是一家专业从事非标自动化设备、自动化检测设备、自动化装配设备

    www.leimingauto.com
  • 音飞网 音飞网

    音飞网致力于翻译不同语种网民的网文,博文,评论,文章等,秉承\"各美其美,美人之美,美美与

    www.innfey.com