Primary menu

Tag Archives: filesystem

Today I’ve learnt that a Linux partition (which is mounted) can be grown “a la brava” (means “the hard way” in Catalan) directly modifying it through Fdisk and then resizing with resize2fs. That’s it….

With my own conservative way I’d boot the machine into Gparted (A very useful small distro that boots into Gparted directly), resize the partition (unmounted), and then reboot again.

The only condition is that the partition which has to be grown is the last one. If not… things get more complicated (or not, if the last partition is a swap one, which can be erased and recreated without problems). Other condition is that particion can only be grown (not shrink).

The process it’s easy:

First grow the disk physically (can be a VM disk, a new bigger disk just cloned, or simply a partition that does’nt fill the entire disk).

With Fdisk, remove the partition.

Without exiting Fdisk, create a new partition. Carefully note that the first sector match the previous first sector. The last sector can be the end of the disk i.e.

Verify/toggle Boot flag, must be activated.

Save and exit. Cross your fingers and reboot.

Once rebooted, grow the filesystem with resize2fs.

Growing a ext3/4 partition

Shell

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

## 4.3Gb of free space before the process

root@nairobi:~# df -h

Filesystem Size Used Avail Use%Mounted on

/dev/xvda211G5.7G4.3G57%/

udev238M4.0K238M1%/dev

tmpfs49M176K49M1%/run

none5.0M05.0M0%/run/lock

none245M0245M0%/run/shm

## Let's do it

## (Note that HDD is 26.8 Gb. It has been grown previously at XEN dom0 level).

root@nairobi:~# fdisk /dev/xvda

Command(mforhelp):p

Disk/dev/xvda:26.8GB,26843545600bytes

255heads,63sectors/track,3263cylinders,total52428800sectors

Units=sectors of1*512=512bytes

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

I/Osize(minimum/optimal):512bytes/512bytes

Disk identifier:0x00088b81

Device Boot Start EndBlocks IdSystem

/dev/xvda1204899942349868882Linux swap/Solaris

/dev/xvda2*999424230686711103462483Linux

Command(mforhelp):d

Partition number(1-4):2

# Remove the last partition. DON'T WRITE CHANGES YET!

# And re-create the partition. Note that first sector MUST be the same than before