-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nixos/hot-resize: init #357523
base: master
Are you sure you want to change the base?
nixos/hot-resize: init #357523
Conversation
How to use :
After you resize your disk just run |
30113a0
to
70cc946
Compare
Also you can backport this PR if is possible. |
You mean me? |
Has you want im just asking. |
Hi , @JohnRTitor can you review this PR ? One question from @GaetanLepage is that : What is the best : Best Regards |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I question the need for such a module. Disk resizing - even if it's just expanding disks - is a dangerous operation; one that I would certainly not trust an automatic bash
script to do.
What issue does this solve? Is this issue worth maintaining more templated bash
that is probably not very extensible?
Hi, @SigmaSquadron The module specifically solves the use case of VMs (especially on platforms like Proxmox) where: Adding disk space is a common and safe operation Best Regards |
New Usage :
|
6c2dd55
to
30c909c
Compare
@ofborg eval |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. The CI failure is unrelated.
text = '' | ||
process_device() { | ||
local device="$1" | ||
local fstype="$2" | ||
local mountpoint="$3" | ||
|
||
echo "Processing $device ($fstype) mounted at $mountpoint..." | ||
|
||
REAL_DEVICE=$(readlink -f "$device") | ||
DISK=$(lsblk -ndo pkname "$REAL_DEVICE") | ||
PART_NUM=$(lsblk -ndo part "$REAL_DEVICE") | ||
|
||
if [ -z "$DISK" ] || [ -z "$PART_NUM" ]; then | ||
echo "Failed to determine disk and partition number for $device" | ||
return 1 | ||
fi | ||
|
||
echo "Growing partition /dev/$DISK partition $PART_NUM..." | ||
GROWPART_OUTPUT=$(growpart "/dev/$DISK" "$PART_NUM" 2>&1) || { | ||
EXIT_CODE=$? | ||
if [ $EXIT_CODE -eq 2 ]; then | ||
echo "Partition is already at maximum size, continuing with filesystem resize..." | ||
else | ||
echo "Failed to grow partition: $GROWPART_OUTPUT" | ||
return $EXIT_CODE | ||
fi | ||
} | ||
|
||
echo "Resizing filesystem..." | ||
case "$fstype" in | ||
ext4) | ||
resize2fs "$device" | ||
;; | ||
xfs) | ||
xfs_growfs "$mountpoint" | ||
;; | ||
btrfs) | ||
btrfs filesystem resize max "$mountpoint" | ||
;; | ||
*) | ||
echo "Unsupported filesystem type: $fstype" | ||
return 1 | ||
;; | ||
esac | ||
|
||
echo "Current size:" | ||
df -h "$mountpoint" | ||
echo "---" | ||
} | ||
|
||
process_device "$@" | ||
''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is small for now, but in the future, as this module gets bigger, you may want to consider splitting the bash part into a separate file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
Yes i can if you want ?
If you think is really needed.
Best Regards
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, wait, how does the script get the devices
? You haven't added them as inputs anywhere.
description = "Filesystem type (supported: ext4, xfs, btrfs)"; | ||
}; | ||
|
||
mountPoint = lib.mkOption { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a good idea to imitate hardware-configuration.nix, making mount point the name of attributes instead of list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this module may be more appropriate in tools like disko, rather than a standalone NixOS module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal was to not use disko that why have create this module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what your intention is, having a dedicated program is much better than throwing random solutions everywhere, especially when you are trying to do a one shot job with a NixOS module thats gonna be persistent...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disko is the ideal place for something like this, especially since Disko is also written in bash
.
That have been fixed. |
Add ability to resize your fs ext4 or xfs or btrfs in vm or vma without reboot.
Have created dedicated module for this because is more agnostic to use it in various situations.
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.