對(duì)于許多l(xiāng)inux用戶來說,ext3,ext4文件系統(tǒng)可能會(huì)比較熟悉,,但是btrfs還真有不少人不知道,,其實(shí)Btrfs 被稱為是下一代 Linux 文件系統(tǒng),據(jù)說它采用了很多先進(jìn)的文件系統(tǒng)設(shè)計(jì),,不僅解決了 ext2/3 的擴(kuò)展性問題,還讓人們看到了下一代文件系統(tǒng)所具有的許多其他特性,。而因?yàn)橛袀€(gè)應(yīng)用, 之前分配磁盤空間不夠用了(只分了1TB), 現(xiàn)在找管理員分多2TB, 加起來就是3TB可用空間. 后端用的是CEPH文件系統(tǒng), 所以在我的系統(tǒng)中, 看到的分區(qū)是這樣的
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第一個(gè)分區(qū)vdd1, 就是我原來的分區(qū)(1TB), 現(xiàn)在vdd已經(jīng)從原來的1TB擴(kuò)容到3TB, 如何把3TB的空間都移給vdd1?
不能直接 btrfs resize
幸好我用的是btrfs文件系統(tǒng), 它的擴(kuò)展性有目共睹, 用網(wǎng)上說明的方法來試下
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, 不過直接報(bào)錯(cuò), 提示過大, 無論如何也無法調(diào)高, 但可以在目前1TB的大小內(nèi)調(diào)整
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
在與網(wǎng)友的交流中, nerd有句話提醒了我' 文件系統(tǒng)是在分區(qū)之內(nèi)的東東 ', 嗯, btrfs是構(gòu)建在分區(qū)之上的文件系統(tǒng), 它應(yīng)該不能修改分區(qū)的大小
而后nerd給了個(gè)鏈接, 里面提到了使用fdisk和resize2fs來調(diào)整ext文件系統(tǒng)的大小, 總體思路是: 刪除分區(qū)->使用新大小新建分區(qū)->做fsck->resize2fs->最后就可以重新掛載并且數(shù)據(jù)一般不會(huì)丟失!
參考鏈接: resize-filesystem-fdisk-resize2fs
這種思路在btrfs應(yīng)該也行! 來試試
先fdick調(diào)整分區(qū)大小, 再btrfs resize, 關(guān)鍵是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 (刪除分區(qū))
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 (保存分區(qū))
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 (新建分區(qū))
Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p (新建主分區(qū), 后續(xù)步驟一路默認(rèn)值, 回車)
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 (保存分區(qū))
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 #這里證實(shí)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 #重新掛載修改后的分區(qū)
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 #調(diào)整大小
Resize '/home/data' of 'max'
root@hostname:/home# df -h | grep data
/dev/vdd1 2.0T 863G 1.2T 43% /home/data
看到最后的大小了么, 不是3T, 而是2T, 我也納悶, 用默認(rèn)值來新建, 應(yīng)該是最大的3T, 后來想到MBR分區(qū)的問題(MBR分區(qū)只能最大2.2TB), 嗯, 我用的fdisk不支持GPT分區(qū), 得改用parted工具來重新弄了
MBR和GPT參考文檔: MBR和GPT分區(qū)格式
用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 (重新刪除分區(qū))
(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 (轉(zhuǎn)為GPT分區(qū), 會(huì)提醒數(shù)據(jù)丟失! 勇敢的續(xù)續(xù)吧)
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 (新建分區(qū))
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 #重新掛載修改后的分區(qū)
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了, 而且一切數(shù)據(jù)還在, 勝利!
后話: 數(shù)據(jù)有風(fēng)險(xiǎn), 操作需謹(jǐn)慎, 請做好備份, 任何一步出錯(cuò), 都可能丟失數(shù)據(jù)! 同時(shí)也感謝nerd!
原文 http://www.igigo.net/post/xiao-za-sui/diao-zheng-btrfsfen-qu-da-xiao