9

Anyone can provide me any test case for the below command: blockdev --setbsz BYTES to set/change the block size.

I have tried like below but no luck.

$ blockdev --setbsz 2048 /dev/sda5
blockdev: 2048: No such file or directory
HalosGhost
  • 4,790
  • Can you tell us what you're actually trying to do? Have you read the documentation? – HalosGhost Jul 18 '14 at 08:11
  • I tried to use --setbsz option for blockdev; but giving the above error. What will be the correct syntax for this option? – sameer pradhan Jul 18 '14 at 08:13
  • Read man blockdev. – HalosGhost Jul 18 '14 at 08:17
  • it says: --setbsz N Set blocksize to N bytes. And i tried the same. – sameer pradhan Jul 18 '14 at 08:18
  • 1
    @HalosGhost man blockdev doesn't help him/her. According to the man page this command is correct. – polym Jul 18 '14 at 08:19
  • which version of util-linux are you using? I just did the same and it worked (well, I used blockdev --setbsz 1024 /dev/sda1) – Dani_l Jul 18 '14 at 08:19
  • @sameerpradhan Can you try blockdev --setbsz=2048 /dev/sda5 ? Maybe the man page is missing a = and this command should not have a whitespace – polym Jul 18 '14 at 08:20
  • @sameerpradhan you have to try it as root user. – Raja G Jul 18 '14 at 08:20
  • I tried it but it doesn't change the value....$ sudo ./toybox blockdev --setbsz 2048 /dev/sda5 blockdev: 2048: No such file or directory $ sudo blockdev --setbsz 2048 /dev/sda5 BLKBSZSET: Device or resource busy $ sudo ./toybox blockdev --getbsz /dev/sda5 4096 – sameer pradhan Jul 18 '14 at 08:25
  • You must umount the device first. the sudo error shows the device is mounted – Dani_l Jul 18 '14 at 08:31
  • $ mount /dev/sda1 on / type ext3 (rw,errors=remount-ro) proc on /proc type proc (rw,noexec,nosuid,nodev) none on /sys type sysfs (rw,noexec,nosuid,nodev) none on /sys/fs/fuse/connections type fusectl (rw) ...binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev) $ sudo blockdev --getbsz /dev/sdb1 512 $ sudo blockdev --setbsz 2048 /dev/sdb1 $ sudo blockdev --getbsz /dev/sdb1 512 Here it didn't give any error but the block size didn't change. – sameer pradhan Jul 18 '14 at 08:35
  • try sudo blockdev --setbsz 2048 --getbsz /dev/sdb1 – Dani_l Jul 18 '14 at 08:46
  • 2
    from man: Note that the block size is specific to the current file descriptor opening the block device, so the change of block size only persists for as long as blockdev has the device open, and is lost once blockdev exits. – Dani_l Jul 18 '14 at 08:47
  • This is an old thread but all I see here is that people assume that blocksize is set per partition (sdaX) whereas in fact it is set per device (sda). You can set your filesystem blocks to arbitrary number and it will use lowest number of device blocks to accommodate this arbitrary size.

    If you unmount your filesystems and change this per device, I would imagine it will screw up filesystems on the device but haven't tried it.

    Basically, backup your data, recreate filesystems any way you want, copy data back. I don't think you can change this on a whim.

    – Tomas Pruzina Jan 15 '18 at 17:13
  • @pruzinat I don't think that's correct. I mounted a file-based image with a vfat partition and a ext4 partition. The device and ext4 partition are both 4096 blocksize, but the vfat is only 512. – Saad Malik Jul 09 '19 at 06:04

3 Answers3

8

Check the block size of current device.

$ blockdev --getbsz /dev/vdb1
512

Unmount filesystem to change block size.

$ umount /dev/vdb1

Create filesystem to change new block size.

$ mkfs -t ext4 -b 4096 /dev/vdb1

Mount to check the changed block size.

$ mount /dev/vdb1 /test/
$ blockdev --getbsz /dev/vdb1
4096
chaos
  • 48,171
vaibhav
  • 81
1

You have to do it as root user after unmounting that device.

# this is as root user
[root@pse-linvm ~]# blockdev --setbsz 4096 /dev/vda2
BLKBSZSET: Device or resource busy
[root@pse-linvm ~]# blockdev --setbsz 4096 /dev/vda6
/dev/vda6: No such file or directory

# this is normal user
[root@pse-linvm ~]# su - raja
[raja@pse-linvm ~]$ blockdev --getbsz /dev/vda2
/dev/vda2: Permission denied

# Error same as yours
[raja@pse-linvm ~]$ blockdev --getbsz 4096 /dev/vda2
4096: No such file or directory
Raja G
  • 5,937
0

Not an answer - just posting in answer box for clarity

[dani@localhost ~]$ blockdev --getbsz /dev/sda1 
blockdev: cannot open /dev/sda1: Permission denied
[dani@localhost ~]$ 
[dani@localhost ~]$ su -
Password: 
[root@localhost ~]# blockdev --getbsz /dev/sda1 
1024
[root@localhost ~]# blockdev --setbsz 1024 /dev/sda1 
BLKBSZSET: Device or resource busy
[root@localhost ~]# umount /boot 
[root@localhost ~]# blockdev --setbsz 1024 /dev/sda1 

works well on fd20 with linux-utils 2.24.2

Dani_l
  • 4,943
  • $ mount /dev/sda1 on / type ext3 (rw,errors=remount-ro) proc on /proc type proc (rw,noexec,nosuid,nodev) none on /sys type sysfs (rw,noexec,nosuid,nodev) ...binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev) $ sudo blockdev --getbsz /dev/sda1 4096 $ sudo blockdev --getbsz /dev/sdb1 512 $ sudo blockdev --setbsz 2048 /dev/sdb1 $ sudo blockdev --getbsz /dev/sdb1 512 Here i mount and tried to change the bsz but no change. And i didn't get any error. – sameer pradhan Jul 18 '14 at 08:47
  • answered in comments to your OP – Dani_l Jul 18 '14 at 08:50