Class: Getch::Disk

Inherits:
Object
  • Object
show all
Defined in:
lib/getch/disk.rb

Instance Method Summary collapse

Constructor Details

#initialize(disk, fs) ⇒ Disk

Returns a new instance of Disk.



3
4
5
6
7
# File 'lib/getch/disk.rb', line 3

def initialize(disk, fs)
  @hdd = disk
  @fs = fs
  @state = Getch::States.new()
end

Instance Method Details

#cleaningObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/getch/disk.rb', line 14

def cleaning
  return if STATES[:partition ]
  puts
  print "Cleaning data on #{@hdd}, can be long, avoid this on Flash Memory (SSD,USB,...) ? (n,y) "
  case gets.chomp
  when /^y|^Y/
    system("dd if=/dev/urandom of=/dev/#{@hdd} bs=4M status=progress")
  else
    return
  end
end

#efi?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/getch/disk.rb', line 9

def efi?
  Dir.exist? '/sys/firmware/efi/efivars'
end

#formatObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/getch/disk.rb', line 40

def format
  return if STATES[:format]
  puts "Format #{@hdd} with #{@fs}"
  if efi? then
    system("mkfs.vfat -F32 /dev/#{@hdd}1")
    system("mkswap /dev/#{@hdd}2")
    system("swapon /dev/#{@hdd}2")
    system("mkfs.ext4 /dev/#{@hdd}3")
    system("mkfs.ext4 /dev/#{@hdd}4")
  else
    system("mkswap /dev/#{@hdd}2")
    system("swapon /dev/#{@hdd}2")
    system("mkfs.ext4 /dev/#{@hdd}3")
    system("mkfs.ext4 /dev/#{@hdd}4")
  end
  @state.format
end

#partitionObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/getch/disk.rb', line 26

def partition
  return if STATES[:partition]
  system("wipefs -a /dev/#{@hdd}")
  system("sgdisk --zap-all /dev/#{@hdd}")
  if efi? then
    puts "Partition disk #{@hdd} for an EFI system"
    partition_efi
  else
    puts "Partition disk #{@hdd} for a Bios system"
    partition_bios
  end
  @state.partition
end